VirtualBox

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

Last change on this file since 35024 was 34962, checked in by vboxsync, 14 years ago

build fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1/* $Id: ldrNative-win.cpp 34962 2010-12-10 15:42:36Z 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.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* 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 <iprt/string.h>
39#include "internal/ldr.h"
40
41
42int rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle, char *pszError, size_t cbError)
43{
44 Assert(sizeof(*phHandle) >= sizeof(HMODULE));
45
46 /*
47 * Do we need to add an extension?
48 */
49 if (!RTPathHaveExt(pszFilename))
50 {
51 size_t cch = strlen(pszFilename);
52 char *psz = (char *)alloca(cch + sizeof(".DLL"));
53 if (!psz)
54 return VERR_NO_MEMORY;
55 memcpy(psz, pszFilename, cch);
56 memcpy(psz + cch, ".DLL", sizeof(".DLL"));
57 pszFilename = psz;
58 }
59
60 /*
61 * Attempt load.
62 */
63 HMODULE hmod = LoadLibrary(pszFilename);
64 if (hmod)
65 {
66 *phHandle = (uintptr_t)hmod;
67 return VINF_SUCCESS;
68 }
69
70 /*
71 * Try figure why it failed to load.
72 */
73 DWORD dwErr = GetLastError();
74 int rc = RTErrConvertFromWin32(dwErr);
75 if (cbError)
76 RTStrPrintf(pszError, cbError, "GetLastError=%u", dwErr);
77 return rc;
78}
79
80
81DECLCALLBACK(int) rtldrNativeGetSymbol(PRTLDRMODINTERNAL pMod, const char *pszSymbol, void **ppvValue)
82{
83 PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
84 FARPROC pfn = GetProcAddress((HMODULE)pModNative->hNative, pszSymbol);
85 if (pfn)
86 {
87 *ppvValue = (void *)pfn;
88 return VINF_SUCCESS;
89 }
90 *ppvValue = NULL;
91 return RTErrConvertFromWin32(GetLastError());
92}
93
94
95DECLCALLBACK(int) rtldrNativeClose(PRTLDRMODINTERNAL pMod)
96{
97 PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
98 if (FreeLibrary((HMODULE)pModNative->hNative))
99 {
100 pModNative->hNative = (uintptr_t)INVALID_HANDLE_VALUE;
101 return VINF_SUCCESS;
102 }
103 return RTErrConvertFromWin32(GetLastError());
104}
105
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