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

📄 modulelib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
** moduleCreateHookDelete - delete a previously added module create hook routine** This routine removes a specified routine from the list of* routines to be called at each moduleCreate() call.** RETURNS: OK, or ERROR if the routine is not in the table of module create* hook routines.** SEE ALSO: moduleCreateHookAdd()*/STATUS moduleCreateHookDelete    (    FUNCPTR     moduleCreateHookRtn  /* routine called when module is added */    )    {    MODCREATE_HOOK * pNode;	         /* hook node */    /*     * Step through the list of create hooks until we find a match     */    for (pNode = (MODCREATE_HOOK *) DLL_FIRST (&moduleCreateHookList);	 pNode != NULL;	 pNode = (MODCREATE_HOOK *) DLL_NEXT ((DL_NODE *) pNode))	{	if (pNode->func == moduleCreateHookRtn)	    {	    	    /*	     * We've found the node, delete it and free the space	     */	    dllRemove (&moduleCreateHookList, (DL_NODE *) pNode);	    free (pNode);	    return (OK);	    }	}    /*     * We didn't find the node, return ERROR     */    errnoSet (S_moduleLib_HOOK_NOT_FOUND);    return (ERROR);    }/******************************************************************************** moduleFindByName - find a module by name* * This routine searches for a module with a name matching <moduleName>.* * RETURNS: MODULE_ID, or NULL if no match is found.*/MODULE_ID moduleFindByName    (    char *	 moduleName	       /* name of module to find */    )    {    MODULE_ID	 moduleId;    char         splitName [NAME_MAX]; /* name part of moduleName */    char         splitPath [PATH_MAX]; /* path part of moduleName */    /* get just the name component of moduleName */    pathSplit (moduleName, splitPath, splitName);    /*     * Go through the module list, check each module against     * the search parameter(s).     */    semTake (moduleListSem, WAIT_FOREVER);    for (moduleId = NODE_TO_ID (DLL_LAST (&moduleList));	 moduleId != NULL;	 moduleId = NODE_TO_ID (DLL_PREVIOUS (&moduleId->moduleNode)))	{		/*	 * Found the right one, give the list semaphore, return the module id	 */	if (strcmp (moduleId->name, splitName) == 0)	    {	    semGive (moduleListSem);	    return (moduleId);	    }	}    /*     * Give back the module list semaphore, and return NULL (nothing found)     */    semGive (moduleListSem);    return (NULL);    }/******************************************************************************** moduleFindByNameAndPath - find a module by file name and path* * This routine searches for a module with a name matching <moduleName>* and path matching <pathName>.* * RETURNS: MODULE_ID, or NULL if no match is found.*/MODULE_ID moduleFindByNameAndPath    (    char * 	moduleName,		/* file name to find */    char * 	pathName		/* path name to find */    )    {    MODULE_ID 	moduleId;    /*     * Go through the module list, check each module against     * the search parameter(s).  Take the module list semaphore first.     */    semTake (moduleListSem, WAIT_FOREVER);        for (moduleId = NODE_TO_ID (DLL_LAST (&moduleList));	 moduleId != NULL;	 moduleId = NODE_TO_ID (DLL_PREVIOUS (&moduleId->moduleNode)))	{		/*	 * Found the right one, give the semaphore, return the module id	 */	if ((strcmp (moduleId->name, moduleName) == 0) &&	    (strcmp (moduleId->path, pathName) == 0))	    {	    semGive (moduleListSem);	    return (moduleId);	    }	}    semGive (moduleListSem);    return (NULL);    }/******************************************************************************** moduleFindByGroup - find a module by group number* * This routine searches for a module with a group number matching* <groupNumber>.* * RETURNS: MODULE_ID, or NULL if no match is found.*/MODULE_ID moduleFindByGroup    (    int 	groupNumber		/* group number to find */    )    {    MODULE_ID 	moduleId;    /*     * Go through the module list, check each module against     * the search parameter(s).  Take the list semaphore first     */    semTake (moduleListSem, WAIT_FOREVER);    for (moduleId = NODE_TO_ID (DLL_LAST (&moduleList));	 moduleId != NULL;	 moduleId = NODE_TO_ID (DLL_PREVIOUS (&moduleId->moduleNode)))	{		/*	 * Found the right one, give the semaphore, return the module id	 */	if (groupNumber == moduleId->group)	    {	    semGive (moduleListSem);	    return (moduleId);	    }	}    semGive (moduleListSem);    return (NULL);    }/******************************************************************************** moduleEach - call a routine to examine each loaded module* * This routine calls a user-supplied routine to examine each module.* The routine should be declared as follows:* * .CS*       BOOL routine*           (*           MODULE_ID	 moduleId,    /@ The associated module @/* 	    int		 userArg      /@ An arbitrary user-supplied argument @/*           )* .CE* * The user routine should return TRUE if moduleEach() is to continue* calling it for the remaining modules, or FALSE if moduleEach() should* exit.* * RETURNS: NULL if all modules were examined, or the module ID that* caused the support routine to return FALSE.* * NOMANUAL*/MODULE_ID moduleEach    (    FUNCPTR 	routine,	/* The routine to call */    int		userArg		/* arbitrary user-supplied argument */    )    {    MODULE_ID	 moduleId;    semTake (moduleListSem, WAIT_FOREVER);    for (moduleId = NODE_TO_ID (DLL_LAST (&moduleList));	 moduleId != NULL;	 moduleId = NODE_TO_ID (DLL_PREVIOUS (&moduleId->moduleNode)))	{	/*	 * If the user routine returns false, then return the current	 * module ID	 */	if ((* routine) (moduleId, userArg) == FALSE)	    {	    semGive (moduleListSem);	    return (moduleId);	    }	}    /* Give back the module list semaphore */    semGive (moduleListSem);    return (NULL);    }/******************************************************************************** moduleIdListGet - get a list of loaded modules* * This routine provides the calling task with a list of all loaded* object modules.  An unsorted list of module IDs for no more than* <maxModules> modules is put into <idList>.* * RETURNS: The number of modules put into the ID list, or ERROR.*/int moduleIdListGet    (    MODULE_ID *	idList,		/* array of module IDs to be filled in */    int		maxModules	/* max modules <idList> can accommodate */    )    {    MODULE_ID 	moduleId;	/* current module */    int		count = 0;	/* count of modules put into array */    semTake (moduleListSem, WAIT_FOREVER);        for (moduleId = NODE_TO_ID (DLL_FIRST (&moduleList));	 moduleId != NULL && count < maxModules;	 moduleId = NODE_TO_ID (DLL_NEXT (&moduleId->moduleNode)))	{	idList [count++] = moduleId;	}    semGive (moduleListSem);        return (count);    }/******************************************************************************** moduleSegInfoGet - get information about the segments of a module** This routine fills in a MODULE_SEG_INFO struct with information about the* specified module's segments.* * RETURNS: OK or ERROR*/LOCAL STATUS moduleSegInfoGet    (    MODULE_ID	  	moduleId,	/* module to query */    MODULE_SEG_INFO *	pModSegInfo	/* ptr to module segment info struct */    )    {    SEGMENT_ID		segId;		/* loop variable */    bzero ((char *) pModSegInfo, sizeof (*pModSegInfo));    for (segId = moduleSegFirst (moduleId);	 segId != NULL;	 segId = moduleSegNext (segId))	{	switch (segId->type)	    {	    case SEGMENT_TEXT:		pModSegInfo->textAddr = segId->address;		pModSegInfo->textSize = segId->size;		break;	    case SEGMENT_DATA:		pModSegInfo->dataAddr = segId->address;		pModSegInfo->dataSize = segId->size;		break;	    case SEGMENT_BSS:		pModSegInfo->bssAddr = segId->address;		pModSegInfo->bssSize = segId->size;		break;	    }	} /* for loop end */        return (OK);    }/******************************************************************************** moduleInfoGet - get information about an object module* * This routine fills in a MODULE_INFO structure with information about the* specified module.* * RETURNS: OK or ERROR.*/STATUS moduleInfoGet    (    MODULE_ID	  moduleId,	/* module to return information about */    MODULE_INFO * pModuleInfo	/* pointer to module info struct */    )    {    /* Validate module id */    if (OBJ_VERIFY (moduleId, moduleClassId) != OK)	{	return (ERROR);	}    strcpy (pModuleInfo->name, moduleId->name);    pModuleInfo->format = moduleId->format;    pModuleInfo->group = moduleId->group;    return (moduleSegInfoGet (moduleId, &pModuleInfo->segInfo));    }/******************************************************************************** moduleCheckSegment - compare the current checksum to the recorded checksum*/LOCAL BOOL moduleCheckSegment    (    SEGMENT_ID	segmentId	/* the segment */    )    {    u_short 		cksum;    extern u_short 	checksum();    /*     * Compute the new checksum, and compare it to the     * old one.     */    cksum = checksum (segmentId->address, segmentId->size);    if (cksum != segmentId->checksum)	{	errnoSet (S_moduleLib_BAD_CHECKSUM);	return (FALSE);	}    else	return (TRUE);    }/******************************************************************************** moduleCheckOne - verify checksums on a specific module*/LOCAL BOOL moduleCheckOne    (    MODULE_ID 	moduleId,	/* module to check */    int		options		/* options */    )    {    SEGMENT_ID	segmentId;    STATUS	returnValue = TRUE;    /* If no options are set, default to checking text segments */    if (options == 0)        options = MODCHECK_TEXT;    for (segmentId = moduleSegFirst (moduleId);	 segmentId != NULL;	 segmentId = moduleSegNext (segmentId))	{	if (segmentId->type & options)	    {	    if (moduleCheckSegment (segmentId) == FALSE)		{		if (!(options & MODCHECK_NOPRINT))		    {		    printf ("Checksum error in segment type %d, ",			    segmentId->type);		    printf ("module %#x (%s)\n", (int) moduleId,			    moduleId->name);		    }		returnValue = FALSE;		}	    }	}    return (returnValue);    }    /******************************************************************************** moduleCheck - verify checksums on all modules** This routine verifies the checksums on the segments of all loaded* modules.  If any of the checksums are incorrect, a message is printed to* the console, and the routine returns ERROR.** By default, only the text segment checksum is validated.** Bits in the <options> parameter may be set to control specific checks:* .iP MODCHECK_TEXT* Validate the checksum for the TEXT segment (default).* .iP MODCHECK_DATA* Validate the checksum for the DATA segment.* .iP MODCHECK_BSS* Validate the checksum for the BSS segment.* .iP MODCHECK_NOPRINT* Do not print a message (moduleCheck() still returns ERROR on failure.)* .LP* See the definitions in moduleLib.h** RETURNS: OK, or ERROR if the checksum is invalid.*/STATUS moduleCheck    (    int options			/* validation options */    )    {    if (moduleEach (moduleCheckOne, options) == NULL)        return (OK);    else        return (ERROR);    }/******************************************************************************** moduleNameGet - get the name associated with a module ID** This routine returns a pointer to the name associated with a module ID.** RETURNS: A pointer to the module name, or NULL if the module ID is invalid.*/char * moduleNameGet    (    MODULE_ID moduleId    )    {    if (OBJ_VERIFY (moduleId, moduleClassId) != OK)  /* validate module id */	{	return (NULL);	}    return (moduleId->name);    }/******************************************************************************** moduleFlagsGet - get the flags associated with a module ID** This routine returns the flags associated with a module ID.** RETURNS: The flags associated with the module ID, or NULL if the module ID* is invalid.*/int moduleFlagsGet    (    MODULE_ID moduleId    )    {    if (OBJ_VERIFY (moduleId, moduleClassId) != OK)  /* validate module id */	{	return (NULL);	}    return (moduleId->flags);    }

⌨️ 快捷键说明

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