VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win32/ldrNative-win32.cpp@ 2981

Last change on this file since 2981 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1/* $Id: ldrNative-win32.cpp 2981 2007-06-01 16:01:28Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Binary Image Loader, Win32 native.
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* Header Files *
24*******************************************************************************/
25#define LOG_GROUP RTLOGGROUP_LDR
26#include <Windows.h>
27
28#include <iprt/ldr.h>
29#include <iprt/assert.h>
30#include <iprt/path.h>
31#include <iprt/err.h>
32#include <iprt/alloca.h>
33#include "internal/ldr.h"
34
35
36int rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle)
37{
38 Assert(sizeof(*phHandle) >= sizeof(HMODULE));
39
40 /*
41 * Do we need to add an extension?
42 */
43 if (!RTPathHaveExt(pszFilename))
44 {
45 size_t cch = strlen(pszFilename);
46 char *psz = (char *)alloca(cch + sizeof(".DLL"));
47 if (!psz)
48 return VERR_NO_MEMORY;
49 memcpy(psz, pszFilename, cch);
50 memcpy(psz + cch, ".DLL", sizeof(".DLL"));
51 pszFilename = psz;
52 }
53
54 /*
55 * Attempt load.
56 */
57 HMODULE hmod = LoadLibrary(pszFilename);
58 if (hmod)
59 {
60 *phHandle = (uintptr_t)hmod;
61 return VINF_SUCCESS;
62 }
63
64 return RTErrConvertFromWin32(GetLastError());
65}
66
67
68DECLCALLBACK(int) rtldrNativeGetSymbol(PRTLDRMODINTERNAL pMod, const char *pszSymbol, void **ppvValue)
69{
70 PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
71 FARPROC pfn = GetProcAddress((HMODULE)pModNative->hNative, pszSymbol);
72 if (pfn)
73 {
74 *ppvValue = (void *)pfn;
75 return VINF_SUCCESS;
76 }
77 *ppvValue = NULL;
78 return RTErrConvertFromWin32(GetLastError());
79}
80
81
82DECLCALLBACK(int) rtldrNativeClose(PRTLDRMODINTERNAL pMod)
83{
84 PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
85 if (FreeLibrary((HMODULE)pModNative->hNative))
86 {
87 pModNative->hNative = (uintptr_t)INVALID_HANDLE_VALUE;
88 return VINF_SUCCESS;
89 }
90 return RTErrConvertFromWin32(GetLastError());
91}
92
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