VirtualBox

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

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

*: added fFlags parameter to SUPR3HardenedLdrLoadAppPriv(), SUPR3HardenedLdrLoad() and RTLdrLoadEx(). VBoxSVC: slurp in VBoxVMM because it is required by the extension packs

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