1 | /* $Id: ldrNative.cpp 2981 2007-06-01 16:01:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime - Binary Image Loader, Native interface.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP RTLOGGROUP_LDR
|
---|
27 | #include <iprt/ldr.h>
|
---|
28 | #include <iprt/alloc.h>
|
---|
29 | #include <iprt/assert.h>
|
---|
30 | #include <iprt/log.h>
|
---|
31 | #include <iprt/string.h>
|
---|
32 | #include <iprt/err.h>
|
---|
33 | #include "internal/ldr.h"
|
---|
34 |
|
---|
35 |
|
---|
36 | /** @copydoc RTLDROPS::pfnEnumSymbols */
|
---|
37 | static DECLCALLBACK(int) rtldrNativeEnumSymbols(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress,
|
---|
38 | PFNRTLDRENUMSYMS pfnCallback, void *pvUser)
|
---|
39 | {
|
---|
40 | return VERR_NOT_SUPPORTED;
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | /** @copydoc RTLDROPS::pfnDone */
|
---|
45 | static DECLCALLBACK(int) rtldrNativeDone(PRTLDRMODINTERNAL pMod)
|
---|
46 | {
|
---|
47 | return VINF_SUCCESS;
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Operations for a native module.
|
---|
53 | */
|
---|
54 | static const RTLDROPS s_rtldrNativeOps =
|
---|
55 | {
|
---|
56 | "native",
|
---|
57 | rtldrNativeClose,
|
---|
58 | rtldrNativeGetSymbol,
|
---|
59 | rtldrNativeDone,
|
---|
60 | rtldrNativeEnumSymbols,
|
---|
61 | /* ext: */
|
---|
62 | NULL,
|
---|
63 | NULL,
|
---|
64 | NULL,
|
---|
65 | NULL,
|
---|
66 | 42
|
---|
67 | };
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Loads a dynamic load library (/shared object) image file using native
|
---|
73 | * OS facilities.
|
---|
74 | *
|
---|
75 | * The filename will be appended the default DLL/SO extension of
|
---|
76 | * the platform if it have been omitted. This means that it's not
|
---|
77 | * possible to load DLLs/SOs with no extension using this interface,
|
---|
78 | * but that's not a bad tradeoff.
|
---|
79 | *
|
---|
80 | * If no path is specified in the filename, the OS will usually search it's library
|
---|
81 | * path to find the image file.
|
---|
82 | *
|
---|
83 | * @returns iprt status code.
|
---|
84 | * @param pszFilename Image filename.
|
---|
85 | * @param phLdrMod Where to store the handle to the loaded module.
|
---|
86 | */
|
---|
87 | RTDECL(int) RTLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod)
|
---|
88 | {
|
---|
89 | LogFlow(("RTLdrLoad: pszFilename=%p:{%s} phLdrMod=%p\n", pszFilename, pszFilename, phLdrMod));
|
---|
90 |
|
---|
91 | /*
|
---|
92 | * validate input.
|
---|
93 | */
|
---|
94 | AssertMsgReturn(VALID_PTR(pszFilename), ("pszFilename=%p\n", pszFilename), VERR_INVALID_PARAMETER);
|
---|
95 | AssertMsgReturn(VALID_PTR(phLdrMod), ("phLdrMod=%p\n", phLdrMod), VERR_INVALID_PARAMETER);
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * Allocate and initialize module structure.
|
---|
99 | */
|
---|
100 | int rc = VERR_NO_MEMORY;
|
---|
101 | PRTLDRMODNATIVE pMod = (PRTLDRMODNATIVE)RTMemAlloc(sizeof(*pMod));
|
---|
102 | if (pMod)
|
---|
103 | {
|
---|
104 | pMod->Core.u32Magic = RTLDRMOD_MAGIC;
|
---|
105 | pMod->Core.eState = LDR_STATE_LOADED;
|
---|
106 | pMod->Core.pOps = &s_rtldrNativeOps;
|
---|
107 | pMod->hNative = ~(uintptr_t)0;
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * Attempt to open the module.
|
---|
111 | */
|
---|
112 | rc = rtldrNativeLoad(pszFilename, &pMod->hNative);
|
---|
113 | if (RT_SUCCESS(rc))
|
---|
114 | {
|
---|
115 | *phLdrMod = &pMod->Core;
|
---|
116 | LogFlow(("RTLdrLoad: returns %Rrc *phLdrMod=%RTldrm\n", rc, *phLdrMod));
|
---|
117 | return rc;
|
---|
118 | }
|
---|
119 | RTMemFree(pMod);
|
---|
120 | }
|
---|
121 | *phLdrMod = NIL_RTLDRMOD;
|
---|
122 | LogFlow(("RTLdrLoad: returns %Rrc\n", rc));
|
---|
123 | return rc;
|
---|
124 | }
|
---|
125 |
|
---|