VirtualBox

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

Last change on this file since 46161 was 46161, checked in by vboxsync, 12 years ago

First part of loading .dSYM bundles.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/* $Id: ldr.cpp 46161 2013-05-19 13:31:13Z vboxsync $ */
2/** @file
3 * IPRT - Binary Image Loader.
4 */
5
6/*
7 * Copyright (C) 2006-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#define LOG_GROUP RTLOGGROUP_LDR
32#include <iprt/ldr.h>
33#include "internal/iprt.h"
34
35#include <iprt/alloc.h>
36#include <iprt/string.h>
37#include <iprt/assert.h>
38#include <iprt/err.h>
39#include <iprt/log.h>
40#include "internal/ldr.h"
41
42
43RTDECL(bool) RTLdrIsLoadable(const char *pszFilename)
44{
45 /*
46 * Try to load the library.
47 */
48 RTLDRMOD hLib;
49 int rc = RTLdrLoad(pszFilename, &hLib);
50 if (RT_SUCCESS(rc))
51 {
52 RTLdrClose(hLib);
53 return true;
54 }
55 return false;
56}
57RT_EXPORT_SYMBOL(RTLdrIsLoadable);
58
59
60RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue)
61{
62 LogFlow(("RTLdrGetSymbol: hLdrMod=%RTldrm pszSymbol=%p:{%s} ppvValue=%p\n",
63 hLdrMod, pszSymbol, pszSymbol, ppvValue));
64 /*
65 * Validate input.
66 */
67 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
68 AssertMsgReturn(pszSymbol, ("pszSymbol=%p\n", pszSymbol), VERR_INVALID_PARAMETER);
69 AssertMsgReturn(VALID_PTR(ppvValue), ("ppvValue=%p\n", ppvValue), VERR_INVALID_PARAMETER);
70 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
71 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
72
73 /*
74 * Do it.
75 */
76 int rc;
77 if (pMod->pOps->pfnGetSymbol)
78 rc = pMod->pOps->pfnGetSymbol(pMod, pszSymbol, ppvValue);
79 else
80 {
81 RTUINTPTR Value = 0;
82 rc = pMod->pOps->pfnGetSymbolEx(pMod, NULL, 0, pszSymbol, &Value);
83 if (RT_SUCCESS(rc))
84 {
85 *ppvValue = (void *)(uintptr_t)Value;
86 if ((uintptr_t)*ppvValue != Value)
87 rc = VERR_BUFFER_OVERFLOW;
88 }
89 }
90 LogFlow(("RTLdrGetSymbol: return %Rrc *ppvValue=%p\n", rc, *ppvValue));
91 return rc;
92}
93RT_EXPORT_SYMBOL(RTLdrGetSymbol);
94
95
96RTDECL(RTLDRFMT) RTLdrGetFormat(RTLDRMOD hLdrMod)
97{
98 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), RTLDRFMT_INVALID);
99 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
100 return pMod->enmFormat;
101}
102RT_EXPORT_SYMBOL(RTLdrGetFormat);
103
104
105RTDECL(RTLDRTYPE) RTLdrGetType(RTLDRMOD hLdrMod)
106{
107 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), RTLDRTYPE_INVALID);
108 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
109 return pMod->enmType;
110}
111RT_EXPORT_SYMBOL(RTLdrGetType);
112
113
114RTDECL(RTLDRENDIAN) RTLdrGetEndian(RTLDRMOD hLdrMod)
115{
116 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), RTLDRENDIAN_INVALID);
117 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
118 return pMod->enmEndian;
119}
120RT_EXPORT_SYMBOL(RTLdrGetEndian);
121
122
123RTDECL(int) RTLdrClose(RTLDRMOD hLdrMod)
124{
125 LogFlow(("RTLdrClose: hLdrMod=%RTldrm\n", hLdrMod));
126
127 /*
128 * Validate input.
129 */
130 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
131 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
132 //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
133
134 /*
135 * Do it.
136 */
137 int rc = pMod->pOps->pfnClose(pMod);
138 AssertRC(rc);
139 pMod->eState = LDR_STATE_INVALID;
140 pMod->u32Magic++;
141 RTMemFree(pMod);
142
143 LogFlow(("RTLdrClose: returns VINF_SUCCESS\n"));
144 return VINF_SUCCESS;
145}
146RT_EXPORT_SYMBOL(RTLdrClose);
147
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette