VirtualBox

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

Last change on this file since 35152 was 35152, checked in by vboxsync, 14 years ago

*: added fFlags parameter to SUPR3HardenedLdrLoadAppPriv(), SUPR3HardenedLdrLoad() and RTLdrLoadEx(). VBoxSVC: slurp in VBoxVMM because it is required by the extension packs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 KB
Line 
1/** @file
2 * IPRT - Loader.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
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
26#ifndef ___iprt_ldr_h
27#define ___iprt_ldr_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31
32
33/** @defgroup grp_ldr RTLdr - Loader
34 * @ingroup grp_rt
35 * @{
36 */
37
38/** Symbols defined in this library are not made available to resolve
39 * references in subsequently loaded libraries (default). */
40#define RTLDRFLAGS_LOCAL 0
41/** Symbols defined in this library will be made available for symbol
42 * resolution of subsequently loaded libraries. */
43#define RTLDRFLAGS_GLOBAL RT_BIT(0)
44
45
46RT_C_DECLS_BEGIN
47
48
49/**
50 * Gets the default file suffix for DLL/SO/DYLIB/whatever.
51 *
52 * @returns The stuff (readonly).
53 */
54RTDECL(const char *) RTLdrGetSuff(void);
55
56/**
57 * Checks if a library is loadable or not.
58 *
59 * This may attempt load and unload the library.
60 *
61 * @returns true/false accordingly.
62 * @param pszFilename Image filename.
63 */
64RTDECL(bool) RTLdrIsLoadable(const char *pszFilename);
65
66/**
67 * Loads a dynamic load library (/shared object) image file using native
68 * OS facilities.
69 *
70 * The filename will be appended the default DLL/SO extension of
71 * the platform if it have been omitted. This means that it's not
72 * possible to load DLLs/SOs with no extension using this interface,
73 * but that's not a bad tradeoff.
74 *
75 * If no path is specified in the filename, the OS will usually search it's library
76 * path to find the image file.
77 *
78 * @returns iprt status code.
79 * @param pszFilename Image filename.
80 * @param phLdrMod Where to store the handle to the loader module.
81 */
82RTDECL(int) RTLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
83
84/**
85 * Loads a dynamic load library (/shared object) image file using native
86 * OS facilities.
87 *
88 * The filename will be appended the default DLL/SO extension of
89 * the platform if it have been omitted. This means that it's not
90 * possible to load DLLs/SOs with no extension using this interface,
91 * but that's not a bad tradeoff.
92 *
93 * If no path is specified in the filename, the OS will usually search it's library
94 * path to find the image file.
95 *
96 * @returns iprt status code.
97 * @param pszFilename Image filename.
98 * @param phLdrMod Where to store the handle to the loader module.
99 * @param fFlags See RTLDFLAGS_.
100 * @param pszError Where to store an error message on failure. Optional.
101 * @param cbError The size of the buffer pointed to by @a pszError.
102 */
103RTDECL(int) RTLdrLoadEx(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, char *pszError, size_t cbError);
104
105/**
106 * Loads a dynamic load library (/shared object) image file residing in the
107 * RTPathAppPrivateArch() directory.
108 *
109 * Suffix is not required.
110 *
111 * @returns iprt status code.
112 * @param pszFilename Image filename. No path.
113 * @param phLdrMod Where to store the handle to the loaded module.
114 */
115RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
116
117/**
118 * Image architecuture specifier for RTLdrOpenEx.
119 */
120typedef enum RTLDRARCH
121{
122 RTLDRARCH_INVALID = 0,
123 /** Whatever. */
124 RTLDRARCH_WHATEVER,
125 /** The host architecture. */
126 RTLDRARCH_HOST,
127 /** 32-bit x86. */
128 RTLDRARCH_X86_32,
129 /** AMD64 (64-bit x86 if you like). */
130 RTLDRARCH_AMD64,
131 /** End of the valid values. */
132 RTLDRARCH_END,
133 /** Make sure the type is a full 32-bit. */
134 RTLDRARCH_32BIT_HACK = 0x7fffffff
135} RTLDRARCH;
136/** Pointer to a RTLDRARCH. */
137typedef RTLDRARCH *PRTLDRARCH;
138
139/**
140 * Open a binary image file, extended version.
141 *
142 * @returns iprt status code.
143 * @param pszFilename Image filename.
144 * @param fFlags Reserved, MBZ.
145 * @param enmArch CPU architecture specifier for the image to be loaded.
146 * @param phLdrMod Where to store the handle to the loader module.
147 */
148RTDECL(int) RTLdrOpen(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
149
150/**
151 * Opens a binary image file using kLdr.
152 *
153 * @returns iprt status code.
154 * @param pszFilename Image filename.
155 * @param phLdrMod Where to store the handle to the loaded module.
156 * @param fFlags Reserved, MBZ.
157 * @param enmArch CPU architecture specifier for the image to be loaded.
158 * @remark Primarily for testing the loader.
159 */
160RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
161
162/**
163 * What to expect and do with the bits passed to RTLdrOpenBits().
164 */
165typedef enum RTLDROPENBITS
166{
167 /** The usual invalid 0 entry. */
168 RTLDROPENBITS_INVALID = 0,
169 /** The bits are readonly and will never be changed. */
170 RTLDROPENBITS_READONLY,
171 /** The bits are going to be changed and the loader will have to duplicate them
172 * when opening the image. */
173 RTLDROPENBITS_WRITABLE,
174 /** The bits are both the source and destination for the loader operation.
175 * This means that the loader may have to duplicate them prior to changing them. */
176 RTLDROPENBITS_SRC_AND_DST,
177 /** The end of the valid enums. This entry marks the
178 * first invalid entry.. */
179 RTLDROPENBITS_END,
180 RTLDROPENBITS_32BIT_HACK = 0x7fffffff
181} RTLDROPENBITS;
182
183/**
184 * Open a binary image from in-memory bits.
185 *
186 * @returns iprt status code.
187 * @param pvBits The start of the raw-image.
188 * @param cbBits The size of the raw-image.
189 * @param enmBits What to expect from the pvBits.
190 * @param pszLogName What to call the raw-image when logging.
191 * For RTLdrLoad and RTLdrOpen the filename is used for this.
192 * @param phLdrMod Where to store the handle to the loader module.
193 */
194RTDECL(int) RTLdrOpenBits(const void *pvBits, size_t cbBits, RTLDROPENBITS enmBits, const char *pszLogName, PRTLDRMOD phLdrMod);
195
196/**
197 * Closes a loader module handle.
198 *
199 * The handle can be obtained using any of the RTLdrLoad(), RTLdrOpen()
200 * and RTLdrOpenBits() functions.
201 *
202 * @returns iprt status code.
203 * @param hLdrMod The loader module handle.
204 */
205RTDECL(int) RTLdrClose(RTLDRMOD hLdrMod);
206
207/**
208 * Gets the address of a named exported symbol.
209 *
210 * @returns iprt status code.
211 * @param hLdrMod The loader module handle.
212 * @param pszSymbol Symbol name.
213 * @param ppvValue Where to store the symbol value. Note that this is restricted to the
214 * pointer size used on the host!
215 */
216RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue);
217
218/**
219 * Gets the address of a named exported symbol.
220 *
221 * This function differs from the plain one in that it can deal with
222 * both GC and HC address sizes, and that it can calculate the symbol
223 * value relative to any given base address.
224 *
225 * @returns iprt status code.
226 * @param hLdrMod The loader module handle.
227 * @param pvBits Optional pointer to the loaded image.
228 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
229 * Not supported for RTLdrLoad() images.
230 * @param BaseAddress Image load address.
231 * Not supported for RTLdrLoad() images.
232 * @param pszSymbol Symbol name.
233 * @param pValue Where to store the symbol value.
234 */
235RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTUINTPTR BaseAddress, const char *pszSymbol, RTUINTPTR *pValue);
236
237/**
238 * Gets the size of the loaded image.
239 * This is only supported for modules which has been opened using RTLdrOpen() and RTLdrOpenBits().
240 *
241 * @returns image size (in bytes).
242 * @returns ~(size_t)0 on if not opened by RTLdrOpen().
243 * @param hLdrMod Handle to the loader module.
244 * @remark Not supported for RTLdrLoad() images.
245 */
246RTDECL(size_t) RTLdrSize(RTLDRMOD hLdrMod);
247
248/**
249 * Resolve an external symbol during RTLdrGetBits().
250 *
251 * @returns iprt status code.
252 * @param hLdrMod The loader module handle.
253 * @param pszModule Module name.
254 * @param pszSymbol Symbol name, NULL if uSymbol should be used.
255 * @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
256 * @param pValue Where to store the symbol value (address).
257 * @param pvUser User argument.
258 */
259typedef DECLCALLBACK(int) RTLDRIMPORT(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser);
260/** Pointer to a FNRTLDRIMPORT() callback function. */
261typedef RTLDRIMPORT *PFNRTLDRIMPORT;
262
263/**
264 * Loads the image into a buffer provided by the user and applies fixups
265 * for the given base address.
266 *
267 * @returns iprt status code.
268 * @param hLdrMod The load module handle.
269 * @param pvBits Where to put the bits.
270 * Must be as large as RTLdrSize() suggests.
271 * @param BaseAddress The base address.
272 * @param pfnGetImport Callback function for resolving imports one by one.
273 * @param pvUser User argument for the callback.
274 * @remark Not supported for RTLdrLoad() images.
275 */
276RTDECL(int) RTLdrGetBits(RTLDRMOD hLdrMod, void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);
277
278/**
279 * Relocates bits after getting them.
280 * Useful for code which moves around a bit.
281 *
282 * @returns iprt status code.
283 * @param hLdrMod The loader module handle.
284 * @param pvBits Where the image bits are.
285 * Must have been passed to RTLdrGetBits().
286 * @param NewBaseAddress The new base address.
287 * @param OldBaseAddress The old base address.
288 * @param pfnGetImport Callback function for resolving imports one by one.
289 * @param pvUser User argument for the callback.
290 * @remark Not supported for RTLdrLoad() images.
291 */
292RTDECL(int) RTLdrRelocate(RTLDRMOD hLdrMod, void *pvBits, RTUINTPTR NewBaseAddress, RTUINTPTR OldBaseAddress,
293 PFNRTLDRIMPORT pfnGetImport, void *pvUser);
294
295/**
296 * Enumeration callback function used by RTLdrEnumSymbols().
297 *
298 * @returns iprt status code. Failure will stop the enumeration.
299 * @param hLdrMod The loader module handle.
300 * @param pszSymbol Symbol name. NULL if ordinal only.
301 * @param uSymbol Symbol ordinal, ~0 if not used.
302 * @param Value Symbol value.
303 * @param pvUser The user argument specified to RTLdrEnumSymbols().
304 */
305typedef DECLCALLBACK(int) RTLDRENUMSYMS(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTUINTPTR Value, void *pvUser);
306/** Pointer to a RTLDRENUMSYMS() callback function. */
307typedef RTLDRENUMSYMS *PFNRTLDRENUMSYMS;
308
309/**
310 * Enumerates all symbols in a module.
311 *
312 * @returns iprt status code.
313 * @param hLdrMod The loader module handle.
314 * @param fFlags Flags indicating what to return and such.
315 * @param pvBits Optional pointer to the loaded image. (RTLDR_ENUM_SYMBOL_FLAGS_*)
316 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
317 * @param BaseAddress Image load address.
318 * @param pfnCallback Callback function.
319 * @param pvUser User argument for the callback.
320 * @remark Not supported for RTLdrLoad() images.
321 */
322RTDECL(int) RTLdrEnumSymbols(RTLDRMOD hLdrMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
323
324/** @name RTLdrEnumSymbols flags.
325 * @{ */
326/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
327#define RTLDR_ENUM_SYMBOL_FLAGS_ALL RT_BIT(1)
328/** @} */
329
330RT_C_DECLS_END
331
332/** @} */
333
334#endif
335
Note: See TracBrowser for help on using the repository browser.

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