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

📄 symbol.c

📁 T-kernel 的extension源代码
💻 C
字号:
/* *---------------------------------------------------------------------- *    T-Kernel / Standard Extension * *    Copyright (C) 2006 by Ken Sakamura. All rights reserved. *    T-Kernel / Standard Extension is distributed  *      under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * *    Version:   1.00.00 *    Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* *	@(#)symbol.c (libdl)  * *	DLL support library *	Reference to symbol */#include "libdl.h"#include <tm/tmonitor.h>/* * Search the shared object of the specified address.  */EXPORT DLInfo* __addrdlinfo( VP addr ){	QUEUE		*q;	P_DYNLDINF	*ldinf;	q = &__dlInfo.q;	do {		ldinf = &((DLInfo*)q)->ldinf;		if (( (UW)addr >= (UW)ldinf->loadaddr )		  &&( (UW)addr < ((UW)ldinf->loadaddr + ldinf->loadsize)) ) {			return (DLInfo*)q;		}	} while ( (q = q->next) != &__dlInfo.q );	return NULL;}/* * Reference to symbol *	Search the symbol specified at "symbol" from the shared object specified at "handle", *	and return the value to "val". *	Return "E_NOEXS" when symbol is not found. In this case, return "NULL" to "val". * *	The following special "handle" are usable. *	DL_DEFAULT	Search the global symbol. *	DL_NEXT		Search the local scope.  */EXPORT ER tkse_dlsym( W handle, const char *symbol, UW *val ){	VP		retaddr = (VP)__builtin_return_address(0);	DLInfo		*dlp;	Elf32_Sym	*sym;	ER		err;	err = LockDL();	if ( err < E_OK ) {		goto err_ret1;	}	switch ( handle ) {	  case DL_DEFAULT:		*val = __so_resolve(&__dlInfo, (UB*)symbol, 0, &sym);		break;	  case DL_NEXT:		dlp = __addrdlinfo(retaddr);		if ( dlp == NULL ) {			err = E_NOEXS;			goto err_ret2;		}				if ( dlp->loader != NULL ) {			*val = __so_localresolve(dlp->loader, (UB*)symbol, dlp, &sym);		} else {			*val = __so_localresolve(dlp, (UB*)symbol, dlp, &sym);		}		break;	  default:		dlp = __getdlinfo(handle);		if ( dlp == NULL ) {			err = E_PAR;			goto err_ret2;		}		*val = __so_localresolve(dlp, (UB*)symbol, 0, &sym);		break;	}	if ( sym == NULL ) {		err = E_NOEXS;		goto err_ret2;	}	UnlockDL();	return E_OK;err_ret2:	UnlockDL();err_ret1:	DEBUG_PRINT(("tkse_dlsym err = %d\n", err));	return err;}/* * Reference to symbol (POSIX I/F) * */extern int	printf( const char *format, ... );EXPORT void *dlsym(void *handle, const char *symbol){	ER err;	UW func;	if ((handle == RTLD_DEFAULT) || (handle == RTLD_NEXT)) {		err = tkse_dlsym( (W)handle, symbol, &func );	} else {		err = tkse_dlsym( *(W *)handle, symbol, &func );	}	if (err >= E_OK) {		return (void *)func;	} else {		return NULL;	}}

⌨️ 快捷键说明

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