⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symlib.c

📁 VxWorks操作系统内核源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
    )    {    return (symTblDestroy (symTblId, FALSE));    }/********************************************************************************* symTblDestroy - destroy a symbol table and optionally deallocate memory** The specified symbol table is terminated if no symbols are resident.* If dealloc is TRUE, memory associated with the symbol table, including the* hash table, is deallocated.** RETURNS: OK, or ERROR if invalid symbol table ID, or symbols still in table.** NOMANUAL*/STATUS symTblDestroy    (    SYMTAB_ID symTblId,         /* ID of symbol table to delete */    BOOL      dealloc           /* deallocate associated memory */    )    {    if (OBJ_VERIFY (symTblId, symTblClassId) != OK)	return (ERROR);				/* invalid symbol table ID */    semTake (&symTblId->symMutex, WAIT_FOREVER);    if (symTblId->nsymbols > 0)			/* non-empty table? */	{	semGive (&symTblId->symMutex);		/* release mutual exclusion */	errno = S_symLib_TABLE_NOT_EMPTY;	return (ERROR);	}    semTerminate (&symTblId->symMutex);		 /* terminate mutex */    objCoreTerminate (&symTblId->objCore);    hashTblDestroy (symTblId->nameHashId, dealloc);    if (dealloc)	return (objFree (symTblClassId, (char *) symTblId));    return (OK);    }/********************************************************************************* symAlloc - allocate and initialize a symbol, including group number** Allocate and initialize a symbol.  The symbol is not added to any symbol* table.  To add a symbol to a symbol table use symAdd() or symTblAdd().* Space for the name is allocated along with the SYMBOL structure, thus the* name parameter need not be static.** RETURNS: Pointer to symbol, or NULL if out of memory.** NOMANUAL*/SYMBOL *symAlloc    (    SYMTAB_ID   symTblId,       /* symbol table to allocate symbol for */    char        *name,          /* pointer to symbol name string */    char        *value,         /* symbol address */    SYM_TYPE    type,           /* symbol type */    UINT16	group		/* symbol group */    )    {    SYMBOL *pSymbol;    char   *symName;    int	   length;    if (OBJ_VERIFY (symTblId, symTblClassId) != OK)	return (NULL);				/* invalid symbol table ID */    if (name == NULL)	return (NULL);				/* null name */    length = strlen (name);			/* figure out name length */    pSymbol = (SYMBOL *) memPartAlloc (symTblId->symPartId,				       (unsigned)(sizeof(SYMBOL) + length + 1));    if (pSymbol == NULL)			/* out of memory */	return (NULL);    /* copy name after symbol */    symName	    = (char *) ((unsigned) pSymbol + sizeof (SYMBOL));    symName[length] = EOS;			/* null terminate string */    strncpy (symName, name, length);		/* copy name into place */    symInit (pSymbol, symName, value, type, group); /* initialize symbol*/    return (pSymbol);				/* return symbol ID */    }/********************************************************************************* symInit - initialize a symbol, including group number** Initialize a symbol.  The symbol is not added to any symbol table.  To add* a symbol to a symbol table use symAdd() or symTblAdd().** RETURNS: OK, or ERROR if symbol table could not be initialized.** NOMANUAL*/STATUS symInit    (    SYMBOL      *pSymbol,       /* pointer to symbol */    char        *name,          /* pointer to symbol name string */    char        *value,         /* symbol address */    SYM_TYPE    type,           /* symbol type */    UINT16	group		/* symbol group */    )    {    /* fill in symbol */    pSymbol->name  = name;			/* symbol name */    pSymbol->value = (void *)value;		/* symbol value */    pSymbol->type  = type;			/* symbol type */    pSymbol->group = group;			/* symbol group */    return (OK);    }/********************************************************************************* symFree - deallocate a symbol** Deallocate the specified symbol.  This routine does not check if symbols* are still resident in symbol tables, so all calls to symFree should be* preceded by a call to symTblRemove.** RETURNS: OK, or ERROR if invalid symbol table.** NOMANUAL*/STATUS symFree    (    SYMTAB_ID symTblId, /* symbol table semaphore */    SYMBOL *pSymbol     /* pointer to symbol to delete */    )    {    if (OBJ_VERIFY (symTblId, symTblClassId) != OK)	return (ERROR);				/* invalid symbol table ID */    return (memPartFree (symTblId->symPartId, (char *) pSymbol));    }/********************************************************************************* symSAdd - create and add a symbol to a symbol table, including a group number* * This routine behaves as symAdd() except it does not check for synchronization* function pointers. Thus it can be used in loaders to prevent from trying to * independently synchronize each symbol of a module.** RETURNS: OK, or ERROR if the symbol table is invalid* or there is insufficient memory for the symbol to be allocated.** NOMANUAL*/STATUS symSAdd    (    SYMTAB_ID symTblId,         /* symbol table to add symbol to */    char      *name,            /* pointer to symbol name string */    char      *value,           /* symbol address */    SYM_TYPE  type,             /* symbol type */    UINT16    group             /* symbol group */    )    {    SYMBOL *pSymbol = symAlloc (symTblId, name, value, type, group);    if (pSymbol == NULL)			/* out of memory? */	return (ERROR);    if (symTblAdd (symTblId, pSymbol) != OK)	/* try to add symbol */	{	symFree (symTblId, pSymbol);		/* deallocate symbol if fail */	return (ERROR);	}        return (OK);    }/********************************************************************************* symAdd - create and add a symbol to a symbol table, including a group number** This routine allocates a symbol <name> and adds it to a specified symbol* table <symTblId> with the specified parameters <value>, <type>, and <group>.* The <group> parameter specifies the group number assigned to a module when* it is loaded; see the manual entry for moduleLib.** RETURNS: OK, or ERROR if the symbol table is invalid* or there is insufficient memory for the symbol to be allocated.** SEE ALSO: moduleLib*/STATUS symAdd    (    SYMTAB_ID symTblId,         /* symbol table to add symbol to */    char      *name,            /* pointer to symbol name string */    char      *value,           /* symbol address */    SYM_TYPE  type,             /* symbol type */    UINT16    group             /* symbol group */    )    {    SYMBOL *pSymbol = symAlloc (symTblId, name, value, type, group);    if (pSymbol == NULL)			/* out of memory? */	return (ERROR);    if (symTblAdd (symTblId, pSymbol) != OK)	/* try to add symbol */	{	symFree (symTblId, pSymbol);		/* deallocate symbol if fail */	return (ERROR);	}        /* synchronize host symbol table if necessary */    if ((syncSymAddRtn != NULL)	&& (symTblId == sysSymTbl))	(* syncSymAddRtn) (name, value, type, group);    return (OK);    }/********************************************************************************* symTblAdd - add a symbol to a symbol table** This routine adds a symbol to a symbol table.** RETURNS: OK, or ERROR if invalid symbol table, or symbol couldn't be added.** INTERNAL* This is a lousy name, it should probably be symAddStatic ().** NOMANUAL*/STATUS symTblAdd    (    SYMTAB_ID symTblId,         /* symbol table to add symbol to */    SYMBOL    *pSymbol          /* pointer to symbol to add */    )    {    if (OBJ_VERIFY (symTblId, symTblClassId) != OK)	return (ERROR);				/* invalid symbol table ID */    semTake (&symTblId->symMutex, WAIT_FOREVER);    if ((!symTblId->sameNameOk) &&	(hashTblFind (symTblId->nameHashId, &pSymbol->nameHNode,		      SYM_MASK_EXACT_TYPE) != NULL))	{	semGive (&symTblId->symMutex);		/* release exclusion to table */	errno = S_symLib_NAME_CLASH;		/* name clashed */	return (ERROR);	}    hashTblPut (symTblId->nameHashId, &pSymbol->nameHNode);    symTblId->nsymbols ++;			/* increment symbol count */    semGive (&symTblId->symMutex);		/* release exclusion to table */    return (OK);    }/********************************************************************************* symRemove - remove a symbol from a symbol table** This routine removes a symbol of matching name and type from a* specified symbol table.  The symbol is deallocated if found.* Note that VxWorks symbols in a standalone VxWorks image (where the * symbol table is linked in) cannot be removed.** RETURNS: OK, or ERROR if the symbol is not found* or could not be deallocated.*/STATUS symRemove    (    SYMTAB_ID symTblId,         /* symbol tbl to remove symbol from */    char      *name,            /* name of symbol to remove */    SYM_TYPE  type              /* type of symbol to remove */    )    {    SYMBOL *pSymbol;    if (symFindSymbol (symTblId, name, NULL, 		       type, SYM_MASK_EXACT_TYPE, &pSymbol) != OK)	return (ERROR);    if (symTblRemove (symTblId, pSymbol) != OK)	return (ERROR);    /* synchronize host symbol table if necessary */    if ((syncSymRemoveRtn != NULL) && (symTblId == sysSymTbl))	(* syncSymRemoveRtn) (name, type);    return (symFree (symTblId, pSymbol));    }/********************************************************************************* symTblRemove - remove and terminate a symbol from a symbol table** This routine removes the specified symbol from the symbol table.  The* symbol is not deallocated.** RETURNS: OK, or ERROR if symbol table invalid, or symbol not found.** NOMANUAL*/STATUS symTblRemove    (    SYMTAB_ID symTblId,         /* symbol table to remove symbol from */    SYMBOL    *pSymbol          /* pointer to symbol to remove */    )    {    HASH_NODE *pNode;    if (OBJ_VERIFY (symTblId, symTblClassId) != OK)	return (ERROR);				/* invalid symbol table ID */    semTake (&symTblId->symMutex, WAIT_FOREVER);    pNode = hashTblFind (symTblId->nameHashId, &pSymbol->nameHNode,			 SYM_MASK_EXACT);    if (pNode == NULL)	{	semGive (&symTblId->symMutex);		/* release exclusion to table */	errnoSet (S_symLib_SYMBOL_NOT_FOUND);	/* symbol wasn't found */	return (ERROR);	}    hashTblRemove (symTblId->nameHashId, pNode);    symTblId->nsymbols--;			/* one less symbol */    semGive (&symTblId->symMutex);		/* release exclusion to table */    return (OK);    }/********************************************************************************* symFindSymbol - find symbol in a symbol table of equivalent name and type** This routine is a generic routine to retrieve a symbol in the* specified symbol table.  It can be used to perform searches by name,* name and type, value, or value and type.* * If the 'name' parameter is non-NULL, a search by name will be* performed and the value parameter will be ignored.  If the name* parameter is NULL, a search by value will be performed.  In a search* by value, if no matching entry is found, the symbol of the matching* type with the next lower value is selected.  (If the type is NULL, as* in a simple search by value, this will simply be whatever symbol* in the symbol table has the next lowest address.)** In both the search by name and search by value cases, potential* matches will have their types compared to <type>, subject to the* <mask>, and only symbols which match the specified type will be* returned.  To have the type matched exactly, set the <type>* parameter to the desired type and set the <mask> parameter to* SYM_MASK_EXACT_TYPE.  To search only by name or only by value and* have the <type> parameter ignored, set the <mask> parameter to* SYM_MATCH_ANY_TYPE.** To search the global VxWorks symbol table, specify \f3sysSymTbl\f1* as <symTblId>.* * INTERNAL* This routine contains a weird hack designed to deal with the additional* symbols the loader puts in the symbol table.  The loader adds three symbols* to the symbol table: <filename>_text, <filename>_data, <filename>_bss.* These symbols may have the same address (i.e. value in the symbol table)* as real routine or variable names.  When looking up a symbol for display* it is desirable to find the real routine or variable names in preference* to these made up names.  For example, loading "demo.o" will cause a* symbol "demo.o_text" to be added to the symbol table with the same value* as the real symbol "_demo".  In a disassembly or "i" printout, etc, we* would rather see "_demo".  So the test inside the loop in this routine* that normally terminates the search if we find an exact match, has been* changed to keep searching if the match it finds ends in "_text", "_data",* or "_bss".  ** If no other exact match is found, the special symbols will be returned

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -