VirtualBox

source: vbox/trunk/include/iprt/ldr.h@ 12142

Last change on this file since 12142 was 11888, checked in by vboxsync, 17 years ago

IPRT: added RTLdrGetSuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
1/** @file
2 * IPRT - Loader.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_ldr_h
31#define ___iprt_ldr_h
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35
36
37/** @defgroup grp_ldr RTLdr - Loader
38 * @ingroup grp_rt
39 * @{
40 */
41
42__BEGIN_DECLS
43
44
45/**
46 * Gets the default file suffix for DLL/SO/DYLIB/whatever.
47 *
48 * @returns The stuff (readonly).
49 */
50RTDECL(const char *) RTLdrGetSuff(void);
51
52/**
53 * Loads a dynamic load library (/shared object) image file using native
54 * OS facilities.
55 *
56 * The filename will be appended the default DLL/SO extension of
57 * the platform if it have been omitted. This means that it's not
58 * possible to load DLLs/SOs with no extension using this interface,
59 * but that's not a bad tradeoff.
60 *
61 * If no path is specified in the filename, the OS will usually search it's library
62 * path to find the image file.
63 *
64 * @returns iprt status code.
65 * @param pszFilename Image filename.
66 * @param phLdrMod Where to store the handle to the loader module.
67 */
68RTDECL(int) RTLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
69
70/**
71 * Loads a dynamic load library (/shared object) image file using native
72 * OS facilities.
73 *
74 * If the path is specified in the filename, only this path is used.
75 * If only the image file name is specified, then try to load it from:
76 * - RTPathAppPrivateArch
77 * - RTPathSharedLibs (legacy)
78 *
79 * @returns iprt status code.
80 * @param pszFilename Image filename.
81 * @param phLdrMod Where to store the handle to the loaded module.
82 */
83RTDECL(int) RTLdrLoadAppSharedLib(const char *pszFilename, PRTLDRMOD phLdrMod);
84
85/**
86 * Open a binary image file.
87 *
88 * @returns iprt status code.
89 * @param pszFilename Image filename.
90 * @param phLdrMod Where to store the handle to the loader module.
91 */
92RTDECL(int) RTLdrOpen(const char *pszFilename, PRTLDRMOD phLdrMod);
93
94/**
95 * Opens a binary image file using kLdr.
96 *
97 * @returns iprt status code.
98 * @param pszFilename Image filename.
99 * @param phLdrMod Where to store the handle to the loaded module.
100 * @remark Primarily for testing the loader.
101 */
102RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, PRTLDRMOD phLdrMod);
103
104/**
105 * What to expect and do with the bits passed to RTLdrOpenBits().
106 */
107typedef enum RTLDROPENBITS
108{
109 /** The usual invalid 0 entry. */
110 RTLDROPENBITS_INVALID = 0,
111 /** The bits are readonly and will never be changed. */
112 RTLDROPENBITS_READONLY,
113 /** The bits are going to be changed and the loader will have to duplicate them
114 * when opening the image. */
115 RTLDROPENBITS_WRITABLE,
116 /** The bits are both the source and destination for the loader operation.
117 * This means that the loader may have to duplicate them prior to changing them. */
118 RTLDROPENBITS_SRC_AND_DST,
119 /** The end of the valid enums. This entry marks the
120 * first invalid entry.. */
121 RTLDROPENBITS_END,
122 RTLDROPENBITS_32BIT_HACK = 0x7fffffff
123} RTLDROPENBITS;
124
125/**
126 * Open a binary image from in-memory bits.
127 *
128 * @returns iprt status code.
129 * @param pvBits The start of the raw-image.
130 * @param cbBits The size of the raw-image.
131 * @param enmBits What to expect from the pvBits.
132 * @param pszLogName What to call the raw-image when logging.
133 * For RTLdrLoad and RTLdrOpen the filename is used for this.
134 * @param phLdrMod Where to store the handle to the loader module.
135 */
136RTDECL(int) RTLdrOpenBits(const void *pvBits, size_t cbBits, RTLDROPENBITS enmBits, const char *pszLogName, PRTLDRMOD phLdrMod);
137
138/**
139 * Closes a loader module handle.
140 *
141 * The handle can be obtained using any of the RTLdrLoad(), RTLdrOpen()
142 * and RTLdrOpenBits() functions.
143 *
144 * @returns iprt status code.
145 * @param hLdrMod The loader module handle.
146 */
147RTDECL(int) RTLdrClose(RTLDRMOD hLdrMod);
148
149/**
150 * Gets the address of a named exported symbol.
151 *
152 * @returns iprt status code.
153 * @param hLdrMod The loader module handle.
154 * @param pszSymbol Symbol name.
155 * @param ppvValue Where to store the symbol value. Note that this is restricted to the
156 * pointer size used on the host!
157 */
158RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue);
159
160/**
161 * Gets the address of a named exported symbol.
162 *
163 * This function differs from the plain one in that it can deal with
164 * both GC and HC address sizes, and that it can calculate the symbol
165 * value relative to any given base address.
166 *
167 * @returns iprt status code.
168 * @param hLdrMod The loader module handle.
169 * @param pvBits Optional pointer to the loaded image.
170 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
171 * Not supported for RTLdrLoad() images.
172 * @param BaseAddress Image load address.
173 * Not supported for RTLdrLoad() images.
174 * @param pszSymbol Symbol name.
175 * @param pValue Where to store the symbol value.
176 */
177RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTUINTPTR BaseAddress, const char *pszSymbol, RTUINTPTR *pValue);
178
179/**
180 * Gets the size of the loaded image.
181 * This is only supported for modules which has been opened using RTLdrOpen() and RTLdrOpenBits().
182 *
183 * @returns image size (in bytes).
184 * @returns ~(size_t)0 on if not opened by RTLdrOpen().
185 * @param hLdrMod Handle to the loader module.
186 * @remark Not supported for RTLdrLoad() images.
187 */
188RTDECL(size_t) RTLdrSize(RTLDRMOD hLdrMod);
189
190/**
191 * Resolve an external symbol during RTLdrGetBits().
192 *
193 * @returns iprt status code.
194 * @param hLdrMod The loader module handle.
195 * @param pszModule Module name.
196 * @param pszSymbol Symbol name, NULL if uSymbol should be used.
197 * @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
198 * @param pValue Where to store the symbol value (address).
199 * @param pvUser User argument.
200 */
201typedef DECLCALLBACK(int) RTLDRIMPORT(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser);
202/** Pointer to a FNRTLDRIMPORT() callback function. */
203typedef RTLDRIMPORT *PFNRTLDRIMPORT;
204
205/**
206 * Loads the image into a buffer provided by the user and applies fixups
207 * for the given base address.
208 *
209 * @returns iprt status code.
210 * @param hLdrMod The load module handle.
211 * @param pvBits Where to put the bits.
212 * Must be as large as RTLdrSize() suggests.
213 * @param BaseAddress The base address.
214 * @param pfnGetImport Callback function for resolving imports one by one.
215 * @param pvUser User argument for the callback.
216 * @remark Not supported for RTLdrLoad() images.
217 */
218RTDECL(int) RTLdrGetBits(RTLDRMOD hLdrMod, void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);
219
220/**
221 * Relocates bits after getting them.
222 * Useful for code which moves around a bit.
223 *
224 * @returns iprt status code.
225 * @param hLdrMod The loader module handle.
226 * @param pvBits Where the image bits are.
227 * Must've been passed to RTLdrGetBits().
228 * @param NewBaseAddress The new base address.
229 * @param OldBaseAddress The old base address.
230 * @param pfnGetImport Callback function for resolving imports one by one.
231 * @param pvUser User argument for the callback.
232 * @remark Not supported for RTLdrLoad() images.
233 */
234RTDECL(int) RTLdrRelocate(RTLDRMOD hLdrMod, void *pvBits, RTUINTPTR NewBaseAddress, RTUINTPTR OldBaseAddress,
235 PFNRTLDRIMPORT pfnGetImport, void *pvUser);
236
237/**
238 * Enumeration callback function used by RTLdrEnumSymbols().
239 *
240 * @returns iprt status code. Failure will stop the enumeration.
241 * @param hLdrMod The loader module handle.
242 * @param pszSymbol Symbol name. NULL if ordinal only.
243 * @param uSymbol Symbol ordinal, ~0 if not used.
244 * @param Value Symbol value.
245 * @param pvUser The user argument specified to RTLdrEnumSymbols().
246 */
247typedef DECLCALLBACK(int) RTLDRENUMSYMS(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTUINTPTR Value, void *pvUser);
248/** Pointer to a RTLDRENUMSYMS() callback function. */
249typedef RTLDRENUMSYMS *PFNRTLDRENUMSYMS;
250
251/**
252 * Enumerates all symbols in a module.
253 *
254 * @returns iprt status code.
255 * @param hLdrMod The loader module handle.
256 * @param fFlags Flags indicating what to return and such.
257 * @param pvBits Optional pointer to the loaded image. (RTLDR_ENUM_SYMBOL_FLAGS_*)
258 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
259 * @param BaseAddress Image load address.
260 * @param pfnCallback Callback function.
261 * @param pvUser User argument for the callback.
262 * @remark Not supported for RTLdrLoad() images.
263 */
264RTDECL(int) RTLdrEnumSymbols(RTLDRMOD hLdrMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
265
266/** @name RTLdrEnumSymbols flags.
267 * @{ */
268/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
269#define RTLDR_ENUM_SYMBOL_FLAGS_ALL RT_BIT(1)
270/** @} */
271
272__END_DECLS
273
274/** @} */
275
276#endif
277
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette