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

📄 dlsym.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>dlsym</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="dlsym"></a> <a name="tag_03_112"></a><!-- dlsym --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_112_01"></a>NAME</h4><blockquote>dlsym - obtain the address of a symbol from a dlopen object</blockquote><h4><a name="tag_03_112_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include &lt;<a href="../basedefs/dlfcn.h.html">dlfcn.h</a>&gt;<br><br> void *dlsym(void *restrict</tt> <i>handle</i><tt>, const char *restrict</tt> <i>name</i><tt>); <img src="../images/opt-end.gif"alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_112_03"></a>DESCRIPTION</h4><blockquote><p>The <i>dlsym</i>() function shall obtain the address of a symbol defined within an object made accessible through a <a href="../functions/dlopen.html"><i>dlopen</i>()</a> call. The <i>handle</i> argument is the value returned from a call to <a href="../functions/dlopen.html"><i>dlopen</i>()</a> (and which has not since been released via a call to <a href="../functions/dlclose.html"><i>dlclose</i>()</a>), and <i>name</i> is the symbol's name as a character string.</p><p>The <i>dlsym</i>() function shall search for the named symbol in all objects loaded automatically as a result of loading theobject referenced by <i>handle</i> (see <a href="dlopen.html"><i>dlopen</i>()</a> ). Load ordering is used in <i>dlsym</i>()operations upon the global symbol object. The symbol resolution algorithm used shall be dependency order as described in <a href="dlopen.html"><i>dlopen</i>()</a> .</p><p>The RTLD_DEFAULT and RTLD_NEXT flags are reserved for future use.</p></blockquote><h4><a name="tag_03_112_04"></a>RETURN VALUE</h4><blockquote><p>If <i>handle</i> does not refer to a valid object opened by <a href="../functions/dlopen.html"><i>dlopen</i>()</a>, or if thenamed symbol cannot be found within any of the objects associated with <i>handle</i>, <i>dlsym</i>() shall return NULL. Moredetailed diagnostic information shall be available through <a href="dlerror.html"><i>dlerror</i>()</a> .</p></blockquote><h4><a name="tag_03_112_05"></a>ERRORS</h4><blockquote><p>No errors are defined.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_112_06"></a>EXAMPLES</h4><blockquote><p>The following example shows how <a href="../functions/dlopen.html"><i>dlopen</i>()</a> and <i>dlsym</i>() can be used to accesseither function or data objects. For simplicity, error checking has been omitted.</p><pre><tt>void    *handle;int     *iptr, (*fptr)(int);<br>/* open the needed object */handle = dlopen("/usr/home/me/libfoo.so", RTLD_LOCAL | RTLD_LAZY);<br>/* find the address of function and data objects */*(void **)(&amp;fptr) = dlsym(handle, "my_function");iptr = (int *)dlsym(handle, "my_object");<br>/* invoke function, passing value of integer as a parameter */(*fptr)(*iptr);</tt></pre></blockquote><h4><a name="tag_03_112_07"></a>APPLICATION USAGE</h4><blockquote><p>Special purpose values for <i>handle</i> are reserved for future use. These values and their meanings are:</p><dl compact><dt>RTLD_DEFAULT</dt><dd>The symbol lookup happens in the normal global scope; that is, a search for a symbol using this handle would find the samedefinition as a direct use of this symbol in the program code.</dd><dt>RTLD_NEXT</dt><dd>Specifies the next object after this one that defines <i>name</i>. <i>This one</i> refers to the object containing theinvocation of <i>dlsym</i>(). The <i>next</i> object is the one found upon the application of a load order symbol resolutionalgorithm (see <a href="dlopen.html"><i>dlopen</i>()</a> ). The next object is either one of global scope (because it wasintroduced as part of the original process image or because it was added with a <a href="../functions/dlopen.html"><i>dlopen</i>()</a> operation including the RTLD_GLOBAL flag), or is an object that was included in thesame <a href="../functions/dlopen.html"><i>dlopen</i>()</a> operation that loaded this one. <p>The RTLD_NEXT flag is useful to navigate an intentionally created hierarchy of multiply-defined symbols created through<i>interposition</i>. For example, if a program wished to create an implementation of <a href="../functions/malloc.html"><i>malloc</i>()</a> that embedded some statistics gathering about memory allocations, such animplementation could use the real <a href="../functions/malloc.html"><i>malloc</i>()</a> definition to perform the memoryallocation-and itself only embed the necessary logic to implement the statistics gathering function.</p></dd></dl></blockquote><h4><a name="tag_03_112_08"></a>RATIONALE</h4><blockquote><p>The ISO&nbsp;C standard does not require that pointers to functions can be cast back and forth to pointers to data. Indeed, theISO&nbsp;C standard does not require that an object of type <b>void *</b> can hold a pointer to a function. Implementationssupporting the XSI extension, however, do require that an object of type <b>void *</b> can hold a pointer to a function. The resultof converting a pointer to a function into a pointer to another data type (except <b>void *</b>) is still undefined, however. Notethat compilers conforming to the ISO&nbsp;C standard are required to generate a warning if a conversion from a <b>void *</b>pointer to a function pointer is attempted as in:</p><pre><tt>fptr = (int (*)(int))dlsym(handle, "my_function");</tt></pre><p>Due to the problem noted here, a future version may either add a new function to return function pointers, or the currentinterface may be deprecated in favor of two new functions: one that returns data pointers and the other that returns functionpointers.</p></blockquote><h4><a name="tag_03_112_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_112_10"></a>SEE ALSO</h4><blockquote><p><a href="dlclose.html"><i>dlclose</i>()</a> , <a href="dlerror.html"><i>dlerror</i>()</a> , <a href="dlopen.html"><i>dlopen</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/dlfcn.h.html"><i>&lt;dlfcn.h&gt;</i></a></p></blockquote><h4><a name="tag_03_112_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 5.</p></blockquote><h4><a name="tag_03_112_12"></a>Issue 6</h4><blockquote><p>The <b>restrict</b> keyword is added to the <i>dlsym</i>() prototype for alignment with the ISO/IEC&nbsp;9899:1999 standard.</p><p>The RTLD_DEFAULT and RTLD_NEXT flags are reserved for future use.</p><p>IEEE&nbsp;Std 1003.1-2001/Cor&nbsp;1-2002, item XSH/TC1/D6/14 is applied, correcting an example, and adding text to theRATIONALE describing issues related to conversion of pointers to functions and back again.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

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