struct FindWellKnownSymbolCallbackInfo {
char *name;
UINT16 group;
};
static BOOL
findWellKnownSymbolCB(char *name,
int val,
SYM_TYPE type,
int arg,
UINT16 group)
{
struct FindWellKnownSymbolCallbackInfo *info =
(struct FindWellKnownSymbolCallbackInfo *) arg;
if (!strcmp(name, info->name)) {
info->group = group;
return FALSE;
}
return TRUE;
}
/* Returns CVM_TRUE upon success, CVM_FALSE upon error */
static CVMBool
getWellKnownSymbolGroupId(UINT16* group)
{
static CVMBool gotId = CVM_FALSE;
static UINT16 id;
if (gotId == CVM_FALSE) {
struct FindWellKnownSymbolCallbackInfo info;
SYMBOL* sym;
#ifdef CVM_DYNLINKSYM_PREPEND_UNDERSCORE
info.name = "_CVMgcUnsafeExecuteJavaMethod";
#else
info.name = "CVMgcUnsafeExecuteJavaMethod";
#endif
sym = symEach(sysSymTbl, (FUNCPTR) &findWellKnownSymbolCB,
(int) &info);
/* If sym is NULL, failed to find symbol -- should not happen. */
if (sym == NULL) {
return CVM_FALSE;
}
id = info.group;
gotId = CVM_TRUE;
}
*group = id;
return gotId;
}
struct CallbackInfo {
char *name;
UINT16 group;
void *val;
};
static BOOL
findSymbolCB(char *name,
int val,
SYM_TYPE type,
int arg,
UINT16 group)
{
struct CallbackInfo *info = (struct CallbackInfo *) arg;
if ((!strcmp(name, info->name)) &&
(info->group == group)) {
/* Found the symbol we're looking for. Returning FALSE from
this callback will cause symEach() to return the current
symbol to its caller. */
info->val = (void *) val;
return FALSE;
}
return TRUE;
}
void *
CVMdynlinkSym(void *dsoHandle, const void *nameArg)
{
VxWorksLibraryHandle* handle = (VxWorksLibraryHandle*)dsoHandle;
const char* name = (const char*)nameArg;
struct CallbackInfo info;
SYMBOL* sym;
void *value;
#ifdef CVM_DYNLINKSYM_PREPEND_UNDERSCORE
/*
* %comment: mam051
* It might be nice if we could modify nameArg in place.
*/
char *buf = malloc(strlen(nameArg) + 1 + 1);
if (buf == NULL) {
return NULL;
}
strcpy(buf, "_");
strcat(buf, nameArg);
name = buf;
#endif
assert(handle != NULL);
if (handle->isGlobal) {
/* Look up a well-known CVM symbol and match its group
ID. This protects us whether cvm.o is dynamically loaded,
or statically linked into the kernel. */
if (getWellKnownSymbolGroupId(&info.group) == CVM_FALSE) {
value = NULL;
goto done;
}
} else {
MODULE_ID mid;
MODULE_INFO mInfo;
mid = handle->id;
if (moduleInfoGet(mid, &mInfo) == ERROR) {
value = NULL;
goto done;
}
info.group = (UINT16) mInfo.group;
}
info.name = (char*)name;
sym = symEach(sysSymTbl, (FUNCPTR) &findSymbolCB, (int) &info);
if (sym == NULL) {
value = NULL;
} else {
value = info.val;
}
done:
#ifdef CVM_DYNLINKSYM_PREPEND_UNDERSCORE
free(buf);
#endif
return value;
}
void
CVMdynlinkClose(void *dsoHandle)
{
VxWorksLibraryHandle* handle = (VxWorksLibraryHandle *)dsoHandle;
if (handle->id != NULL) {
unldByModuleId(handle->id, 0);
}
free(handle);
}
主要是vxworks的这个函数, symEach(sysSymTbl, (FUNCPTR) &findWellKnownSymbolCB, (int) &info);
不明白呀! 也找不到原代码. 谢谢!
workbench的帮助里面有这个函数说明呀,调用findWellKnownSymbolCB这个callback函数
你这里好像是查询系统符号表,看有没有Info->name这个符号参数