VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp@ 43879

Last change on this file since 43879 was 39327, checked in by vboxsync, 13 years ago

scm whitespace cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 19.5 KB
Line 
1/* $Id: ldrEx.cpp 39327 2011-11-16 10:52:07Z vboxsync $ */
2/** @file
3 * IPRT - Binary Image Loader, Extended Features.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#define LOG_GROUP RTLOGGROUP_LDR
32#include <iprt/ldr.h>
33#include "internal/iprt.h"
34
35#include <iprt/alloc.h>
36#include <iprt/assert.h>
37#include <iprt/log.h>
38#include <iprt/string.h>
39#include <iprt/err.h>
40#include "internal/ldr.h"
41#include "internal/ldrMZ.h"
42
43
44/**
45 * Open part with reader.
46 *
47 * @returns iprt status code.
48 * @param pReader The loader reader instance which will provide the raw image bits.
49 * @param fFlags Reserved, MBZ.
50 * @param enmArch Architecture specifier.
51 * @param phMod Where to store the handle.
52 */
53int rtldrOpenWithReader(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phMod)
54{
55 /*
56 * Read and verify the file signature.
57 */
58 union
59 {
60 char ach[4];
61 uint16_t au16[2];
62 uint32_t u32;
63 } uSign;
64 int rc = pReader->pfnRead(pReader, &uSign, sizeof(uSign), 0);
65 if (RT_FAILURE(rc))
66 return rc;
67#ifndef LDR_WITH_KLDR
68 if ( uSign.au16[0] != IMAGE_DOS_SIGNATURE
69 && uSign.u32 != IMAGE_NT_SIGNATURE
70 && uSign.u32 != IMAGE_ELF_SIGNATURE
71 && uSign.au16[0] != IMAGE_LX_SIGNATURE)
72 {
73 Log(("rtldrOpenWithReader: %s: unknown magic %#x / '%.4s\n", pReader->pfnLogName(pReader), uSign.u32, &uSign.ach[0]));
74 return VERR_INVALID_EXE_SIGNATURE;
75 }
76#endif
77 uint32_t offHdr = 0;
78 if (uSign.au16[0] == IMAGE_DOS_SIGNATURE)
79 {
80 rc = pReader->pfnRead(pReader, &offHdr, sizeof(offHdr), RT_OFFSETOF(IMAGE_DOS_HEADER, e_lfanew));
81 if (RT_FAILURE(rc))
82 return rc;
83
84 if (offHdr <= sizeof(IMAGE_DOS_HEADER))
85 {
86 Log(("rtldrOpenWithReader: %s: no new header / invalid offset %#RX32\n", pReader->pfnLogName(pReader), offHdr));
87 return VERR_INVALID_EXE_SIGNATURE;
88 }
89 rc = pReader->pfnRead(pReader, &uSign, sizeof(uSign), offHdr);
90 if (RT_FAILURE(rc))
91 return rc;
92 if ( uSign.u32 != IMAGE_NT_SIGNATURE
93 && uSign.au16[0] != IMAGE_LX_SIGNATURE
94 && uSign.au16[0] != IMAGE_LE_SIGNATURE
95 && uSign.au16[0] != IMAGE_NE_SIGNATURE)
96 {
97 Log(("rtldrOpenWithReader: %s: unknown new magic %#x / '%.4s\n", pReader->pfnLogName(pReader), uSign.u32, &uSign.ach[0]));
98 return VERR_INVALID_EXE_SIGNATURE;
99 }
100 }
101
102 /*
103 * Create image interpreter instance depending on the signature.
104 */
105 if (uSign.u32 == IMAGE_NT_SIGNATURE)
106#ifdef LDR_WITH_PE
107 rc = rtldrPEOpen(pReader, fFlags, enmArch, offHdr, phMod);
108#else
109 rc = VERR_PE_EXE_NOT_SUPPORTED;
110#endif
111 else if (uSign.u32 == IMAGE_ELF_SIGNATURE)
112#if defined(LDR_WITH_ELF)
113 rc = rtldrELFOpen(pReader, fFlags, enmArch, phMod);
114#else
115 rc = VERR_ELF_EXE_NOT_SUPPORTED;
116#endif
117 else if (uSign.au16[0] == IMAGE_LX_SIGNATURE)
118#ifdef LDR_WITH_LX
119 rc = rtldrLXOpen(pReader, fFlags, enmArch, offHdr, phMod);
120#else
121 rc = VERR_LX_EXE_NOT_SUPPORTED;
122#endif
123 else if (uSign.au16[0] == IMAGE_LE_SIGNATURE)
124#ifdef LDR_WITH_LE
125 rc = rtldrLEOpen(pReader, fFlags, enmArch, phMod);
126#else
127 rc = VERR_LE_EXE_NOT_SUPPORTED;
128#endif
129 else if (uSign.au16[0] == IMAGE_NE_SIGNATURE)
130#ifdef LDR_WITH_NE
131 rc = rtldrNEOpen(pReader, fFlags, enmArch, phMod);
132#else
133 rc = VERR_NE_EXE_NOT_SUPPORTED;
134#endif
135 else if (uSign.au16[0] == IMAGE_DOS_SIGNATURE)
136#ifdef LDR_WITH_MZ
137 rc = rtldrMZOpen(pReader, fFlags, enmArch, phMod);
138#else
139 rc = VERR_MZ_EXE_NOT_SUPPORTED;
140#endif
141 else if (/* uSign.u32 == IMAGE_AOUT_A_SIGNATURE
142 || uSign.u32 == IMAGE_AOUT_Z_SIGNATURE*/ /** @todo find the aout magics in emx or binutils. */
143 0)
144#ifdef LDR_WITH_AOUT
145 rc = rtldrAOUTOpen(pReader, fFlags, enmArch, phMod);
146#else
147 rc = VERR_AOUT_EXE_NOT_SUPPORTED;
148#endif
149 else
150 {
151#ifndef LDR_WITH_KLDR
152 Log(("rtldrOpenWithReader: %s: the format isn't implemented %#x / '%.4s\n", pReader->pfnLogName(pReader), uSign.u32, &uSign.ach[0]));
153#endif
154 rc = VERR_INVALID_EXE_SIGNATURE;
155 }
156
157#ifdef LDR_WITH_KLDR
158 /* Try kLdr if it's a format we don't recognize. */
159 if (rc <= VERR_INVALID_EXE_SIGNATURE && rc > VERR_BAD_EXE_FORMAT)
160 rc = rtldrkLdrOpen(pReader, fFlags, enmArch, phMod);
161#endif
162
163 LogFlow(("rtldrOpenWithReader: %s: returns %Rrc *phMod=%p\n", pReader->pfnLogName(pReader), rc, *phMod));
164 return rc;
165}
166
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 LogFlow(("RTLdrSize: hLdrMod=%RTldrm\n", hLdrMod));
180
181 /*
182 * Validate input.
183 */
184 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), ~(size_t)0);
185 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
186 AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), ~(size_t)0);
187
188 /*
189 * Do it.
190 */
191 size_t cb = pMod->pOps->pfnGetImageSize(pMod);
192 LogFlow(("RTLdrSize: returns %zu\n", cb));
193 return cb;
194}
195RT_EXPORT_SYMBOL(RTLdrSize);
196
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, RTLDRADDR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser)
212{
213 LogFlow(("RTLdrGetBits: hLdrMod=%RTldrm pvBits=%p BaseAddress=%RTptr pfnGetImport=%p pvUser=%p\n",
214 hLdrMod, pvBits, BaseAddress, pfnGetImport, pvUser));
215
216 /*
217 * Validate input.
218 */
219 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
220 AssertMsgReturn(VALID_PTR(pvBits), ("pvBits=%p\n", pvBits), VERR_INVALID_PARAMETER);
221 AssertMsgReturn(VALID_PTR(pfnGetImport), ("pfnGetImport=%p\n", pfnGetImport), VERR_INVALID_PARAMETER);
222 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
223 AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
224
225 /*
226 * Do it.
227 */
228 int rc = pMod->pOps->pfnGetBits(pMod, pvBits, BaseAddress, pfnGetImport, pvUser);
229 LogFlow(("RTLdrGetBits: returns %Rrc\n",rc));
230 return rc;
231}
232RT_EXPORT_SYMBOL(RTLdrGetBits);
233
234
235/**
236 * Relocates bits after getting them.
237 * Useful for code which moves around a bit.
238 *
239 * @returns iprt status code.
240 * @param hLdrMod The loader module handle.
241 * @param pvBits Where the image bits are.
242 * Must have been passed to RTLdrGetBits().
243 * @param NewBaseAddress The new base address.
244 * @param OldBaseAddress The old base address.
245 * @param pfnGetImport Callback function for resolving imports one by one.
246 * @param pvUser User argument for the callback.
247 * @remark Not supported for RTLdrLoad() images.
248 */
249RTDECL(int) RTLdrRelocate(RTLDRMOD hLdrMod, void *pvBits, RTLDRADDR NewBaseAddress, RTLDRADDR OldBaseAddress,
250 PFNRTLDRIMPORT pfnGetImport, void *pvUser)
251{
252 LogFlow(("RTLdrRelocate: hLdrMod=%RTldrm pvBits=%p NewBaseAddress=%RTptr OldBaseAddress=%RTptr pfnGetImport=%p pvUser=%p\n",
253 hLdrMod, pvBits, NewBaseAddress, OldBaseAddress, pfnGetImport, pvUser));
254
255 /*
256 * Validate input.
257 */
258 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
259 AssertMsgReturn(VALID_PTR(pvBits), ("pvBits=%p\n", pvBits), VERR_INVALID_PARAMETER);
260 AssertMsgReturn(VALID_PTR(pfnGetImport), ("pfnGetImport=%p\n", pfnGetImport), VERR_INVALID_PARAMETER);
261 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
262 AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
263
264 /*
265 * Do it.
266 */
267 int rc = pMod->pOps->pfnRelocate(pMod, pvBits, NewBaseAddress, OldBaseAddress, pfnGetImport, pvUser);
268 LogFlow(("RTLdrRelocate: returns %Rrc\n", rc));
269 return rc;
270}
271RT_EXPORT_SYMBOL(RTLdrRelocate);
272
273
274/**
275 * Gets the address of a named exported symbol.
276 *
277 * This function differs from the plain one in that it can deal with
278 * both GC and HC address sizes, and that it can calculate the symbol
279 * value relative to any given base address.
280 *
281 * @returns iprt status code.
282 * @param hLdrMod The loader module handle.
283 * @param pvBits Optional pointer to the loaded image.
284 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
285 * Not supported for RTLdrLoad() images and must be NULL.
286 * @param BaseAddress Image load address.
287 * Not supported for RTLdrLoad() images and must be 0.
288 * @param pszSymbol Symbol name.
289 * @param pValue Where to store the symbol value.
290 */
291RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTLDRADDR BaseAddress, const char *pszSymbol,
292 PRTLDRADDR pValue)
293{
294 LogFlow(("RTLdrGetSymbolEx: hLdrMod=%RTldrm pvBits=%p BaseAddress=%RTptr pszSymbol=%p:{%s} pValue\n",
295 hLdrMod, pvBits, BaseAddress, pszSymbol, pszSymbol, pValue));
296
297 /*
298 * Validate input.
299 */
300 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
301 AssertMsgReturn(!pvBits || VALID_PTR(pvBits), ("pvBits=%p\n", pvBits), VERR_INVALID_PARAMETER);
302 AssertMsgReturn(pszSymbol, ("pszSymbol=%p\n", pszSymbol), VERR_INVALID_PARAMETER);
303 AssertMsgReturn(VALID_PTR(pValue), ("pValue=%p\n", pvBits), VERR_INVALID_PARAMETER);
304 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
305 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
306
307 /*
308 * Do it.
309 */
310 int rc;
311 if (pMod->pOps->pfnGetSymbolEx)
312 rc = pMod->pOps->pfnGetSymbolEx(pMod, pvBits, BaseAddress, pszSymbol, pValue);
313 else if (!BaseAddress && !pvBits)
314 {
315 void *pvValue;
316 rc = pMod->pOps->pfnGetSymbol(pMod, pszSymbol, &pvValue);
317 if (RT_SUCCESS(rc))
318 *pValue = (uintptr_t)pvValue;
319 }
320 else
321 AssertMsgFailedReturn(("BaseAddress=%RTptr pvBits=%p\n", BaseAddress, pvBits), VERR_INVALID_FUNCTION);
322 LogFlow(("RTLdrGetSymbolEx: returns %Rrc *pValue=%p\n", rc, *pValue));
323 return rc;
324}
325RT_EXPORT_SYMBOL(RTLdrGetSymbolEx);
326
327
328/**
329 * Enumerates all symbols in a module.
330 *
331 * @returns iprt status code.
332 * @param hLdrMod The loader module handle.
333 * @param fFlags Flags indicating what to return and such.
334 * @param pvBits Optional pointer to the loaded image.
335 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
336 * @param BaseAddress Image load address.
337 * @param pfnCallback Callback function.
338 * @param pvUser User argument for the callback.
339 * @remark Not supported for RTLdrLoad() images.
340 */
341RTDECL(int) RTLdrEnumSymbols(RTLDRMOD hLdrMod, unsigned fFlags, const void *pvBits, RTLDRADDR BaseAddress,
342 PFNRTLDRENUMSYMS pfnCallback, void *pvUser)
343{
344 LogFlow(("RTLdrEnumSymbols: hLdrMod=%RTldrm fFlags=%#x pvBits=%p BaseAddress=%RTptr pfnCallback=%p pvUser=%p\n",
345 hLdrMod, fFlags, pvBits, BaseAddress, pfnCallback, pvUser));
346
347 /*
348 * Validate input.
349 */
350 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
351 AssertMsgReturn(!pvBits || VALID_PTR(pvBits), ("pvBits=%p\n", pvBits), VERR_INVALID_PARAMETER);
352 AssertMsgReturn(VALID_PTR(pfnCallback), ("pfnCallback=%p\n", pfnCallback), VERR_INVALID_PARAMETER);
353 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
354 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
355
356 /*
357 * Do it.
358 */
359 int rc = pMod->pOps->pfnEnumSymbols(pMod, fFlags, pvBits, BaseAddress, pfnCallback, pvUser);
360 LogFlow(("RTLdrEnumSymbols: returns %Rrc\n", rc));
361 return rc;
362}
363RT_EXPORT_SYMBOL(RTLdrEnumSymbols);
364
365
366RTDECL(int) RTLdrEnumDbgInfo(RTLDRMOD hLdrMod, const void *pvBits, PFNRTLDRENUMDBG pfnCallback, void *pvUser)
367{
368 LogFlow(("RTLdrEnumDbgInfo: hLdrMod=%RTldrm pvBits=%p pfnCallback=%p pvUser=%p\n",
369 hLdrMod, pvBits, pfnCallback, pvUser));
370
371 /*
372 * Validate input.
373 */
374 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
375 AssertMsgReturn(!pvBits || RT_VALID_PTR(pvBits), ("pvBits=%p\n", pvBits), VERR_INVALID_PARAMETER);
376 AssertMsgReturn(RT_VALID_PTR(pfnCallback), ("pfnCallback=%p\n", pfnCallback), VERR_INVALID_PARAMETER);
377 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
378 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
379
380 /*
381 * Do it.
382 */
383 int rc;
384 if (pMod->pOps->pfnEnumDbgInfo)
385 rc = pMod->pOps->pfnEnumDbgInfo(pMod, pvBits, pfnCallback, pvUser);
386 else
387 rc = VERR_NOT_SUPPORTED;
388
389 LogFlow(("RTLdrEnumDbgInfo: returns %Rrc\n", rc));
390 return rc;
391}
392RT_EXPORT_SYMBOL(RTLdrEnumDbgInfo);
393
394
395RTDECL(int) RTLdrEnumSegments(RTLDRMOD hLdrMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser)
396{
397 LogFlow(("RTLdrEnumSegments: hLdrMod=%RTldrm pfnCallback=%p pvUser=%p\n",
398 hLdrMod, pfnCallback, pvUser));
399
400 /*
401 * Validate input.
402 */
403 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
404 AssertMsgReturn(RT_VALID_PTR(pfnCallback), ("pfnCallback=%p\n", pfnCallback), VERR_INVALID_PARAMETER);
405 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
406 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
407
408 /*
409 * Do it.
410 */
411 int rc;
412 if (pMod->pOps->pfnEnumSegments)
413 rc = pMod->pOps->pfnEnumSegments(pMod, pfnCallback, pvUser);
414 else
415 rc = VERR_NOT_SUPPORTED;
416
417 LogFlow(("RTLdrEnumSegments: returns %Rrc\n", rc));
418 return rc;
419
420}
421RT_EXPORT_SYMBOL(RTLdrEnumSegments);
422
423
424RTDECL(int) RTLdrLinkAddressToSegOffset(RTLDRMOD hLdrMod, RTLDRADDR LinkAddress, uint32_t *piSeg, PRTLDRADDR poffSeg)
425{
426 LogFlow(("RTLdrLinkAddressToSegOffset: hLdrMod=%RTldrm LinkAddress=%RTptr piSeg=%p poffSeg=%p\n",
427 hLdrMod, LinkAddress, piSeg, poffSeg));
428
429 /*
430 * Validate input.
431 */
432 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
433 AssertPtrReturn(piSeg, VERR_INVALID_POINTER);
434 AssertPtrReturn(poffSeg, VERR_INVALID_POINTER);
435
436 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
437 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
438
439 *piSeg = UINT32_MAX;
440 *poffSeg = ~(RTLDRADDR)0;
441
442 /*
443 * Do it.
444 */
445 int rc;
446 if (pMod->pOps->pfnLinkAddressToSegOffset)
447 rc = pMod->pOps->pfnLinkAddressToSegOffset(pMod, LinkAddress, piSeg, poffSeg);
448 else
449 rc = VERR_NOT_SUPPORTED;
450
451 LogFlow(("RTLdrLinkAddressToSegOffset: returns %Rrc %#x:%RTptr\n", rc, *piSeg, *poffSeg));
452 return rc;
453}
454RT_EXPORT_SYMBOL(RTLdrLinkAddressToSegOffset);
455
456
457RTDECL(int) RTLdrLinkAddressToRva(RTLDRMOD hLdrMod, RTLDRADDR LinkAddress, PRTLDRADDR pRva)
458{
459 LogFlow(("RTLdrLinkAddressToRva: hLdrMod=%RTldrm LinkAddress=%RTptr pRva=%p\n",
460 hLdrMod, LinkAddress, pRva));
461
462 /*
463 * Validate input.
464 */
465 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
466 AssertPtrReturn(pRva, VERR_INVALID_POINTER);
467
468 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
469 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
470
471 *pRva = ~(RTLDRADDR)0;
472
473 /*
474 * Do it.
475 */
476 int rc;
477 if (pMod->pOps->pfnLinkAddressToRva)
478 rc = pMod->pOps->pfnLinkAddressToRva(pMod, LinkAddress, pRva);
479 else
480 rc = VERR_NOT_SUPPORTED;
481
482 LogFlow(("RTLdrLinkAddressToRva: returns %Rrc %RTptr\n", rc, *pRva));
483 return rc;
484}
485RT_EXPORT_SYMBOL(RTLdrLinkAddressToRva);
486
487
488RTDECL(int) RTLdrSegOffsetToRva(RTLDRMOD hLdrMod, uint32_t iSeg, RTLDRADDR offSeg, PRTLDRADDR pRva)
489{
490 LogFlow(("RTLdrSegOffsetToRva: hLdrMod=%RTldrm LinkAddress=%RTptr iSeg=%#x offSeg=%RTptr pRva=%p\n",
491 hLdrMod, iSeg, offSeg, pRva));
492
493 /*
494 * Validate input.
495 */
496 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
497 AssertPtrReturn(pRva, VERR_INVALID_POINTER);
498
499 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
500 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
501
502 *pRva = ~(RTLDRADDR)0;
503
504 /*
505 * Do it.
506 */
507 int rc;
508 if (pMod->pOps->pfnSegOffsetToRva)
509 rc = pMod->pOps->pfnSegOffsetToRva(pMod, iSeg, offSeg, pRva);
510 else
511 rc = VERR_NOT_SUPPORTED;
512
513 LogFlow(("RTLdrSegOffsetToRva: returns %Rrc %RTptr\n", rc, *pRva));
514 return rc;
515}
516RT_EXPORT_SYMBOL(RTLdrSegOffsetToRva);
517
518RTDECL(int) RTLdrRvaToSegOffset(RTLDRMOD hLdrMod, RTLDRADDR Rva, uint32_t *piSeg, PRTLDRADDR poffSeg)
519{
520 LogFlow(("RTLdrRvaToSegOffset: hLdrMod=%RTldrm Rva=%RTptr piSeg=%p poffSeg=%p\n",
521 hLdrMod, Rva, piSeg, poffSeg));
522
523 /*
524 * Validate input.
525 */
526 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
527 AssertPtrReturn(piSeg, VERR_INVALID_POINTER);
528 AssertPtrReturn(poffSeg, VERR_INVALID_POINTER);
529
530 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
531 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
532
533 *piSeg = UINT32_MAX;
534 *poffSeg = ~(RTLDRADDR)0;
535
536 /*
537 * Do it.
538 */
539 int rc;
540 if (pMod->pOps->pfnRvaToSegOffset)
541 rc = pMod->pOps->pfnRvaToSegOffset(pMod, Rva, piSeg, poffSeg);
542 else
543 rc = VERR_NOT_SUPPORTED;
544
545 LogFlow(("RTLdrRvaToSegOffset: returns %Rrc %#x:%RTptr\n", rc, *piSeg, *poffSeg));
546 return rc;
547}
548RT_EXPORT_SYMBOL(RTLdrRvaToSegOffset);
549
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