VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/init-win.cpp@ 46727

Last change on this file since 46727 was 46593, checked in by vboxsync, 12 years ago

updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: init-win.cpp 46593 2013-06-17 14:32:51Z vboxsync $ */
2/** @file
3 * IPRT - Init Ring-3, Windows Specific Code.
4 */
5
6/*
7 * Copyright (C) 2006-2013 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/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#define LOG_GROUP RTLOGGROUP_DEFAULT
32#include <Windows.h>
33#ifndef LOAD_LIBRARY_SEARCH_APPLICATION_DIR
34# define LOAD_LIBRARY_SEARCH_APPLICATION_DIR 0x200
35# define LOAD_LIBRARY_SEARCH_SYSTEM32 0x800
36#endif
37
38#include "internal/iprt.h"
39#include <iprt/initterm.h>
40#include <iprt/err.h>
41#include "../init.h"
42
43
44/*******************************************************************************
45* Global Variables *
46*******************************************************************************/
47/** The native kernel32.dll handle. */
48DECLHIDDEN(HMODULE) g_hModKernel32 = NULL;
49/** The native ntdll.dll handle. */
50DECLHIDDEN(HMODULE) g_hModNtDll = NULL;
51/** Windows DLL loader protection level. */
52DECLHIDDEN(RTR3WINLDRPROT) g_enmWinLdrProt = RTR3WINLDRPROT_NONE;
53
54
55DECLHIDDEN(int) rtR3InitNativeObtrusiveWorker(void)
56{
57 /*
58 * Disable error popups.
59 */
60 UINT fOldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
61 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | fOldErrMode);
62
63 /*
64 * Restrict DLL searching for the process on windows versions which allow
65 * us to do so.
66 * - The first trick works on XP SP1+ and disables the searching of the
67 * current directory.
68 * - The second trick is W7 w/ KB2533623 and W8+, it restrict the DLL
69 * searching to the application directory and the System32 directory.
70 */
71 int rc = VINF_SUCCESS;
72
73 typedef BOOL (WINAPI *PFNSETDLLDIRECTORY)(LPCWSTR);
74 PFNSETDLLDIRECTORY pfnSetDllDir = (PFNSETDLLDIRECTORY)GetProcAddress(g_hModKernel32, "SetDllDirectoryW");
75 if (pfnSetDllDir)
76 {
77 if (pfnSetDllDir(L""))
78 g_enmWinLdrProt = RTR3WINLDRPROT_NO_CWD;
79 else
80 rc = VERR_INTERNAL_ERROR_3;
81 }
82
83 typedef BOOL (WINAPI *PFNSETDEFAULTDLLDIRECTORIES)(DWORD);
84 PFNSETDEFAULTDLLDIRECTORIES pfnSetDefDllDirs;
85 pfnSetDefDllDirs = (PFNSETDEFAULTDLLDIRECTORIES)GetProcAddress(g_hModKernel32, "SetDefaultDllDirectories");
86 if (pfnSetDefDllDirs)
87 {
88 if (pfnSetDefDllDirs(LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32))
89 g_enmWinLdrProt = RTR3WINLDRPROT_SAFE;
90 else if (RT_SUCCESS(rc))
91 rc = VERR_INTERNAL_ERROR_4;
92 }
93
94 return rc;
95}
96
97
98DECLHIDDEN(int) rtR3InitNativeFirst(uint32_t fFlags)
99{
100 /*
101 * Make sure we've got the handles of the two main Windows NT dlls.
102 */
103 g_hModKernel32 = GetModuleHandleW(L"kernel32.dll");
104 if (g_hModKernel32 == NULL)
105 return VERR_INTERNAL_ERROR_2;
106 g_hModNtDll = GetModuleHandleW(L"ntdll.dll");
107 if (g_hModNtDll == NULL)
108 return VERR_INTERNAL_ERROR_2;
109
110 int rc = VINF_SUCCESS;
111 if (!(fFlags & RTR3INIT_FLAGS_UNOBTRUSIVE))
112 rc = rtR3InitNativeObtrusiveWorker();
113
114 return rc;
115}
116
117
118DECLHIDDEN(void) rtR3InitNativeObtrusive(void)
119{
120 rtR3InitNativeObtrusiveWorker();
121}
122
123
124DECLHIDDEN(int) rtR3InitNativeFinal(uint32_t fFlags)
125{
126 /* Nothing to do here. */
127 return VINF_SUCCESS;
128}
129
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