aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/sys/module/common.h
blob: d46dcc38784518e489c87727a8c8091b176a99e3 (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
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * common.h - Common internal operations performed by the module subsystem
 *
 *  Created on: Aug 11, 2008
 *      Author: Stefan Bucur <stefanb@zytor.com>
 */

#ifndef COMMON_H_
#define COMMON_H_

#include <stdio.h>

#include <sys/module.h>
#include <sys/elfutils.h>

#include <linux/list.h>


// Performs an operation and jumps to a given label if an error occurs
#define CHECKED(res, expr, error)		\
	do { 								\
		(res) = (expr);					\
		if ((res) < 0)					\
			goto error;					\
	} while (0)

#define MIN(x,y)	(((x) < (y)) ? (x) : (y))
#define MAX(x,y)	(((x) > (y)) ? (x) : (y))


#ifdef ELF_DEBUG
#define DBG_PRINT(fmt, args...)	fprintf(stderr, "[ELF] " fmt, ##args)
#else
#define DBG_PRINT(fmt, args...)	// Expand to nothing
#endif

/**
 * modules - A global linked list containing all the loaded modules.
 */
extern struct list_head modules;

// User-space debugging routines
#ifdef ELF_DEBUG

extern void print_elf_ehdr(Elf32_Ehdr *ehdr);
extern void print_elf_symbols(struct elf_module *module);

#endif //ELF_DEBUG

/*
 * Image files manipulation routines
 */

extern int image_load(struct elf_module *module);
extern int image_unload(struct elf_module *module);
extern int image_read(void *buff, size_t size, struct elf_module *module);
extern int image_skip(size_t size, struct elf_module *module);
extern int image_seek(Elf32_Off offset, struct elf_module *module);

extern struct module_dep *module_dep_alloc(struct elf_module *module);

extern int check_header_common(Elf32_Ehdr *elf_hdr);

extern int enforce_dependency(struct elf_module *req, struct elf_module *dep);
extern int clear_dependency(struct elf_module *req, struct elf_module *dep);

extern int check_symbols(struct elf_module *module);


#endif /* COMMON_H_ */