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

📄 loadlib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 2 页
字号:
*     pText = 0x800000;			/@ address of text segment	  @/*     pData = pBss = LD_NO_ADDRESS	/@ other segments follow by default @/*     module_id = loadModuleAt (fd, LOAD_GLOBAL_SYMBOLS, &pText, &pData, &pBss);* .CE** RETURNS:* MODULE_ID, or* NULL if the file cannot be read, there is not enough memory,* or the file format is illegal.** SEE ALSO:* .pG "Basic OS"*/MODULE_ID loadModuleAt    (    FAST int fd,	/* fd from which to read module */    int symFlag,	/* symbols to add to table */			/* (LOAD_[NO | LOCAL | GLOBAL | ALL]_SYMBOLS) */    char **ppText,      /* load text segment at addr. pointed to by this */			/* ptr, return load addr. via this ptr */    char **ppData,      /* load data segment at addr. pointed to by this */			/* pointer, return load addr. via this ptr */    char **ppBss	/* load BSS segment at addr. pointed to by this */			/* pointer, return load addr. via this ptr */    )    {    return (loadModuleAtSym (fd, symFlag, ppText, ppData, ppBss, sysSymTbl));    }/******************************************************************************** loadModuleAtSym - load object module into memory with specified symbol table** This routine is the underlying routine to loadModuleAt().  This interface* allows specification of the the symbol table used to resolve undefined* external references and to which to add new symbols.** RETURNS:* MODULE_ID, or* NULL if can't read file or not enough memory or illegal file format** NOMANUAL*/MODULE_ID loadModuleAtSym    (    FAST int fd,	/* fd from which to read module */    int symFlag,	/* symbols to be added to table			 *   ([NO | GLOBAL | ALL]_SYMBOLS) */    char **ppText,      /* load text segment at address pointed to by this			 * pointer, return load address via this pointer */    char **ppData,      /* load data segment at address pointed to by this			 * pointer, return load address via this pointer */    char **ppBss,       /* load bss segment at address pointed to by this			 * pointer, return load address via this pointer */    SYMTAB_ID symTbl    /* symbol table to use */    )    {    MODULE_ID module;    if (loadRoutine == NULL)	{	errnoSet (S_loadLib_ROUTINE_NOT_INSTALLED);	return (NULL);	}    else	{	module = (MODULE_ID) (*loadRoutine) (fd, symFlag, ppText, ppData, ppBss,					    symTbl);	if (module != NULL)	    {	    cplusLoadFixup (module, symFlag, symTbl);	    /* synchronize host symbol table if necessary */		    if (syncLoadRtn != NULL)		(* syncLoadRtn) (module);	    }	return module;	}    }/******************************************************************************** loadModuleGet - create module information for a loaded object module** RETURNS:  MODULE_ID, or NULL if module could not be created.** NOMANUAL*/MODULE_ID loadModuleGet    (    char * 	fileName,	/* name of the module */    int		format,		/* object module format */    int	*	symFlag		/* pointer to symFlag */    )    {    MODULE_ID	moduleId;    /* Change old style flags to new style */    switch (*symFlag)	{	case NO_SYMBOLS:	    *symFlag = LOAD_NO_SYMBOLS;	    break;	case GLOBAL_SYMBOLS:	    *symFlag = LOAD_GLOBAL_SYMBOLS;	    break;	case ALL_SYMBOLS:	    *symFlag = LOAD_ALL_SYMBOLS;	    break;	}    moduleId = moduleCreate (fileName, format, *symFlag);    return (moduleId);    }/********************************************************************************* addSegNames - add segment names to symbol table** This routine adds names of the form "objectFile.o_text," objectFile.o_data,"* and "objectFile.o_bss" to the symbol table.** NOMANUAL*/void addSegNames    (    int		fd,		/* file descriptor for the object file */    char	*pText,		/* pointer to the text segment */    char	*pData,		/* pointer to the data segment */    char	*pBss,		/* pointer to the BSS segment */    SYMTAB_ID   symTbl,		/* symbol table to use */    UINT16	group		/* group number */    )    {    char fullname [MAX_FILENAME_LENGTH];    char symName[MAX_SYS_SYM_LEN + 1];    char *pName;    if (ioctl (fd, FIOGETNAME, (int) fullname) == OK)	pName = pathLastNamePtr (fullname);	/* get last simple name */    else	pName = "???";    /* XXX     * Adding these symbols is now obsolete, and should probably     * be removed in a future version of the OS.  For now, leave them     * in for backwards compatability.     */    if (pText != NULL)	{	sprintf (symName, "%s_text", pName);	if (symSAdd (symTbl, symName, pText, (N_EXT | N_TEXT), group) != OK)	    printErr (cantAddSymErrMsg, symName, errnoGet());	}    if (pData != NULL)	{	sprintf (symName, "%s_data", pName);	if (symSAdd (symTbl, symName, pData, (N_EXT | N_DATA), group) != OK)	    printErr (cantAddSymErrMsg, symName, errnoGet());	}    if (pBss != NULL)	{	sprintf (symName,  "%s_bss",  pName);	if (symSAdd (symTbl, symName, pBss, (N_EXT | N_BSS), group) != OK)	    printErr (cantAddSymErrMsg, symName, errnoGet());	}    }/******************************************************************************** loadSegmentsAllocate - allocate text, data, and bss segments** This routine allocates memory for the text, data, and bss segments of* an object module.  Before calling this routine, set up the fields of the* SEG_INFO structure to specify the desired location and size of each segment.** RETURNS: OK, or ERROR if memory couldn't be allocated.** NOMANUAL*/STATUS loadSegmentsAllocate    (    SEG_INFO *	pSeg		/* pointer to segment information */    )    {    BOOL 	protectText = FALSE;    int 	pageSize;    int		alignment = 0;    int		textAlignment = pSeg->flagsText; /* save text alignment */    int		dataAlignment = pSeg->flagsData; /* save data alignment */    int		bssAlignment = pSeg->flagsBss;	 /* save bss alignment */    /* clear pSeg->flags<xxx> fields */    pSeg->flagsText = 0;    pSeg->flagsData = 0;    pSeg->flagsBss = 0;    /*     * if text segment protection is selected, then allocate the text     * segment seperately on a page boundry     */    if ((pSeg->sizeText != 0) && vmLibInfo.protectTextSegs	&& (pSeg->addrText == LD_NO_ADDRESS))	{	if ((pageSize = VM_PAGE_SIZE_GET()) == ERROR)	    return (ERROR);	/* round text size to integral number of pages */	pSeg->sizeProtectedText = pSeg->sizeText / pageSize * pageSize				  + pageSize;	/*	 * get the section alignment (maximum between page size and section	 * alignment specified in the file).	 */	alignment = max(pageSize, textAlignment);	if ((pSeg->addrText = memalign (alignment,					pSeg->sizeProtectedText)) == NULL)	    return (ERROR);	pSeg->flagsText |= SEG_WRITE_PROTECTION;	pSeg->flagsText |= SEG_FREE_MEMORY;	protectText = TRUE;	}    /* if all addresses are unspecified, allocate one large chunk of memory */    if (pSeg->addrText == LD_NO_ADDRESS &&	pSeg->addrData == LD_NO_ADDRESS &&	pSeg->addrBss  == LD_NO_ADDRESS)	{	/* SPR #21836 */	alignment = 0;	if (textAlignment > dataAlignment)	    alignment = max (textAlignment, bssAlignment);	else	    alignment = max (dataAlignment, bssAlignment);	if (alignment != 0)	    pSeg->addrText = memalign (alignment, pSeg->sizeText + 				       pSeg->sizeData + pSeg->sizeBss);	else	    pSeg->addrText = malloc (pSeg->sizeText + pSeg->sizeData +				     pSeg->sizeBss);	/* check for malloc error */	if (pSeg->addrText == NULL)	    return (ERROR);	pSeg->addrData = pSeg->addrText + pSeg->sizeText;	pSeg->addrBss = pSeg->addrData + pSeg->sizeData;	pSeg->flagsText |= SEG_FREE_MEMORY;	}    /* if addresses not specified, allocate memory. */    if (pSeg->addrText == LD_NO_ADDRESS && pSeg->sizeText != 0)	{	/* SPR #21836 */	if (textAlignment != 0)	    {	    if ((pSeg->addrText = (char *) memalign (textAlignment,		pSeg->sizeText)) == NULL)		return (ERROR);	    }	else	    {	    if ((pSeg->addrText = (char *) malloc (pSeg->sizeText)) == NULL)		return (ERROR);	    }	pSeg->flagsText |= SEG_FREE_MEMORY;	}    if (pSeg->addrData == LD_NO_ADDRESS && pSeg->sizeData != 0)	{	/* SPR #21836 */	if (dataAlignment != 0)	    {	    if ((pSeg->addrData = (char *) memalign (dataAlignment,		pSeg->sizeData)) == NULL)		return (ERROR);	    }	else	    {	    if ((pSeg->addrData = (char *) malloc (pSeg->sizeData)) == NULL)		return (ERROR);	    }	pSeg->flagsData |= SEG_FREE_MEMORY;	}    if (pSeg->addrBss == LD_NO_ADDRESS && pSeg->sizeBss)	{	/* SPR #21836 */	if (bssAlignment != 0)	    {	    if ((pSeg->addrBss = (char *) memalign (bssAlignment,		pSeg->sizeBss)) == NULL)		return (ERROR);	    }	else	    {	    if ((pSeg->addrBss = (char *) malloc (pSeg->sizeBss)) == NULL)		return (ERROR);	    }	pSeg->flagsBss |= SEG_FREE_MEMORY;	}    return (OK);    }

⌨️ 快捷键说明

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