VirtualBox

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

Last change on this file since 16933 was 16933, checked in by vboxsync, 16 years ago

IPRT/PDM,SUPLIb,REM: Extended RTLdrOpen with an architecture argument for use with FAT R0.r0 images later some day. Also added fFlags argument that's currently MBZ case.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 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 residing in the
72 * RTPathAppPrivateArch() directory.
73 *
74 * Suffix is not required.
75 *
76 * @returns iprt status code.
77 * @param pszFilename Image filename. No path.
78 * @param phLdrMod Where to store the handle to the loaded module.
79 */
80RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
81
82/**
83 * Image architecuture specifier for RTLdrOpenEx.
84 */
85typedef enum RTLDRARCH
86{
87 RTLDRARCH_INVALID = 0,
88 /** Whatever. */
89 RTLDRARCH_WHATEVER,
90 /** The host architecture. */
91 RTLDRARCH_HOST,
92 /** 32-bit x86. */
93 RTLDRARCH_X86_32,
94 /** AMD64 (64-bit x86 if you like). */
95 RTLDRARCH_AMD64,
96 /** End of the valid values. */
97 RTLDRARCH_END,
98 /** Make sure the type is a full 32-bit. */
99 RTLDRARCH_32BIT_HACK = 0x7fffffff
100} RTLDRARCH;
101/** Pointer to a RTLDRARCH. */
102typedef RTLDRARCH *PRTLDRARCH;
103
104/**
105 * Open a binary image file, extended version.
106 *
107 * @returns iprt status code.
108 * @param pszFilename Image filename.
109 * @param fFlags Reserved, MBZ.
110 * @param enmArch CPU architecture specifier for the image to be loaded.
111 * @param phLdrMod Where to store the handle to the loader module.
112 */
113RTDECL(int) RTLdrOpen(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
114
115/**
116 * Opens a binary image file using kLdr.
117 *
118 * @returns iprt status code.
119 * @param pszFilename Image filename.
120 * @param phLdrMod Where to store the handle to the loaded module.
121 * @param fFlags Reserved, MBZ.
122 * @param enmArch CPU architecture specifier for the image to be loaded.
123 * @remark Primarily for testing the loader.
124 */
125RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
126
127/**
128 * What to expect and do with the bits passed to RTLdrOpenBits().
129 */
130typedef enum RTLDROPENBITS
131{
132 /** The usual invalid 0 entry. */
133 RTLDROPENBITS_INVALID = 0,
134 /** The bits are readonly and will never be changed. */
135 RTLDROPENBITS_READONLY,
136 /** The bits are going to be changed and the loader will have to duplicate them
137 * when opening the image. */
138 RTLDROPENBITS_WRITABLE,
139 /** The bits are both the source and destination for the loader operation.
140 * This means that the loader may have to duplicate them prior to changing them. */
141 RTLDROPENBITS_SRC_AND_DST,
142 /** The end of the valid enums. This entry marks the
143 * first invalid entry.. */
144 RTLDROPENBITS_END,
145 RTLDROPENBITS_32BIT_HACK = 0x7fffffff
146} RTLDROPENBITS;
147
148/**
149 * Open a binary image from in-memory bits.
150 *
151 * @returns iprt status code.
152 * @param pvBits The start of the raw-image.
153 * @param cbBits The size of the raw-image.
154 * @param enmBits What to expect from the pvBits.
155 * @param pszLogName What to call the raw-image when logging.
156 * For RTLdrLoad and RTLdrOpen the filename is used for this.
157 * @param phLdrMod Where to store the handle to the loader module.
158 */
159RTDECL(int) RTLdrOpenBits(const void *pvBits, size_t cbBits, RTLDROPENBITS enmBits, const char *pszLogName, PRTLDRMOD phLdrMod);
160
161/**
162 * Closes a loader module handle.
163 *
164 * The handle can be obtained using any of the RTLdrLoad(), RTLdrOpen()
165 * and RTLdrOpenBits() functions.
166 *
167 * @returns iprt status code.
168 * @param hLdrMod The loader module handle.
169 */
170RTDECL(int) RTLdrClose(RTLDRMOD hLdrMod);
171
172/**
173 * Gets the address of a named exported symbol.
174 *
175 * @returns iprt status code.
176 * @param hLdrMod The loader module handle.
177 * @param pszSymbol Symbol name.
178 * @param ppvValue Where to store the symbol value. Note that this is restricted to the
179 * pointer size used on the host!
180 */
181RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue);
182
183/**
184 * Gets the address of a named exported symbol.
185 *
186 * This function differs from the plain one in that it can deal with
187 * both GC and HC address sizes, and that it can calculate the symbol
188 * value relative to any given base address.
189 *
190 * @returns iprt status code.
191 * @param hLdrMod The loader module handle.
192 * @param pvBits Optional pointer to the loaded image.
193 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
194 * Not supported for RTLdrLoad() images.
195 * @param BaseAddress Image load address.
196 * Not supported for RTLdrLoad() images.
197 * @param pszSymbol Symbol name.
198 * @param pValue Where to store the symbol value.
199 */
200RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTUINTPTR BaseAddress, const char *pszSymbol, RTUINTPTR *pValue);
201
202/**
203 * Gets the size of the loaded image.
204 * This is only supported for modules which has been opened using RTLdrOpen() and RTLdrOpenBits().
205 *
206 * @returns image size (in bytes).
207 * @returns ~(size_t)0 on if not opened by RTLdrOpen().
208 * @param hLdrMod Handle to the loader module.
209 * @remark Not supported for RTLdrLoad() images.
210 */
211RTDECL(size_t) RTLdrSize(RTLDRMOD hLdrMod);
212
213/**
214 * Resolve an external symbol during RTLdrGetBits().
215 *
216 * @returns iprt status code.
217 * @param hLdrMod The loader module handle.
218 * @param pszModule Module name.
219 * @param pszSymbol Symbol name, NULL if uSymbol should be used.
220 * @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
221 * @param pValue Where to store the symbol value (address).
222 * @param pvUser User argument.
223 */
224typedef DECLCALLBACK(int) RTLDRIMPORT(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser);
225/** Pointer to a FNRTLDRIMPORT() callback function. */
226typedef RTLDRIMPORT *PFNRTLDRIMPORT;
227
228/**
229 * Loads the image into a buffer provided by the user and applies fixups
230 * for the given base address.
231 *
232 * @returns iprt status code.
233 * @param hLdrMod The load module handle.
234 * @param pvBits Where to put the bits.
235 * Must be as large as RTLdrSize() suggests.
236 * @param BaseAddress The base address.
237 * @param pfnGetImport Callback function for resolving imports one by one.
238 * @param pvUser User argument for the callback.
239 * @remark Not supported for RTLdrLoad() images.
240 */
241RTDECL(int) RTLdrGetBits(RTLDRMOD hLdrMod, void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);
242
243/**
244 * Relocates bits after getting them.
245 * Useful for code which moves around a bit.
246 *
247 * @returns iprt status code.
248 * @param hLdrMod The loader module handle.
249 * @param pvBits Where the image bits are.
250 * Must've been passed to RTLdrGetBits().
251 * @param NewBaseAddress The new base address.
252 * @param OldBaseAddress The old base address.
253 * @param pfnGetImport Callback function for resolving imports one by one.
254 * @param pvUser User argument for the callback.
255 * @remark Not supported for RTLdrLoad() images.
256 */
257RTDECL(int) RTLdrRelocate(RTLDRMOD hLdrMod, void *pvBits, RTUINTPTR NewBaseAddress, RTUINTPTR OldBaseAddress,
258 PFNRTLDRIMPORT pfnGetImport, void *pvUser);
259
260/**
261 * Enumeration callback function used by RTLdrEnumSymbols().
262 *
263 * @returns iprt status code. Failure will stop the enumeration.
264 * @param hLdrMod The loader module handle.
265 * @param pszSymbol Symbol name. NULL if ordinal only.
266 * @param uSymbol Symbol ordinal, ~0 if not used.
267 * @param Value Symbol value.
268 * @param pvUser The user argument specified to RTLdrEnumSymbols().
269 */
270typedef DECLCALLBACK(int) RTLDRENUMSYMS(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTUINTPTR Value, void *pvUser);
271/** Pointer to a RTLDRENUMSYMS() callback function. */
272typedef RTLDRENUMSYMS *PFNRTLDRENUMSYMS;
273
274/**
275 * Enumerates all symbols in a module.
276 *
277 * @returns iprt status code.
278 * @param hLdrMod The loader module handle.
279 * @param fFlags Flags indicating what to return and such.
280 * @param pvBits Optional pointer to the loaded image. (RTLDR_ENUM_SYMBOL_FLAGS_*)
281 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
282 * @param BaseAddress Image load address.
283 * @param pfnCallback Callback function.
284 * @param pvUser User argument for the callback.
285 * @remark Not supported for RTLdrLoad() images.
286 */
287RTDECL(int) RTLdrEnumSymbols(RTLDRMOD hLdrMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
288
289/** @name RTLdrEnumSymbols flags.
290 * @{ */
291/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
292#define RTLDR_ENUM_SYMBOL_FLAGS_ALL RT_BIT(1)
293/** @} */
294
295__END_DECLS
296
297/** @} */
298
299#endif
300
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