ReactOS 0.4.16-dev-736-g28b802b
appcrt_dllmain.cpp
Go to the documentation of this file.
1//
2// appcrt_dllmain.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// The entry point for the AppCRT dynamic library.
7//
8#include <corecrt_internal.h>
9
10#ifndef CRTDLL
11 #error This file should only be built into the CRT DLLs
12#endif
13
14extern "C" {
15
16// Flag set iff DllMain was called with DLL_PROCESS_ATTACH
18
20{
21 if (!__vcrt_initialize())
22 return FALSE;
23
24 if (!__acrt_initialize())
25 {
27 return FALSE;
28 }
29
30 // Increment flag indicating the process attach completed successfully:
32 return TRUE;
33}
34
35static BOOL DllMainProcessDetach(bool const terminating)
36{
37 // If there was no prior process attach or if it failed, return immediately:
39 return FALSE;
40
42 if (!__acrt_uninitialize(terminating))
43 return FALSE;
44
45 // The VCRuntime is uninitialized during the AppCRT uninitialization; we do
46 // not need to uninitialize it here.
47 return TRUE;
48}
49
50
51// Make sure this function is not inlined so that we can use it as a place to put a breakpoint for debugging.
53{
54 // Do nothing. This function is used to mark the end of the init process.
55}
56
57static __declspec(noinline) BOOL DllMainDispatch(HINSTANCE, DWORD const fdwReason, LPVOID const lpReserved)
58{
60 switch (fdwReason)
61 {
64 break;
65
68 break;
69
72 break;
73
76 break;
77 }
78
80 return result;
81}
82
84{
86 {
87 // The /GS security cookie must be initialized before any exception
88 // handling targeting the current image is registered. No function
89 // using exception handling can be called in the current image until
90 // after __security_init_cookie has been called.
92 }
93
94 // The remainder of the DllMain implementation is in a separate, noinline
95 // function to ensure that no code that might touch the security cookie
96 // runs before the __security_init_cookie function is called. (If code
97 // that uses EH or array-type local variables were to be inlined into
98 // this function, that would cause the compiler to introduce use of the
99 // cookie into this function, before the call to __security_init_cookie.
100 // The separate, noinline function ensures that this does not occur.)
101 return DllMainDispatch(hInstance, fdwReason, lpReserved);
102}
103
104#ifdef _UCRT_ENCLAVE_BUILD
105
106#include <enclaveids.h>
107
108const IMAGE_ENCLAVE_CONFIG __enclave_config = {
109 sizeof(IMAGE_ENCLAVE_CONFIG),
110 0,
111 0,
112 0,
113 0,
114 0,
115 { 0 },
116 ENCLAVE_IMAGE_ID_UCRT,
117};
118
119#endif
120
121} // extern "C"
BOOL WINAPI __acrt_DllMain(HINSTANCE const hInstance, DWORD const fdwReason, LPVOID const lpReserved)
__acrt_end_boot()
static BOOL DllMainProcessDetach(bool const terminating)
static DWORD const fdwReason
static BOOL DllMainProcessAttach()
static DWORD const LPVOID const lpReserved
return result
static int __acrt_process_attached
HINSTANCE hInstance
Definition: charmap.c:19
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define DLL_THREAD_ATTACH
Definition: compat.h:132
#define noinline
Definition: types.h:64
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
void __declspec(noinline) __cdecl _free_base(void *const block)
Definition: free_base.cpp:98
GLuint64EXT * result
Definition: glext.h:11304
__crt_bool __cdecl __acrt_thread_detach()
__crt_bool __cdecl __acrt_thread_attach()
__crt_bool __cdecl __acrt_uninitialize(__crt_bool const terminating)
__crt_bool __cdecl __acrt_initialize()
void __cdecl __security_init_cookie(void)
Definition: gs_support.c:55
__vcrt_bool __cdecl __vcrt_uninitialize(_In_ __vcrt_bool _Terminating)
Definition: __vcrt_init.c:28
__vcrt_bool __cdecl __vcrt_initialize(void)
Definition: __vcrt_init.c:18
#define WINAPI
Definition: msvc.h:6