ReactOS 0.4.16-dev-732-g2d1144a
win_policies.cpp
Go to the documentation of this file.
1//
2// win_policies.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Wrapper functions that determine what policies should apply for the process in question.
7//
8
9#include <corecrt_internal.h>
10
11template<typename TPolicy>
12static typename TPolicy::policy_type __cdecl get_win_policy(typename TPolicy::appmodel_policy_type defaultValue)
13{
14 typename TPolicy::appmodel_policy_type appmodelPolicy = defaultValue;
15
16 // Secure processes cannot load the appmodel DLL, so only attempt loading
17 // policy information if this is not a secure process.
19 {
20 TPolicy::appmodel_get_policy(&appmodelPolicy);
21 }
22
23 return TPolicy::appmodel_policy_to_policy_type(appmodelPolicy);
24}
25
26template<typename TPolicy>
27static typename TPolicy::policy_type __cdecl get_cached_win_policy(typename TPolicy::appmodel_policy_type defaultValue)
28{
29 static long state_cache = 0;
30 if (long const cached_state = __crt_interlocked_read(&state_cache))
31 {
32 return static_cast<typename TPolicy::policy_type>(cached_state);
33 }
34
35 typename TPolicy::appmodel_policy_type appmodelPolicy = defaultValue;
36
37 // Secure processes cannot load the appmodel DLL, so only attempt loading
38 // policy information if this is not a secure process.
40 {
41 TPolicy::appmodel_get_policy(&appmodelPolicy);
42 }
43
44 typename TPolicy::policy_type const policyValue = TPolicy::appmodel_policy_to_policy_type(appmodelPolicy);
45
46 long const cached_state = _InterlockedExchange(&state_cache, static_cast<long>(policyValue));
47 if (cached_state)
48 {
49 _ASSERTE(cached_state == static_cast<long>(policyValue));
50 }
51
52 return policyValue;
53}
54
55// Determines whether ExitProcess() or TerminateProcess() should be used to end the process
57{
58 struct process_end_policy_properties
59 {
60 typedef process_end_policy policy_type;
61 typedef AppPolicyProcessTerminationMethod appmodel_policy_type;
62
63 static policy_type appmodel_policy_to_policy_type(appmodel_policy_type const appmodelPolicy) throw()
64 {
66 {
68 }
69 else
70 {
72 }
73 }
74
75 static LONG appmodel_get_policy(appmodel_policy_type* appmodelPolicy)
76 {
78 }
79 };
80
81 return get_win_policy<process_end_policy_properties>(AppPolicyProcessTerminationMethod_ExitProcess);
82}
83
84// Determines whether RoInitialize() should be called when creating a thread
86{
87 struct begin_thread_init_policy_properties
88 {
89 typedef begin_thread_init_policy policy_type;
90 typedef AppPolicyThreadInitializationType appmodel_policy_type;
91
92 static_assert(begin_thread_init_policy_unknown == 0, "Default value for cache must be 0");
93
94 static policy_type appmodel_policy_to_policy_type(long const appmodelPolicy) throw()
95 {
97 {
99 }
100 else
101 {
103 }
104 }
105
106 static LONG appmodel_get_policy(appmodel_policy_type* appmodelPolicy)
107 {
109 }
110 };
111
112 return get_cached_win_policy<begin_thread_init_policy_properties>(AppPolicyThreadInitializationType_None);
113}
114
115// Determines whether we should attempt to display assert dialog
117{
118 struct developer_information_policy_properties
119 {
120 typedef developer_information_policy policy_type;
121 typedef AppPolicyShowDeveloperDiagnostic appmodel_policy_type;
122
123 static_assert(developer_information_policy_unknown == 0, "Default value for cache must be 0");
124
125 static policy_type appmodel_policy_to_policy_type(long const appmodelPolicy) throw()
126 {
127 if (appmodelPolicy == AppPolicyShowDeveloperDiagnostic_ShowUI)
128 {
130 }
131 else
132 {
134 }
135 }
136
137 static LONG appmodel_get_policy(appmodel_policy_type* appmodelPolicy)
138 {
140 }
141 };
142
143 return get_cached_win_policy<developer_information_policy_properties>(AppPolicyShowDeveloperDiagnostic_ShowUI);
144}
145
146// Determines what type of windowing model technology is available
148{
149 struct windowing_model_policy_properties
150 {
151 typedef windowing_model_policy policy_type;
152 typedef AppPolicyWindowingModel appmodel_policy_type;
153
154 static_assert(windowing_model_policy_unknown == 0, "Default value for cache must be 0");
155
156 static policy_type appmodel_policy_to_policy_type(long const appmodelPolicy) throw()
157 {
158 switch (appmodelPolicy)
159 {
162
165
168
170 default:
172 }
173 }
174
175 static LONG appmodel_get_policy(appmodel_policy_type* appmodelPolicy)
176 {
177 return __acrt_AppPolicyGetWindowingModelInternal(appmodelPolicy);
178 }
179 };
180
181 return get_cached_win_policy<windowing_model_policy_properties>(AppPolicyWindowingModel_ClassicDesktop);
182}
#define __cdecl
Definition: accygwin.h:79
AppPolicyShowDeveloperDiagnostic
Definition: appmodel.h:27
@ AppPolicyShowDeveloperDiagnostic_ShowUI
Definition: appmodel.h:29
AppPolicyThreadInitializationType
Definition: appmodel.h:21
@ AppPolicyThreadInitializationType_None
Definition: appmodel.h:22
@ AppPolicyThreadInitializationType_InitializeWinRT
Definition: appmodel.h:23
AppPolicyWindowingModel
Definition: appmodel.h:33
@ AppPolicyWindowingModel_ClassicDesktop
Definition: appmodel.h:36
@ AppPolicyWindowingModel_Universal
Definition: appmodel.h:35
@ AppPolicyWindowingModel_None
Definition: appmodel.h:34
@ AppPolicyWindowingModel_ClassicPhone
Definition: appmodel.h:37
AppPolicyProcessTerminationMethod
Definition: appmodel.h:15
@ AppPolicyProcessTerminationMethod_TerminateProcess
Definition: appmodel.h:17
@ AppPolicyProcessTerminationMethod_ExitProcess
Definition: appmodel.h:16
LONG WINAPI __acrt_AppPolicyGetThreadInitializationTypeInternal(_Out_ AppPolicyThreadInitializationType *policy)
developer_information_policy
@ developer_information_policy_ui
@ developer_information_policy_unknown
@ developer_information_policy_none
LONG WINAPI __acrt_AppPolicyGetWindowingModelInternal(_Out_ AppPolicyWindowingModel *policy)
LONG WINAPI __acrt_AppPolicyGetProcessTerminationMethodInternal(_Out_ AppPolicyProcessTerminationMethod *policy)
process_end_policy
@ process_end_policy_terminate_process
@ process_end_policy_exit_process
windowing_model_policy
@ windowing_model_policy_legacyphone
@ windowing_model_policy_unknown
@ windowing_model_policy_none
@ windowing_model_policy_corewindow
@ windowing_model_policy_hwnd
LONG WINAPI __acrt_AppPolicyGetShowDeveloperDiagnosticInternal(_Out_ AppPolicyShowDeveloperDiagnostic *policy)
bool __cdecl __acrt_is_secure_process(void)
Definition: peb_access.cpp:19
begin_thread_init_policy
@ begin_thread_init_policy_ro_initialize
@ begin_thread_init_policy_unknown
@ begin_thread_init_policy_none
#define _ASSERTE(expr)
Definition: crtdbg.h:114
char typename[32]
Definition: main.c:84
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
long LONG
Definition: pedump.c:60
windowing_model_policy __cdecl __acrt_get_windowing_model_policy()
static TPolicy::policy_type __cdecl get_win_policy(typename TPolicy::appmodel_policy_type defaultValue)
process_end_policy __cdecl __acrt_get_process_end_policy()
static TPolicy::policy_type __cdecl get_cached_win_policy(typename TPolicy::appmodel_policy_type defaultValue)
begin_thread_init_policy __cdecl __acrt_get_begin_thread_init_policy()
developer_information_policy __cdecl __acrt_get_developer_information_policy()