VirtualBox

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

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

iprt: RTLdrIsLoadable for checking if an dynamically library could be loaded.

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