1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5
6
7
8#ifndef __UNSAFE_H__
9#define __UNSAFE_H__
10
11// should we just check proper inclusion?
12#include <winwrap.h>
13
14#include "staticcontract.h"
15
16inline VOID UnsafeEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
17{
18 STATIC_CONTRACT_LEAF;
19 EnterCriticalSection(lpCriticalSection);
20}
21
22inline VOID UnsafeLeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
23{
24 STATIC_CONTRACT_LEAF;
25 LeaveCriticalSection(lpCriticalSection);
26}
27
28inline BOOL UnsafeTryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
29{
30 STATIC_CONTRACT_LEAF;
31 return TryEnterCriticalSection(lpCriticalSection);
32}
33
34inline VOID UnsafeInitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
35{
36 STATIC_CONTRACT_LEAF;
37 InitializeCriticalSection(lpCriticalSection);
38}
39
40inline VOID UnsafeDeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
41{
42 STATIC_CONTRACT_LEAF;
43 DeleteCriticalSection(lpCriticalSection);
44}
45
46inline HANDLE UnsafeCreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCWSTR lpName)
47{
48 STATIC_CONTRACT_WRAPPER;
49 return WszCreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName);
50}
51
52inline BOOL UnsafeSetEvent(HANDLE hEvent)
53{
54 STATIC_CONTRACT_LEAF;
55 return SetEvent(hEvent);
56}
57
58inline BOOL UnsafeResetEvent(HANDLE hEvent)
59{
60 STATIC_CONTRACT_LEAF;
61 return ResetEvent(hEvent);
62}
63
64inline HANDLE UnsafeCreateSemaphore(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName)
65{
66 STATIC_CONTRACT_WRAPPER;
67 return WszCreateSemaphore(lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName);
68}
69
70inline BOOL UnsafeReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount)
71{
72 STATIC_CONTRACT_LEAF;
73 return ReleaseSemaphore(hSemaphore, lReleaseCount, lpPreviousCount);
74}
75
76inline LPVOID UnsafeTlsGetValue(DWORD dwTlsIndex)
77{
78 STATIC_CONTRACT_LEAF;
79 return TlsGetValue(dwTlsIndex);
80}
81
82inline BOOL UnsafeTlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
83{
84 STATIC_CONTRACT_LEAF;
85 return TlsSetValue(dwTlsIndex, lpTlsValue);
86}
87
88inline DWORD UnsafeTlsAlloc(void)
89{
90 STATIC_CONTRACT_LEAF;
91 return TlsAlloc();
92}
93
94inline BOOL UnsafeTlsFree(DWORD dwTlsIndex)
95{
96 STATIC_CONTRACT_LEAF;
97 return TlsFree(dwTlsIndex);
98}
99
100#endif
101
102
103