aboutsummaryrefslogtreecommitdiffstats
path: root/elf/elf_module.h
blob: fd0e15c5130306f230f2fc3364162cb49774b651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef ELF_MODULE_H_
#define ELF_MODULE_H_

#include <elf.h>
#include <stdint.h>
#include "linux_list.h"

#define MODULE_NAME_SIZE		64

#define MODULE_ELF_CLASS		ELFCLASS32
#define MODULE_ELF_DATA			ELFDATA2LSB
#define MODULE_ELF_VERSION		EV_CURRENT


typedef int (*module_init_func)();
typedef void (*module_exit_func)();

// Structure encapsulating a module loaded in memory
struct elf_module {
	char				name[MODULE_NAME_SIZE]; 		// The module name
	
	struct list_head	deps;		// Head of module dependency list
	struct list_head	list;		// The list entry in the module list
	
	module_init_func	init_func;	// The initialization entry point
	module_exit_func	exit_func;	// The module finalization code
	
	void				*file_image; // The image of the module file in memory
	uint32_t			file_size; // The size of the module file
	
	// Information for modules loaded in user space
#ifdef ELF_USERSPACE_TEST
	int					file_fd;	// The file descriptor of the open file
#endif
};

// Structure encapsulating a module dependency need
struct module_dep {
	struct list_head	list;		// The list entry in the dependency list
	
	char				name[MODULE_NAME_SIZE];		// The name of the module
};

// Initialization of the module subsystem
extern int modules_init();
// Termination of the module subsystem
extern void modules_term();

// Allocates the structure for a new module
extern struct elf_module *module_alloc(const char *name);

// Loads the module into the system
extern int module_load(struct elf_module *module);

// Unloads the module from the system and releases all the associated memory
extern int module_unload(struct elf_module *module);

#endif /*ELF_MODULE_H_*/