VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/ldrNative-win.cpp@ 34959

最後變更 在這個檔案從34959是 34959,由 vboxsync 提交於 14 年 前

Added RTLdrLoadEx for exposing dlerror info.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 3.1 KB
 
1/* $Id: ldrNative-win.cpp 34959 2010-12-10 15:17:31Z vboxsync $ */
2/** @file
3 * IPRT - Binary Image Loader, Win32 native.
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.alldomusa.eu.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* Header Files *
29*******************************************************************************/
30#define LOG_GROUP RTLOGGROUP_LDR
31#include <Windows.h>
32
33#include <iprt/ldr.h>
34#include <iprt/assert.h>
35#include <iprt/path.h>
36#include <iprt/err.h>
37#include <iprt/alloca.h>
38#include "internal/ldr.h"
39
40
41int rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle, char *pszError, size_t cbError)
42{
43 Assert(sizeof(*phHandle) >= sizeof(HMODULE));
44
45 /*
46 * Do we need to add an extension?
47 */
48 if (!RTPathHaveExt(pszFilename))
49 {
50 size_t cch = strlen(pszFilename);
51 char *psz = (char *)alloca(cch + sizeof(".DLL"));
52 if (!psz)
53 return VERR_NO_MEMORY;
54 memcpy(psz, pszFilename, cch);
55 memcpy(psz + cch, ".DLL", sizeof(".DLL"));
56 pszFilename = psz;
57 }
58
59 /*
60 * Attempt load.
61 */
62 HMODULE hmod = LoadLibrary(pszFilename);
63 if (hmod)
64 {
65 *phHandle = (uintptr_t)hmod;
66 return VINF_SUCCESS;
67 }
68
69 /*
70 * Try figure why it failed to load.
71 */
72 DWORD dwErr = GetLastError(dwErr);
73 int rc = RTErrConvertFromWin32(dwErr);
74 if (cbError)
75 RTStrPrintf(pszError, cbError, "GetLastError=%u", dwErr);
76 return rc;
77}
78
79
80DECLCALLBACK(int) rtldrNativeGetSymbol(PRTLDRMODINTERNAL pMod, const char *pszSymbol, void **ppvValue)
81{
82 PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
83 FARPROC pfn = GetProcAddress((HMODULE)pModNative->hNative, pszSymbol);
84 if (pfn)
85 {
86 *ppvValue = (void *)pfn;
87 return VINF_SUCCESS;
88 }
89 *ppvValue = NULL;
90 return RTErrConvertFromWin32(GetLastError());
91}
92
93
94DECLCALLBACK(int) rtldrNativeClose(PRTLDRMODINTERNAL pMod)
95{
96 PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
97 if (FreeLibrary((HMODULE)pModNative->hNative))
98 {
99 pModNative->hNative = (uintptr_t)INVALID_HANDLE_VALUE;
100 return VINF_SUCCESS;
101 }
102 return RTErrConvertFromWin32(GetLastError());
103}
104
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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