VirtualBox

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

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

Biggest check-in ever. New source code headers for all (C) innotek files.

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