VirtualBox

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

Last change on this file since 28863 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/* $Id: ldrNative-win.cpp 28800 2010-04-27 08:22:32Z 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 "internal/ldr.h"
39
40
41int rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle)
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 return RTErrConvertFromWin32(GetLastError());
70}
71
72
73DECLCALLBACK(int) rtldrNativeGetSymbol(PRTLDRMODINTERNAL pMod, const char *pszSymbol, void **ppvValue)
74{
75 PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
76 FARPROC pfn = GetProcAddress((HMODULE)pModNative->hNative, pszSymbol);
77 if (pfn)
78 {
79 *ppvValue = (void *)pfn;
80 return VINF_SUCCESS;
81 }
82 *ppvValue = NULL;
83 return RTErrConvertFromWin32(GetLastError());
84}
85
86
87DECLCALLBACK(int) rtldrNativeClose(PRTLDRMODINTERNAL pMod)
88{
89 PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
90 if (FreeLibrary((HMODULE)pModNative->hNative))
91 {
92 pModNative->hNative = (uintptr_t)INVALID_HANDLE_VALUE;
93 return VINF_SUCCESS;
94 }
95 return RTErrConvertFromWin32(GetLastError());
96}
97
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