summaryrefslogtreecommitdiffhomepage
path: root/include/mdso/mdso.h
blob: f42c67f65b16ee00dc0a907d12bfbc4916a1d4b4 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef MDSO_H
#define MDSO_H

#include <stdint.h>
#include <stdio.h>

#include "mdso_api.h"

#ifdef __cplusplus
extern "C" {
#endif

/* pre-alpha */
#ifndef MDSO_APP
#ifndef MDSO_PRE_ALPHA
#error  libmdso: pre-alpha: ABI is not final!
#error  to use the library, please pass -DMDSO_PRE_ALPHA to the compiler.
#endif
#endif

/* status codes */
#define MDSO_OK				0x00
#define MDSO_USAGE			0x01
#define MDSO_BAD_OPT			0x02
#define MDSO_BAD_OPT_VAL		0x03
#define MDSO_IO_ERROR			0xA0
#define MDSO_MAP_ERROR			0xA1

/* driver flags */
#define MDSO_DRIVER_VERBOSITY_NONE	0x0000
#define MDSO_DRIVER_VERBOSITY_ERRORS	0x0001
#define MDSO_DRIVER_VERBOSITY_STATUS	0x0002
#define MDSO_DRIVER_VERBOSITY_USAGE	0x0004
#define MDSO_DRIVER_CLONE_VECTOR	0x0008

#define MDSO_DRIVER_VERSION		0x0010
#define MDSO_DRIVER_DRY_RUN		0x0020
#define MDSO_DRIVER_QUAD_PTR		0x0040

/* unit action flags */

struct mdso_source_version {
	int		major;
	int		minor;
	int		revision;
	const char *	commit;
};

struct mdso_input {
	void *	addr;
	size_t	size;
};

struct mdso_common_ctx {
	uint64_t			drvflags;
	uint64_t			actflags;
	uint64_t			fmtflags;
	uint32_t			dsoflags;
	const char *			libname;
	const char *			asmbase;
	const char *			dstdir;
};

struct mdso_driver_ctx {
	const char **			units;
	const char *			program;
	const char *			module;
	const struct mdso_common_ctx *	cctx;
	void *				any;
	int				status;
	int				nerrors;
};

struct mdso_unit_ctx {
	const char * const *		path;
	const struct mdso_input *	map;
	const struct mdso_common_ctx *	cctx;
	const char * const *		syms;
	void *				any;
	int				status;
	int				nerrors;
};

/* package info */
mdso_api				const struct mdso_source_version * mdso_source_version(void);

/* driver api */
mdso_api int  mdso_get_driver_ctx	(char ** argv, char ** envp, uint32_t flags, struct mdso_driver_ctx **);
mdso_api int  mdso_create_driver_ctx	(const struct mdso_common_ctx *, struct mdso_driver_ctx **);
mdso_api void mdso_free_driver_ctx	(struct mdso_driver_ctx *);

mdso_api int  mdso_get_unit_ctx		(const struct mdso_driver_ctx *, const char * path, struct mdso_unit_ctx **);
mdso_api void mdso_free_unit_ctx	(struct mdso_unit_ctx *);

mdso_api int  mdso_map_input		(int fd, const char * path, int prot, struct mdso_input *);
mdso_api int  mdso_unmap_input		(struct mdso_input *);

/* utility api */
mdso_api int  mdso_main			(int, char **, char **);
mdso_api int  mdso_output_export_symbols(const struct mdso_unit_ctx *, const struct mdso_common_ctx *, FILE *);
mdso_api int  mdso_create_implib_sources(const struct mdso_driver_ctx *);

/* low-level api */
mdso_api uint32_t mdso_crc32_mbstr	(const unsigned char * str, size_t * symlen);
mdso_api uint64_t mdso_crc64_mbstr	(const unsigned char * str, size_t * symlen);
mdso_api FILE *   mdso_create_output	(const struct mdso_driver_ctx *, const char * asmname);
mdso_api int      mdso_generate_dsometa	(const struct mdso_common_ctx *, FILE * fout);
mdso_api int      mdso_generate_symentry(const struct mdso_common_ctx *, const char * sym, FILE * fout);
mdso_api int      mdso_generate_symfn	(const char * sym, FILE * fout);

#ifdef __cplusplus
}
#endif

#endif