-
Notifications
You must be signed in to change notification settings - Fork 0
/
cexpmodP.h
182 lines (165 loc) · 6.78 KB
/
cexpmodP.h
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#ifndef CEXP_MODULE_PRIVATE_H
#define CEXP_MODULE_PRIVATE_H
/* Private interface to cexp modules */
/* SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
*
* Authorship
* ----------
* This software (CEXP - C-expression interpreter and runtime
* object loader/linker) was created by
*
* Till Straumann <[email protected]>, 2002-2008,
* Stanford Linear Accelerator Center, Stanford University.
*
* Acknowledgement of sponsorship
* ------------------------------
* This software was produced by
* the Stanford Linear Accelerator Center, Stanford University,
* under Contract DE-AC03-76SFO0515 with the Department of Energy.
*
* Government disclaimer of liability
* ----------------------------------
* Neither the United States nor the United States Department of Energy,
* nor any of their employees, makes any warranty, express or implied, or
* assumes any legal liability or responsibility for the accuracy,
* completeness, or usefulness of any data, apparatus, product, or process
* disclosed, or represents that its use would not infringe privately owned
* rights.
*
* Stanford disclaimer of liability
* --------------------------------
* Stanford University makes no representations or warranties, express or
* implied, nor assumes any liability for the use of this software.
*
* Stanford disclaimer of copyright
* --------------------------------
* Stanford University, owner of the copyright, hereby disclaims its
* copyright and all other rights in this software. Hence, anyone may
* freely use it for any purpose without restriction.
*
* Maintenance of notices
* ----------------------
* In the interest of clarity regarding the origin and status of this
* SLAC software, this and all the preceding Stanford University notices
* are to remain affixed to any copy or derivative of this software made
* or distributed by the recipient and are to be affixed to any copy of
* software made or distributed by the recipient that contains a copy or
* derivative of this software.
*
* SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
*/
#include "cexpmod.h"
#include "cexpsegsP.h"
/* implementation of a module */
#define MAX_NUM_MODULES 256
#define LD_WORDLEN 5
#define BITMAP_DEPTH ((MAX_NUM_MODULES)>>(LD_WORDLEN))
#define BITMAP_SET(bm,bitno) (((bm)[(bitno)>>LD_WORDLEN]) |= (1<<((bitno)&((1<<LD_WORDLEN)-1))))
#define BITMAP_CLR(bm,bitno) (((bm)[(bitno)>>LD_WORDLEN]) &= ~(1<<((bitno)&((1<<LD_WORDLEN)-1))))
#define BITMAP_TST(bm,bitno) (((bm)[(bitno)>>LD_WORDLEN]) & (1<<((bitno)&((1<<LD_WORDLEN)-1))))
#define BITMAP_DECLARE(bm) BitmapWord bm[BITMAP_DEPTH]
typedef unsigned long BitmapWord;
typedef short ModuleId; /* Id < 0 means INVALID */
typedef void (*VoidFnPtr)(void);
/* 'magic' names; if symbols with these names are found in
* an object file, pointers should be stored (by the object
* loader code) to the iniCallback and finiCallback fields
* below...
*/
#define CEXPMOD_INITIALIZER_SYM "_cexpModuleInitialize"
#define CEXPMOD_FINALIZER_SYM "_cexpModuleFinalize"
/* Version to protect the layout of CexpModuleRec, CexpSymRec, CexpTARec */
#define CEXPMOD_MAGIC "cexp0000"
typedef struct CexpModuleRec_ {
char *name;
CexpModule next;
CexpSym *section_syms; /* NULL terminated list to section address symbols
* pointer may be NULL if there is no list
*/
unsigned long text_vma; /* where the text segment was loaded */
/* ^^^^ FIELDS ABOVE HERE ARE USED BY THE gencore UTILITY ^^^^^^^^^^^^^^^^
* when changing anything, 'gencore' must be changed accordingly and the
* magic number be changed
*/
CexpSymTbl symtbl;
ModuleId id; /* unique ID */
CexpSegment segs; /* array of actual memory segments */
unsigned long memSize; /* total memory occupied by binary */
BITMAP_DECLARE(neededby); /* bitmap module ids that depend on this one */
BITMAP_DECLARE(needs); /* bitmap of module ids this module depends on */
VoidFnPtr *ctor_list;
unsigned nCtors;
VoidFnPtr *dtor_list;
unsigned nDtors;
void (*cleanup)(CexpModule thismod);
/* cleanup routine is invoked after destructors NOTE:
* this routine is intended for use by the object code
* module whereas the 'finiCallback()' below is used
* to point to code in the loaded module.
*/
void *modPvt; /* lowlevel object format private data */
void (*iniCallback)(CexpModule thismod);
/* optional (non-C++) initialization routine; called
* after constructors
*/
int (*finiCallback)(CexpModule thismod);
/* optional (non-C++) finalizer; called before destructors.
* If 'finiCallback()' returns a non-zero value, this is
* interpreted as REJECTING the unload operation and the
* module is left untouched. This can e.g. be used to
* prevent a 'in-use' driver from being unloaded.
*/
char *fileName;
void *fileAttributes;
/* compatibility attributes as described by '.gnu.attributes'
* section. Currently, only pmbfd supports this.
*/
void *exidx;
unsigned long nExidx;
} CexpModuleRec;
/* This routine must be provided by the underlying
* object file handling. It is responsible for
* allocating all of the necessary members of the
* new modules (except for the name).
*
* In particular, this routine must raise the
* bits for all module dependencies in the 'needs'
* bitmap:
* if (need(some_module))
* BITMAP_SET(this_module->needs,some_module->id);
*/
int
cexpLoadFile(const char *filename, CexpModule new_module);
/* Release all data structures associated with *pmod
*
* NOTE: this must only be called once the module
* has been dequeued from the list
*/
void
cexpModuleFree(CexpModule *pmod);
/* search for an address in all modules giving its aindex
* to the *pmod's aindex table
*
* RETURNS: aindex or -1 if the address is not within the
* boundaries of any module.
*/
int
cexpSymLkAddrIdx(void *addr, int margin, FILE *f, CexpModule *pmod);
/* Symbol and associated module */
typedef struct CexpSymAIdxRec_ {
int idx;
CexpModule mod;
} CexpSymAIdxRec, *CexpSymAIdx;
/* Search for an address in all modules; returns the 2*margin+1
* symbols closest to 'addr' into the 'symmods' array (storage
* allocated by user, 2*margin+1 entries).
* symmods[margin] contains the symbol closest to 'addr', the
* elements > or < margin contain the closest symbols upwards
* and downwards, respectively.
* NOTE: it is possible for individual entries to be 'invalid'
* (mod member == NULL) which means that not enough close symbols
* were found.
*/
void
cexpSymLkAddrRange(void *addr, CexpSymAIdxRec symmods[], int margin);
#endif