VxWorks系统函数loadModule()程序示例
loadModule()在VxWorks中用来加载.o,.out文件,然后用moduleFindByName()来找到符号表中固定入口函数所在的位置。 可以参考usrLib.h和moduleLib.h来获得详细信息。
#include #include #include #include #include #include #include #include
extern SYMTAB_ID sysSymTbl ;
int loadTestModuleAndRun() { int fd = ERRor ; int status = ERRor ; MODULE_ID hModule ; FUNCPTR taskEntry = NULL ; SYM_TYPE * pType ;
fd = open("/sd0/test.out",O_RDONLY,0) ;
if (fd==ERROR) { printf("can not open binary file.\n") ; return ERRor ; } else { printf("binary file opened.\n") ; }
if ((hModule="loadModule"(fd,LOAD_ALL_SYMBOLS))==NULL) { printf("loadModule error = 0x%x.\n",errno) ; return ERROR; }
close(fd) ;
status = symFindByName(sysSymTbl,"test", (char **)&taskEntry,pType ) ;
if (status==ERROR) { printf("symFindByName error=%d\n", errno) ; return ERROR; } else { /* Type N_ABS="2",N_TEXT="4",N_DATA="6",N_BSS="8";N_EXT="1" */
printf("taskEntryr="0x"%x, type=%d\n.", (int)taskEntry,(int)*pType); }
status = taskSpawn("test",100,0,30000,taskEntry, 0,0,0,0,0,0,0,0,0,0) ;
if (status==ERROR) { printf("taskSpawn error=%d\n",errno) ; return ERROR; }
return OK ; }
|