VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/win/VBoxSupLib-win.cpp@ 78351

Last change on this file since 78351 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1/* $Id: VBoxSupLib-win.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * IPRT - VBoxSupLib.dll, Windows.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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#include <iprt/nt/nt-and-windows.h>
32
33#include <iprt/path.h>
34
35
36/**
37 * The Dll main entry point.
38 * @remarks The dllexport is for forcing the linker to generate an import
39 * library, so the build system doesn't get confused.
40 */
41extern "C" __declspec(dllexport)
42BOOL __stdcall DllMainEntrypoint(HANDLE hModule, DWORD dwReason, PVOID pvReserved)
43{
44 RT_NOREF1(pvReserved);
45
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
56 && RtlGetLastWin32Error() == NO_ERROR)
57 {
58 int cExtraLoads = 2;
59 while (cExtraLoads-- > 0)
60 LoadLibraryW(wszName);
61 }
62 break;
63 }
64
65 case DLL_THREAD_ATTACH:
66 {
67#ifdef VBOX_WITH_HARDENING
68# ifndef VBOX_WITHOUT_DEBUGGER_CHECKS
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 }
79# endif
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
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