VirtualBox

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

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

Runtime function to load a shared library from the application directories.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use