71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * IPRT - Init Ring-3, Windows Specific Code.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Copyright (C) 2006-2013 Oracle Corporation
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * available from http://www.virtualbox.org. This file is free software;
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * you can redistribute it and/or modify it under the terms of the GNU
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * General Public License (GPL) as published by the Free Software
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * The contents of this file may alternatively be used under the terms
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * of the Common Development and Distribution License Version 1.0
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * VirtualBox OSE distribution, in which case the provisions of the
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * CDDL are applicable instead of those of the GPL.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * You may elect to license modified versions of this file under the
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * terms and conditions of either the GPL or the CDDL or both.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync/*******************************************************************************
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync* Header Files *
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync*******************************************************************************/
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync#include "../init.h"
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync/*******************************************************************************
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync* Global Variables *
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync*******************************************************************************/
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync/** Windows DLL loader protection level. */
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsyncDECLHIDDEN(RTR3WINLDRPROT) g_enmWinLdrProt = RTR3WINLDRPROT_NONE;
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync/** Our simplified windows version. */
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsyncDECLHIDDEN(RTWINOSTYPE) g_enmWinVer = kRTWinOSType_UNKNOWN;
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync/** Extended windows version information. */
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync/** The native kernel32.dll handle. */
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync/** The native ntdll.dll handle. */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * Translates OSVERSIONINOFEX into a Windows OS type.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @returns The Windows OS type.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @param pOSInfoEx The OS info returned by Windows.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @remarks This table has been assembled from Usenet postings, personal
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * observations, and reading other people's code. Please feel
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * free to add to it or correct it.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync dwPlatFormID dwMajorVersion dwMinorVersion dwBuildNumber
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync95 1 4 0 950
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync95 SP1 1 4 0 >950 && <=1080
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync95 OSR2 1 4 <10 >1080
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync98 1 4 10 1998
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync98 SP1 1 4 10 >1998 && <2183
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync98 SE 1 4 10 >=2183
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncME 1 4 90 3000
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncNT 3.51 2 3 51 1057
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncNT 4 2 4 0 1381
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync2000 2 5 0 2195
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncXP 2 5 1 2600
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync2003 2 5 2 3790
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncCE 1.0 3 1 0
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncCE 2.0 3 2 0
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncCE 2.1 3 2 1
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncCE 3.0 3 3 0
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsyncstatic RTWINOSTYPE rtR3InitWinSimplifiedVersion(OSVERSIONINFOEXW const *pOSInfoEx)
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync DWORD const dwPlatformId = pOSInfoEx->dwPlatformId;
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync DWORD const dwMinorVersion = pOSInfoEx->dwMinorVersion;
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync DWORD const dwMajorVersion = pOSInfoEx->dwMajorVersion;
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync DWORD const dwBuildNumber = pOSInfoEx->dwBuildNumber & 0xFFFF; /* Win 9x needs this. */
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync * Initializes the global variables related to windows version.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * ASSUMES OSVERSIONINFOEX starts with the exact same layout as OSVERSIONINFO (safe).
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync AssertCompileMembersSameSizeAndOffset(OSVERSIONINFOEX, szCSDVersion, OSVERSIONINFO, szCSDVersion);
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync AssertCompileMemberOffset(OSVERSIONINFOEX, wServicePackMajor, sizeof(OSVERSIONINFO));
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync * Use the NT version of GetVersionExW so we don't get fooled by
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync * compatability shims.
507150dbeee290c9769dc80de3579a1dcabc8bd0vboxsync g_WinOsInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync LONG (__stdcall *pfnRtlGetVersion)(OSVERSIONINFOEXW *);
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync *(FARPROC *)&pfnRtlGetVersion = GetProcAddress(g_hModNtDll, "RtlGetVersion");
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync * Couldn't find it or it failed, try the windows version of the API.
507150dbeee290c9769dc80de3579a1dcabc8bd0vboxsync g_WinOsInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync if (!GetVersionExW((POSVERSIONINFOW)&g_WinOsInfoEx))
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync * If that didn't work either, just get the basic version bits.
507150dbeee290c9769dc80de3579a1dcabc8bd0vboxsync g_WinOsInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
507150dbeee290c9769dc80de3579a1dcabc8bd0vboxsync if (GetVersionExW((POSVERSIONINFOW)&g_WinOsInfoEx))
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync Assert(g_WinOsInfoEx.dwPlatformId != VER_PLATFORM_WIN32_NT || g_WinOsInfoEx.dwMajorVersion < 5);
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync g_enmWinVer = rtR3InitWinSimplifiedVersion(&g_WinOsInfoEx);
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync * Disable error popups.
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync UINT fOldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | fOldErrMode);
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Restrict DLL searching for the process on windows versions which allow
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * us to do so.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * - The first trick works on XP SP1+ and disables the searching of the
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * current directory.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * - The second trick is W7 w/ KB2533623 and W8+, it restrict the DLL
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * searching to the application directory and the System32 directory.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync typedef BOOL (WINAPI *PFNSETDLLDIRECTORY)(LPCWSTR);
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync PFNSETDLLDIRECTORY pfnSetDllDir = (PFNSETDLLDIRECTORY)GetProcAddress(g_hModKernel32, "SetDllDirectoryW");
bf11cc8a816102c7f343cb5cc113e7a08fa129a0vboxsync /** @bugref 6861: Observed GUI issues on Vista (32-bit and 64-bit). */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync typedef BOOL(WINAPI *PFNSETDEFAULTDLLDIRECTORIES)(DWORD);
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync pfnSetDefDllDirs = (PFNSETDEFAULTDLLDIRECTORIES)GetProcAddress(g_hModKernel32, "SetDefaultDllDirectories");
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync if (pfnSetDefDllDirs(LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32))
71955773a7f477f9a159a491f765ba97e1f00e1avboxsyncDECLHIDDEN(int) rtR3InitNativeFirst(uint32_t fFlags)
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Make sure we've got the handles of the two main Windows NT dlls.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync g_hModKernel32 = GetModuleHandleW(L"kernel32.dll");
71955773a7f477f9a159a491f765ba97e1f00e1avboxsyncDECLHIDDEN(int) rtR3InitNativeFinal(uint32_t fFlags)
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync /* Nothing to do here. */