1 | /* $Id: dbgmodldr.cpp 38531 2011-08-25 14:30:23Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Debug Module Image Interpretation by RTLdr.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011 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 | #include <iprt/dbg.h>
|
---|
32 | #include "internal/iprt.h"
|
---|
33 |
|
---|
34 | #include <iprt/assert.h>
|
---|
35 | #include <iprt/err.h>
|
---|
36 | #include <iprt/ldr.h>
|
---|
37 | #include <iprt/mem.h>
|
---|
38 | #include <iprt/param.h>
|
---|
39 | #include <iprt/path.h>
|
---|
40 | #include <iprt/string.h>
|
---|
41 | #include "internal/dbgmod.h"
|
---|
42 | #include "internal/magics.h"
|
---|
43 |
|
---|
44 |
|
---|
45 | /*******************************************************************************
|
---|
46 | * Structures and Typedefs *
|
---|
47 | *******************************************************************************/
|
---|
48 | /**
|
---|
49 | * The instance data of the RTLdr based image reader.
|
---|
50 | */
|
---|
51 | typedef struct RTDBGMODLDR
|
---|
52 | {
|
---|
53 | /** The loader handle. */
|
---|
54 | RTLDRMOD hLdrMod;
|
---|
55 | } RTDBGMODLDR;
|
---|
56 | /** Pointer to instance data NM map reader. */
|
---|
57 | typedef RTDBGMODLDR *PRTDBGMODLDR;
|
---|
58 |
|
---|
59 |
|
---|
60 | /** @interface_method_impl{RTDBGMODVTIMG,pfnEnumDbgInfo} */
|
---|
61 | static DECLCALLBACK(int) rtDbgModLdr_EnumDbgInfo(PRTDBGMODINT pMod, PFNRTLDRENUMDBG pfnCallback, void *pvUser)
|
---|
62 | {
|
---|
63 | PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
|
---|
64 | return RTLdrEnumDbgInfo(pThis->hLdrMod, NULL, pfnCallback, pvUser);
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | /** @interface_method_impl{RTDBGMODVTIMG,pfnClose} */
|
---|
69 | static DECLCALLBACK(int) rtDbgModLdr_Close(PRTDBGMODINT pMod)
|
---|
70 | {
|
---|
71 | PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
|
---|
72 | AssertPtr(pThis);
|
---|
73 |
|
---|
74 | int rc = RTLdrClose(pThis->hLdrMod); AssertRC(rc);
|
---|
75 | pThis->hLdrMod = NIL_RTLDRMOD;
|
---|
76 | RTMemFree(pThis);
|
---|
77 |
|
---|
78 | return VINF_SUCCESS;
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | /** @interface_method_impl{RTDBGMODVTIMG,pfnTryOpen} */
|
---|
83 | static DECLCALLBACK(int) rtDbgModLdr_TryOpen(PRTDBGMODINT pMod)
|
---|
84 | {
|
---|
85 | RTLDRMOD hLdrMod;
|
---|
86 | int rc = RTLdrOpen(pMod->pszImgFile, 0 /*fFlags*/, RTLDRARCH_WHATEVER, &hLdrMod);
|
---|
87 | if (RT_FAILURE(rc))
|
---|
88 | return rc;
|
---|
89 |
|
---|
90 | PRTDBGMODLDR pThis = (PRTDBGMODLDR)RTMemAllocZ(sizeof(RTDBGMODLDR));
|
---|
91 | if (!pThis)
|
---|
92 | {
|
---|
93 | RTLdrClose(hLdrMod);
|
---|
94 | return VERR_NO_MEMORY;
|
---|
95 | }
|
---|
96 |
|
---|
97 | pThis->hLdrMod = hLdrMod;
|
---|
98 | pMod->pvImgPriv = pThis;
|
---|
99 | return VINF_SUCCESS;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | /** Virtual function table for the RTLdr based image reader. */
|
---|
104 | DECL_HIDDEN_CONST(RTDBGMODVTIMG) const g_rtDbgModVtImgLdr =
|
---|
105 | {
|
---|
106 | /*.u32Magic = */ RTDBGMODVTIMG_MAGIC,
|
---|
107 | /*.fReserved = */ 0,
|
---|
108 | /*.pszName = */ "RTLdr",
|
---|
109 | /*.pfnTryOpen = */ rtDbgModLdr_TryOpen,
|
---|
110 | /*.pfnClose = */ rtDbgModLdr_Close,
|
---|
111 | /*.pfnEnumDbgInfo = */ rtDbgModLdr_EnumDbgInfo,
|
---|
112 | /*.pfnMapPart = */ NULL /** @todo*/,
|
---|
113 | /*.pfnUnmapPart = */ NULL /** @todo*/,
|
---|
114 |
|
---|
115 | /*.u32EndMagic = */ RTDBGMODVTIMG_MAGIC
|
---|
116 | };
|
---|
117 |
|
---|
118 |
|
---|