Add accessors for struct mapi_stub and make it opaque.undefined
@@ -132,7 +132,7 @@ mapi_get_proc_address(const char *name) | |||
if (!stub) | |||
stub = stub_find_dynamic(name, 0); | |||
return (stub) ? (mapi_proc) stub->addr : NULL; | |||
return (stub) ? (mapi_proc) stub_get_addr(stub) : NULL; | |||
} | |||
/** | |||
@@ -172,11 +172,12 @@ mapi_table_fill(struct mapi_table *tbl, const mapi_proc *procs) | |||
for (i = 0; i < mapi_num_stubs; i++) { | |||
const struct mapi_stub *stub = mapi_stub_map[i]; | |||
int slot = stub_get_slot(stub); | |||
mapi_func func = (mapi_func) procs[i]; | |||
if (!func) | |||
func = table_get_func(noop, stub); | |||
table_set_func(tbl, stub, func); | |||
func = table_get_func(noop, slot); | |||
table_set_func(tbl, slot, func); | |||
} | |||
} | |||
@@ -39,6 +39,12 @@ | |||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) | |||
struct mapi_stub { | |||
mapi_func addr; | |||
int slot; | |||
const void *name; | |||
}; | |||
/* define public_string_pool and public_stubs */ | |||
#define MAPI_TMP_PUBLIC_STUBS | |||
#include "mapi_tmp.h" | |||
@@ -164,3 +170,38 @@ stub_fix_dynamic(struct mapi_stub *stub, const struct mapi_stub *alias) | |||
entry_patch(stub->addr, slot); | |||
stub->slot = slot; | |||
} | |||
/** | |||
* Return the name of a stub. | |||
*/ | |||
const char * | |||
stub_get_name(const struct mapi_stub *stub) | |||
{ | |||
const char *name; | |||
if (stub >= public_stubs && | |||
stub < public_stubs + ARRAY_SIZE(public_stubs)) | |||
name = &public_string_pool[(unsigned long) stub->name]; | |||
else | |||
name = (const char *) stub->name; | |||
return name; | |||
} | |||
/** | |||
* Return the slot of a stub. | |||
*/ | |||
int | |||
stub_get_slot(const struct mapi_stub *stub) | |||
{ | |||
return stub->slot; | |||
} | |||
/** | |||
* Return the address of a stub. | |||
*/ | |||
mapi_func | |||
stub_get_addr(const struct mapi_stub *stub) | |||
{ | |||
return stub->addr; | |||
} |
@@ -31,11 +31,7 @@ | |||
typedef void (*mapi_func)(void); | |||
struct mapi_stub { | |||
mapi_func addr; | |||
int slot; | |||
const void *name; | |||
}; | |||
struct mapi_stub; | |||
void | |||
stub_init_once(void); | |||
@@ -49,4 +45,13 @@ stub_find_dynamic(const char *name, int generate); | |||
void | |||
stub_fix_dynamic(struct mapi_stub *stub, const struct mapi_stub *alias); | |||
const char * | |||
stub_get_name(const struct mapi_stub *stub); | |||
int | |||
stub_get_slot(const struct mapi_stub *stub); | |||
mapi_func | |||
stub_get_addr(const struct mapi_stub *stub); | |||
#endif /* _STUB_H_ */ |
@@ -51,24 +51,23 @@ table_get_noop(void) | |||
} | |||
/** | |||
* Update the dispatch table to dispatch a stub to the given function. | |||
* Set the function of a slot. | |||
*/ | |||
static INLINE void | |||
table_set_func(struct mapi_table *tbl, | |||
const struct mapi_stub *stub, mapi_func func) | |||
table_set_func(struct mapi_table *tbl, int slot, mapi_func func) | |||
{ | |||
mapi_func *funcs = (mapi_func *) tbl; | |||
funcs[stub->slot] = func; | |||
funcs[slot] = func; | |||
} | |||
/** | |||
* Return the dispatched function of a stub. | |||
* Return the function of a slot. | |||
*/ | |||
static INLINE mapi_func | |||
table_get_func(const struct mapi_table *tbl, const struct mapi_stub *stub) | |||
table_get_func(const struct mapi_table *tbl, int slot) | |||
{ | |||
const mapi_func *funcs = (const mapi_func *) tbl; | |||
return funcs[stub->slot]; | |||
return funcs[slot]; | |||
} | |||
#endif /* _TABLE_H_ */ |