[51770] | 1 | /* $Id: VBoxSupLib-win.cpp 64532 2016-11-03 14:02:39Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * IPRT - VBoxSupLib.dll, Windows.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[62490] | 7 | * Copyright (C) 2006-2016 Oracle Corporation
|
---|
[51770] | 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 |
|
---|
[57358] | 28 | /*********************************************************************************************************************************
|
---|
| 29 | * Header Files *
|
---|
| 30 | *********************************************************************************************************************************/
|
---|
[51770] | 31 | #include <iprt/nt/nt-and-windows.h>
|
---|
| 32 |
|
---|
| 33 | #include <iprt/path.h>
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | /**
|
---|
| 37 | * The Dll main entry point.
|
---|
[52024] | 38 | * @remarks The dllexport is for forcing the linker to generate an import
|
---|
[64532] | 39 | * library, so the build system doesn't get confused.
|
---|
[51770] | 40 | */
|
---|
[52024] | 41 | extern "C" __declspec(dllexport)
|
---|
[51770] | 42 | BOOL __stdcall DllMainEntrypoint(HANDLE hModule, DWORD dwReason, PVOID pvReserved)
|
---|
| 43 | {
|
---|
[62677] | 44 | RT_NOREF1(pvReserved);
|
---|
| 45 |
|
---|
[51770] | 46 | switch (dwReason)
|
---|
| 47 | {
|
---|
| 48 | /*
|
---|
| 49 | * Make sure the DLL isn't ever unloaded.
|
---|
| 50 | */
|
---|
| 51 | case DLL_PROCESS_ATTACH:
|
---|
| 52 | {
|
---|
| 53 | WCHAR wszName[RTPATH_MAX];
|
---|
| 54 | SetLastError(NO_ERROR);
|
---|
| 55 | if ( GetModuleFileNameW((HMODULE)hModule, wszName, RT_ELEMENTS(wszName)) > 0
|
---|
[52940] | 56 | && RtlGetLastWin32Error() == NO_ERROR)
|
---|
[51770] | 57 | {
|
---|
| 58 | int cExtraLoads = 2;
|
---|
| 59 | while (cExtraLoads-- > 0)
|
---|
| 60 | LoadLibraryW(wszName);
|
---|
| 61 | }
|
---|
| 62 | break;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | case DLL_THREAD_ATTACH:
|
---|
| 66 | {
|
---|
[51775] | 67 | #ifdef VBOX_WITH_HARDENING
|
---|
| 68 | # ifndef VBOX_WITHOUT_DEBUGGER_CHECKS
|
---|
[51770] | 69 | /*
|
---|
| 70 | * Anti debugging hack that prevents most debug notifications from
|
---|
| 71 | * ending up in the debugger.
|
---|
| 72 | */
|
---|
| 73 | NTSTATUS rcNt = NtSetInformationThread(GetCurrentThread(), ThreadHideFromDebugger, NULL, 0);
|
---|
| 74 | if (!NT_SUCCESS(rcNt))
|
---|
| 75 | {
|
---|
| 76 | __debugbreak();
|
---|
| 77 | return FALSE;
|
---|
| 78 | }
|
---|
[51775] | 79 | # endif
|
---|
[51770] | 80 | #endif
|
---|
| 81 | break;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | case DLL_THREAD_DETACH:
|
---|
| 85 | /* Nothing to do. */
|
---|
| 86 | break;
|
---|
| 87 |
|
---|
| 88 | case DLL_PROCESS_DETACH:
|
---|
| 89 | /* Nothing to do. */
|
---|
| 90 | break;
|
---|
| 91 |
|
---|
| 92 | default:
|
---|
| 93 | /* ignore */
|
---|
| 94 | break;
|
---|
| 95 | }
|
---|
| 96 | return TRUE;
|
---|
| 97 | }
|
---|
| 98 |
|
---|