📄 addrinfo.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. * *---------------------------------------------------------------------- *//* * @(#)addrinfo.c (libdl) * * DLL support library * Address information */#include "libdl.h"#include "symtab.h"#define ERR_DLADDR 0 /* error code (dladdr) */#include <tm/tmonitor.h>/* * Specified address library information acquisition * Return the information on the library that owns the address specified in "addr" to the "info". * Additionaly,return the access handle of the shared object to the return value. * Return E_NOEXS if there is no shared object at "addr" location. * * typedef struct { * ATR atr; object attribute * VP path; filename * VP fbase; base address * const B *sname; symbol name * VP saddr; symbol address * } T_DLINFO; * * atr; object attribute * path filename * fbase Load address of the shared object * sname Symbol name of the nearest location in "addr" location or * the address smaller than "addr" * saddr Symbol value of sname (Address) */EXPORT WER tkse_dladdr( VP addr, T_DLINFO *info ){ DLInfo *dlp; Elf32_Sym *symtab, *end, *match; UW saddr; ER err; err = LockDL(); if ( err < E_OK ) { goto err_ret1; } /* Target object search */ dlp = __addrdlinfo(addr); if ( dlp == NULL ) { err = E_NOEXS; goto err_ret2; } symtab = dlp->symtab; end = GET_SYMTAB_END(symtab, dlp); saddr = (UW)addr - (UW)dlp->ldofs; match = symtab; while ( ++symtab < end ) { if (( (UW)symtab->st_value <= saddr ) &&( (UW)symtab->st_value > (UW)match->st_value )) { switch ( ELF32_ST_BIND(symtab->st_info) ) { case STB_GLOBAL: case STB_WEAK: match = symtab; default: /* nothing to do */ break; } } } /* Storage of the shared object information */ info->path = (VP)(dlp->soHdr.src.path); info->fbase = (VP)(dlp->ldofs); info->sname = (const B *)(( match->st_name == 0U ) ? NULL: (dlp->strtab + match->st_name)); info->saddr = (VP)(( dlp->symtab == match ) ? NULL: ((B*)match->st_value + dlp->ldofs)); UnlockDL(); return (WER)DLInfoID(dlp);err_ret2: UnlockDL();err_ret1: DEBUG_PRINT(("tkse_dladdr err = %d\n", err)); return err;}/* * Specified address library information acquisition * */EXPORT int dladdr( void *addr, Dl_info *info ){ WER err; T_DLINFO dlInfo; err = tkse_dladdr( addr, &dlInfo ); if (err < E_OK) { err = ERR_DLADDR; } info->dli_fname = (char *)(dlInfo.path); info->dli_fbase = dlInfo.fbase; info->dli_sname = dlInfo.sname; info->dli_saddr = dlInfo.saddr; return (int)err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -