VirtualBox

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

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

rebrand IPRT

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