annotate doc/manual/manual_dynload_api.tex @ 663:127b569978cc default tip

- another tweak handling clang trying to be too smart (see last commit)
author Tassilo Philipp
date Sun, 24 Mar 2024 13:52:44 +0100
parents 17287342e273
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 %//////////////////////////////////////////////////////////////////////////////
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 %
228
f8a6e60598cc - completed dynload API doc
Tassilo Philipp
parents: 0
diff changeset
3 % Copyright (c) 2007-2017 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 % Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 %
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 % Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 % purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 % copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 %
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 % THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 % WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 % MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 % ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 % WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 % ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 % OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 %
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 %//////////////////////////////////////////////////////////////////////////////
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 \section{\product{Dynload} C library API}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21
490
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
22 See the dynload(3) manpage for more information.
228
f8a6e60598cc - completed dynload API doc
Tassilo Philipp
parents: 0
diff changeset
23
490
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
24 %@@@ removed, as manpages are more precise and up to date ------------------->
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
25 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
26 %The \product{dynload} library encapsulates dynamic loading mechanisms and
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
27 %gives access to functions in foreign dynamic libraries and code modules.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
28 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
29 %\subsection{Loading code}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
30 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
31 %\begin{lstlisting}[language=c,label=dl-load]
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
32 %DLLib* dlLoadLibrary(const char* libpath);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
33 %void dlFreeLibrary(void* libhandle);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
34 %\end{lstlisting}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
35 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
36 %\lstinline{dlLoadLibrary} loads a dynamic library at \lstinline{libpath}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
37 %and returns a handle to it for use in \lstinline{dlFreeLibrary} and
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
38 %\lstinline{dlFindSymbol} calls. Passing a null pointer for the \lstinline{libpath}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
39 %argument is valid, and returns a handle to the main executable of the calling code.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
40 %Also, searching libraries in library paths (e.g. by just passing the library's leaf
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
41 %name) should work, however, they are OS specific. Returns a null pointer on error.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
42 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
43 %\lstinline{dlFreeLibrary} frees the loaded library with handle \lstinline{pLib}.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
44 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
45 %\subsection{Retrieving functions}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
46 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
47 %\begin{lstlisting}[language=c]
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
48 %void* dlFindSymbol(void* libhandle, const char* symbol);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
49 %\end{lstlisting}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
50 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
51 %This function returns a pointer to a symbol with name \lstinline{pSymbolName} in the
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
52 %library with handle \lstinline{pLib}, or returns a null pointer if the symbol cannot
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
53 %be found. The name is specified as it would appear in C source code (mangled if C++, etc.).
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
54 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
55 %\subsection{Misc functions}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
56 %\begin{lstlisting}[language=c]
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
57 %int dlGetLibraryPath(DLLib* pLib, char* sOut, int bufSize);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
58 %\end{lstlisting}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
59 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
60 %This function can be used to get a copy of the path to the library loaded with handle
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
61 %\lstinline{pLib}. The parameter \lstinline{sOut} is a pointer to a buffer of size
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
62 %\lstinline{bufSize} (in bytes), to hold the output string. The return value is the size
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
63 %of the buffer (in bytes) needed to hold the null-terminated string, or 0 if it can't be
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
64 %looked up. If \lstinline{bufSize} \textgreater= return value \textgreater 1, a null-terminted string with the
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
65 %path to the library should be in \lstinline{sOut}. If it returns 0, the library name wasn't
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
66 %able to be found. Please note that this might happen in some rare cases, so make sure to always check.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
67 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
68 %\subsection{Symbol iteration}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
69 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
70 %\begin{lstlisting}[language=c]
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
71 %DLSyms* dlSymsInit(const char* libPath);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
72 %void dlSymsCleanup(DLSyms* pSyms);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
73 %int dlSymsCount(DLSyms* pSyms);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
74 %const char* dlSymsName(DLSyms* pSyms, int index);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
75 %const char* dlSymsNameFromValue(DLSyms* pSyms, void* value); /* symbol must be loaded */
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
76 %\end{lstlisting}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
77 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
78 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
79 %These functions can be used to iterate over symbols. Since they can be used on libraries that are not linked, they are made
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
80 %for symbol name lookups, not to get a symbol's address. For that refer to
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
81 %\lstinline{dlFindSymbol}. \lstinline{dlSymsInit} will return a handle (or a null pointer
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
82 %on error) to the shared object specified by \lstinline{libPath}, to be used with the other dlSyms* functions. Note that contrary
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
83 %to loading and linking libraries, no (OS-specific) rules for searching libraries in library paths, etc. apply. The handle must be freed with
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
84 %\lstinline{dlSymsCleanup}. \lstinline{dlSymsCount} returns the number of
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
85 %symbols in the shared object, \lstinline{dlSymsName} and \lstinline{dlSymsNameFromValue}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
86 %are used to lookup symbol names using an index or symbol's address, respectively,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
87 %returning a null pointer on error. The names are returned as they would appear
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
88 %in C source code (mangled if C++, etc.). The address passed to \lstinline{dlSymsNameFromValue}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
89 %must point to a loaded symbol.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
90 %