Delete Unsafe redefinitions of Windows APIs (#24688)
authorJan Kotas <jkotas@microsoft.com>
Wed, 22 May 2019 04:15:32 +0000 (21:15 -0700)
committerGitHub <noreply@github.com>
Wed, 22 May 2019 04:15:32 +0000 (21:15 -0700)
Leftover from SQL hosting infrastructure

17 files changed:
src/inc/clrhost.h
src/inc/unsafe.h [deleted file]
src/inc/winwrap.h
src/strongname/api/common.h
src/utilcode/clrhost.cpp
src/utilcode/clrhost_nodependencies.cpp
src/utilcode/hostimpl.cpp
src/vm/common.h
src/vm/crst.cpp
src/vm/eedbginterfaceimpl.cpp
src/vm/gcenv.os.cpp
src/vm/i386/excepx86.cpp
src/vm/synch.cpp
src/vm/threads.cpp
src/vm/util.hpp
src/vm/win32threadpool.cpp
src/vm/win32threadpool.h

index 0d90f2c..c210652 100644 (file)
@@ -357,227 +357,6 @@ private:
 
 HMODULE GetCLRModule ();
 
-#ifndef FEATURE_NO_HOST
-/*
-    Here we start the list of functions we want to deprecate.
-    We use a define to generate a linker error.
-    We must insure to include the header file that has the definition we are about
-    to deprecate before we use the #define otherwise we will run into a linker error
-    when legitimately undef'ing the function
-*/
-
-//
-// following are windows deprecates
-//
-#include <windows.h>
-
-/*
-    If you are reading this, you have probably tracked down the fact that memory Alloc,
-    etc. don't work inside your DLL because you are using src\inc & src\utilcode
-    services.
-    You need to use the ClrXXX equivalent functions to properly guarantee your code
-    works correctly wrt hosting and others execution engine requirements.
-    Check the list of Clr functions above
-*/
-
-#define GetProcessHeap() \
-        Dont_Use_GetProcessHeap()
-
-#define VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect) \
-        Dont_Use_VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect)
-
-#define VirtualFree(lpAddress, dwSize, dwFreeType) \
-        Dont_Use_VirtualFree(lpAddress, dwSize, dwFreeType)
-
-#define VirtualQuery(lpAddress, lpBuffer, dwLength) \
-        Dont_Use_VirtualQuery(lpAddress, lpBuffer, dwLength)
-
-#define VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect) \
-        Dont_Use_VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect)
-
-#define HeapCreate(flOptions, dwInitialSize, dwMaximumSize) \
-        Dont_Use_HeapCreate(flOptions, dwInitialSize, dwMaximumSize)
-
-#define HeapDestroy(hHeap) \
-        Dont_Use_HeapDestroy(hHeap)
-
-#define HeapAlloc(hHeap, dwFlags, dwBytes) \
-        Dont_Use_HeapAlloc(hHeap, dwFlags, dwBytes)
-
-#define HeapReAlloc(hHeap, dwFlags, lpMem, dwBytes) \
-        Dont_Use_HeapReAlloc(hHeap, dwFlags, lpMem, dwBytes)
-
-#define HeapFree(hHeap, dwFlags, lpMem) \
-        Dont_Use_HeapFree(hHeap, dwFlags, lpMem)
-
-#define HeapValidate(hHeap, dwFlags, lpMem) \
-        Dont_Use_HeapValidate(hHeap, dwFlags, lpMem)
-
-#define LocalAlloc(uFlags, uBytes) \
-        Dont_Use_LocalAlloc(uFlags, uBytes)
-
-#define LocalFree(hMem) \
-        Dont_Use_LocalFree(hMem)
-
-#define LocalReAlloc(hMem, uBytes, uFlags) \
-        Dont_Use_LocalReAlloc(hMem, uBytes, uFlags)
-
-#define GlobalAlloc(uFlags, dwBytes) \
-        Dont_Use_GlobalAlloc(uFlags, dwBytes)
-
-#define GlobalFree(hMem) \
-        Dont_Use_GlobalFree(hMem)
-
-//#define ExitThread          Dont_Use_ExitThread
-
-#define ExitProcess         Dont_Use_ExitProcess
-
-/*
-    If you are reading this, you have probably tracked down the fact that TlsAlloc,
-    etc. don't work inside your DLL because you are using src\inc & src\utilcode
-    services.
-
-    This is because the CLR can operate in a fiberized environment under host control.
-    When this is the case, logical thread local storage must be fiber-relative rather
-    than thread-relative.
-
-    Although the OS provides FLS routines on .NET Server, it does not yet provide
-    those services on WinXP or Win2K.  So you cannot just use fiber routines from
-    the OS.
-
-    Instead, you must use the ClrFls_ routines described above.  However, there are
-    some important differences between these EE-provided services and the OS TLS
-    services that you are used to:
-
-    1)  There is no TlsAlloc/FlsAlloc equivalent.  You must statically describe
-        your needs via the PredefinedTlsSlots below.  If you have dynamic requirements,
-        you should give yourself a single static slot and then build your dynamic
-        requirements on top of this.  The lack of a dynamic API is a deliberate
-        choice on my part, rather than lack of time.
-
-    2)  You can provide a cleanup routine, which we will call on your behalf.  However,
-        this can be called on a different thread than the "thread" (fiber or thread)
-        which holds the data.  It can be called after that thread has actually been
-        terminated.  It can be called before you see a DLL_THREAD_DETACH on your
-        physical thread.  The circumstances vary based on whether the process is hosted
-        and based on whether TS_WeOwn is set on the internal Thread object.  Make
-        no assumptions here.
-*/
-#define TlsAlloc() \
-        Dont_Use_TlsAlloc()
-
-#define TlsSetValue(dwTlsIndex, lpTlsValue) \
-        Dont_Use_TlsSetValue(dwTlsIndex, lpTlsValue)
-
-#define TlsGetValue(dwTlsIndex) \
-        Dont_Use_TlsGetValue(dwTlsIndex)
-
-#define TlsFree(dwTlsIndex) \
-        Dont_Use_TlsFree(dwTlsIndex)
-
-
-/*
-    If you are reading this, you have probably tracked down the fact that synchronization objects
-    and critical sections don't work inside your DLL because you are using src\inc & src\utilcode services.
-    Please refer to the ClrXXX functions described above to make proper use of synchronization obejct, etc.
-
-    Also it's extremely useful to look at the Holder classes defined above.
-    Those classes provide a nice encapsulation for synchronization object that allows automatic release of locks.
-*/
-#define InitializeCriticalSection(lpCriticalSection) \
-        Dont_Use_InitializeCriticalSection(lpCriticalSection)
-
-#define InitializeCriticalSectionAndSpinCount(lpCriticalSection, dwSpinCount) \
-        Dont_Use_InitializeCriticalSectionAndSpinCount(lpCriticalSection, dwSpinCount)
-
-#define DeleteCriticalSection(lpCriticalSection) \
-        Dont_Use_DeleteCriticalSection(lpCriticalSection)
-
-#define EnterCriticalSection(lpCriticalSection) \
-        Dont_Use_EnterCriticalSection(lpCriticalSection)
-
-#define TryEnterCriticalSection(lpCriticalSection) \
-        Dont_Use_TryEnterCriticalSection(lpCriticalSection)
-
-#define LeaveCriticalSection(lpCriticalSection) \
-        Dont_Use_LeaveCriticalSection(lpCriticalSection)
-
-#ifdef CreateEvent
-#undef CreateEvent
-#endif
-#define CreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName) \
-        Dont_Use_CreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName)
-
-#ifdef OpenEvent
-#undef OpenEvent
-#endif
-#define OpenEvent(dwDesiredAccess, bInheritHandle, lpName) \
-        Dont_Use_OpenEvent(dwDesiredAccess, bInheritHandle, lpName)
-
-#define ResetEvent(hEvent) \
-        Dont_Use_ResetEvent(hEvent)
-
-#define SetEvent(hEvent) \
-        Dont_Use_SetEvent(hEvent)
-
-#define PulseEvent(hEvent) \
-        Dont_Use_PulseEvent(hEvent)
-
-#ifdef CreateSemaphore
-#undef CreateSemaphore
-#endif
-#define CreateSemaphore(lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName) \
-        Dont_Use_CreateSemaphore(lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName)
-
-#ifdef OpenSemaphore
-#undef OpenSemaphore
-#endif
-#define OpenSemaphore(dwDesiredAccess, bInheritHandle, lpName) \
-        Dont_Use_OpenSemaphore(dwDesiredAccess, bInheritHandle, lpName)
-
-#define ReleaseSemaphore(hSemaphore, lReleaseCount, lpPreviousCount) \
-        Dont_Use_ReleaseSemaphore(hSemaphore, lReleaseCount, lpPreviousCount)
-
-#ifdef Sleep
-#undef Sleep
-#endif
-#define Sleep(dwMilliseconds) \
-        Dont_Use_Sleep(dwMilliseconds)
-
-#ifdef SleepEx
-#undef SleepEx
-#endif
-#define SleepEx(dwMilliseconds,bAlertable) \
-        Dont_Use_SleepEx(dwMilliseconds,bAlertable)
-
-//
-// following are clib deprecates
-//
-#include <stdlib.h>
-#include <malloc.h>
-
-#ifdef malloc
-#undef malloc
-#endif
-
-#define _CRT_EXCEPTION_NO_MALLOC
-#define malloc(size) \
-        Dont_Use_malloc(size)
-
-#ifdef realloc
-#undef realloc
-#endif
-#define realloc(memblock, size) \
-        Dont_Use_realloc(memblock, size)
-
-#ifdef free
-#undef free
-#endif
-#define free(memblock) \
-        Dont_Use_free(memblock)
-
-#endif //!FEATURE_NO_HOST
-
 extern void IncCantAllocCount();
 extern void DecCantAllocCount();
 
diff --git a/src/inc/unsafe.h b/src/inc/unsafe.h
deleted file mode 100644 (file)
index ba4a166..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-                                                      
-
-
-#ifndef __UNSAFE_H__
-#define __UNSAFE_H__
-
-// should we just check proper inclusion?
-#include <winwrap.h>
-
-#include "staticcontract.h"
-
-inline VOID UnsafeEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
-{
-    STATIC_CONTRACT_LEAF;
-    EnterCriticalSection(lpCriticalSection);
-}
-
-inline VOID UnsafeLeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
-{
-    STATIC_CONTRACT_LEAF;
-    LeaveCriticalSection(lpCriticalSection);
-}
-
-inline BOOL UnsafeTryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
-{
-    STATIC_CONTRACT_LEAF;
-    return TryEnterCriticalSection(lpCriticalSection);
-}
-
-inline VOID UnsafeInitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
-{
-    STATIC_CONTRACT_LEAF;
-    InitializeCriticalSection(lpCriticalSection);
-}
-
-inline VOID UnsafeDeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
-{
-    STATIC_CONTRACT_LEAF;
-    DeleteCriticalSection(lpCriticalSection);
-}
-
-inline HANDLE UnsafeCreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCWSTR lpName)
-{
-    STATIC_CONTRACT_WRAPPER;
-    return WszCreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName);
-}
-
-inline BOOL UnsafeSetEvent(HANDLE hEvent)
-{
-    STATIC_CONTRACT_LEAF;
-    return SetEvent(hEvent);
-}
-
-inline BOOL UnsafeResetEvent(HANDLE hEvent)
-{
-    STATIC_CONTRACT_LEAF;
-    return ResetEvent(hEvent);
-}
-
-inline HANDLE UnsafeCreateSemaphore(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName)
-{
-    STATIC_CONTRACT_WRAPPER;
-    return WszCreateSemaphore(lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName);
-}
-
-inline BOOL UnsafeReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount)
-{
-    STATIC_CONTRACT_LEAF;
-    return ReleaseSemaphore(hSemaphore, lReleaseCount, lpPreviousCount);
-}
-
-inline LPVOID UnsafeTlsGetValue(DWORD dwTlsIndex)
-{
-    STATIC_CONTRACT_LEAF;
-    return TlsGetValue(dwTlsIndex);
-}
-
-inline BOOL UnsafeTlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
-{
-    STATIC_CONTRACT_LEAF;
-    return TlsSetValue(dwTlsIndex, lpTlsValue);
-}
-
-inline DWORD UnsafeTlsAlloc(void) 
-{
-    STATIC_CONTRACT_LEAF;
-    return TlsAlloc();
-}
-
-inline BOOL UnsafeTlsFree(DWORD dwTlsIndex) 
-{
-    STATIC_CONTRACT_LEAF;
-    return TlsFree(dwTlsIndex);
-}
-
-#endif
-
-
index e438676..84d0bed 100644 (file)
 #undef GetTimeFormat
 #undef LCMapString
 
-// winnetwk.h
-#undef WNetGetConnection
-
-// Win32 Fusion API's
-#undef QueryActCtxW
-
 #endif // !defined(__TODO_PORT_TO_WRAPPERS__)
 
 //
 #define WszMultiByteToWideChar MultiByteToWideChar
 #define WszWideCharToMultiByte WideCharToMultiByte
 #define WszCreateSemaphore CreateSemaphoreW
-#define WszQueryActCtxW QueryActCtxW
 
 
 #ifdef FEATURE_CORESYSTEM
index 4347eba..aea24eb 100644 (file)
@@ -65,9 +65,6 @@
 #pragma function(memcpy,memcmp,strcmp,strcpy,strlen,strcat)
 #endif // _MSC_VER
 
-// make all the unsafe redefinitions available
-#include "unsafe.h"
-
 //-----------------------------------------------------------------------------------------------------------
 
 #include "lazycow.h"
index 649e91e..a20f813 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "stdafx.h"
 
-#include "unsafe.h"
 #include "clrhost.h"
 #include "utilcode.h"
 #include "ex.h"
index d881e1e..a272787 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "stdafx.h"
 
-#include "unsafe.h"
 #include "clrhost.h"
 #include "utilcode.h"
 #include "ex.h"
index 5aacc58..bf0a3ca 100644 (file)
@@ -17,7 +17,6 @@
 #include "clrinternal.h"
 #include "hostimpl.h"
 #include "predeftlsslot.h"
-#include "unsafe.h"
 
 // to avoid to include clrhost.h in this file
 #ifdef FAILPOINTS_ENABLED
@@ -38,7 +37,7 @@ extern LPVOID* (*__ClrFlsGetBlock)();
 //
 LPVOID* ClrFlsGetBlockDirect()
 {
-    return (LPVOID*)UnsafeTlsGetValue(TlsIndex);
+    return (LPVOID*)TlsGetValue(TlsIndex);
 }
 
 //
@@ -52,12 +51,12 @@ static void **CheckThreadState(DWORD slot, BOOL force = TRUE)
     // Ensure we have a TLS Index
     if (TlsIndex == TLS_OUT_OF_INDEXES)
     {
-        DWORD tmp = UnsafeTlsAlloc();
+        DWORD tmp = TlsAlloc();
 
         if (InterlockedCompareExchange((LONG*)&TlsIndex, tmp, TLS_OUT_OF_INDEXES) != (LONG) TLS_OUT_OF_INDEXES)
         {
             // We lost the race with another thread.
-            UnsafeTlsFree(tmp);
+            TlsFree(tmp);
         }
 
         // Switch to faster TLS getter now that the TLS slot is initialized
@@ -90,7 +89,7 @@ static void **CheckThreadState(DWORD slot, BOOL force = TRUE)
         }
         for (int i=0; i<MAX_PREDEFINED_TLS_SLOT; i++)
             pTlsData[i] = 0;
-        UnsafeTlsSetValue(TlsIndex, pTlsData);
+        TlsSetValue(TlsIndex, pTlsData);
     }
 
     return pTlsData;
@@ -101,7 +100,7 @@ static void **CheckThreadState(DWORD slot, BOOL force = TRUE)
 VOID STDMETHODCALLTYPE TLS_FreeMasterSlotIndex()
 {
     if (TlsIndex != TLS_OUT_OF_INDEXES)
-        if (UnsafeTlsFree(TlsIndex))
+        if (TlsFree(TlsIndex))
             TlsIndex = TLS_OUT_OF_INDEXES;
 } // TLS_FreeMasterSlotIndex
 
@@ -158,7 +157,7 @@ LPVOID* STDMETHODCALLTYPE UtilExecutionEngine::TLS_GetDataBlock()
     if (TlsIndex == TLS_OUT_OF_INDEXES)
         return NULL;
 
-    return (LPVOID *)UnsafeTlsGetValue(TlsIndex);
+    return (LPVOID *)TlsGetValue(TlsIndex);
 }
 
 LPVOID STDMETHODCALLTYPE UtilExecutionEngine::TLS_GetValue(DWORD slot) 
@@ -209,39 +208,39 @@ VOID STDMETHODCALLTYPE UtilExecutionEngine::TLS_ThreadDetaching()
 CRITSEC_COOKIE STDMETHODCALLTYPE UtilExecutionEngine::CreateLock(LPCSTR szTag, LPCSTR level, CrstFlags flags) 
 {
     CRITICAL_SECTION *cs = (CRITICAL_SECTION*)malloc(sizeof(CRITICAL_SECTION));
-    UnsafeInitializeCriticalSection(cs);
+    InitializeCriticalSection(cs);
     return (CRITSEC_COOKIE)cs; 
 }
 
 void STDMETHODCALLTYPE UtilExecutionEngine::DestroyLock(CRITSEC_COOKIE lock) 
 {
     _ASSERTE(lock);
-    UnsafeDeleteCriticalSection((CRITICAL_SECTION*)lock);
+    DeleteCriticalSection((CRITICAL_SECTION*)lock);
     free(lock);
 }
 
 void STDMETHODCALLTYPE UtilExecutionEngine::AcquireLock(CRITSEC_COOKIE lock) 
 {
     _ASSERTE(lock);
-    UnsafeEnterCriticalSection((CRITICAL_SECTION*)lock);
+    EnterCriticalSection((CRITICAL_SECTION*)lock);
 }
 
 void STDMETHODCALLTYPE UtilExecutionEngine::ReleaseLock(CRITSEC_COOKIE lock) 
 {
     _ASSERTE(lock);
-    UnsafeLeaveCriticalSection((CRITICAL_SECTION*)lock);
+    LeaveCriticalSection((CRITICAL_SECTION*)lock);
 }
 
 EVENT_COOKIE STDMETHODCALLTYPE UtilExecutionEngine::CreateAutoEvent(BOOL bInitialState) 
 {
-    HANDLE handle = UnsafeCreateEvent(NULL, FALSE, bInitialState, NULL);
+    HANDLE handle = WszCreateEvent(NULL, FALSE, bInitialState, NULL);
     _ASSERTE(handle);
     return (EVENT_COOKIE)handle;
 }
 
 EVENT_COOKIE STDMETHODCALLTYPE UtilExecutionEngine::CreateManualEvent(BOOL bInitialState) 
 {
-    HANDLE handle = UnsafeCreateEvent(NULL, TRUE, bInitialState, NULL);
+    HANDLE handle = WszCreateEvent(NULL, TRUE, bInitialState, NULL);
     _ASSERTE(handle);
     return (EVENT_COOKIE)handle;
 }
@@ -255,13 +254,13 @@ void STDMETHODCALLTYPE UtilExecutionEngine::CloseEvent(EVENT_COOKIE event)
 BOOL STDMETHODCALLTYPE UtilExecutionEngine::ClrSetEvent(EVENT_COOKIE event) 
 {
     _ASSERTE(event);
-    return UnsafeSetEvent((HANDLE)event);
+    return SetEvent((HANDLE)event);
 }
 
 BOOL STDMETHODCALLTYPE UtilExecutionEngine::ClrResetEvent(EVENT_COOKIE event) 
 {
     _ASSERTE(event);
-    return UnsafeResetEvent((HANDLE)event);
+    return ResetEvent((HANDLE)event);
 }
 
 DWORD STDMETHODCALLTYPE UtilExecutionEngine::WaitForEvent(EVENT_COOKIE event, DWORD dwMilliseconds, BOOL bAlertable) 
@@ -278,7 +277,7 @@ DWORD STDMETHODCALLTYPE UtilExecutionEngine::WaitForSingleObject(HANDLE handle,
 
 SEMAPHORE_COOKIE STDMETHODCALLTYPE UtilExecutionEngine::ClrCreateSemaphore(DWORD dwInitial, DWORD dwMax) 
 {
-    HANDLE handle = UnsafeCreateSemaphore(NULL, (LONG)dwInitial, (LONG)dwMax, NULL);
+    HANDLE handle = WszCreateSemaphore(NULL, (LONG)dwInitial, (LONG)dwMax, NULL);
     _ASSERTE(handle);
     return (SEMAPHORE_COOKIE)handle;
 }
@@ -298,7 +297,7 @@ DWORD STDMETHODCALLTYPE UtilExecutionEngine::ClrWaitForSemaphore(SEMAPHORE_COOKI
 BOOL STDMETHODCALLTYPE UtilExecutionEngine::ClrReleaseSemaphore(SEMAPHORE_COOKIE semaphore, LONG lReleaseCount, LONG *lpPreviousCount) 
 {
     _ASSERTE(semaphore);
-    return UnsafeReleaseSemaphore((HANDLE)semaphore, lReleaseCount, lpPreviousCount);
+    return ReleaseSemaphore((HANDLE)semaphore, lReleaseCount, lpPreviousCount);
 }
 
 MUTEX_COOKIE STDMETHODCALLTYPE UtilExecutionEngine::ClrCreateMutex(LPSECURITY_ATTRIBUTES lpMutexAttributes,
index 6fd5a37..c273b52 100644 (file)
@@ -90,9 +90,6 @@
 
 #include "volatile.h"
 
-// make all the unsafe redefinitions available
-#include "unsafe.h"
-
 #include <../../debug/inc/dbgtargetcontext.h>
 
 //-----------------------------------------------------------------------------------------------------------
@@ -384,7 +381,7 @@ inline VOID UnsafeEEEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
     STATIC_CONTRACT_GC_NOTRIGGER;
     STATIC_CONTRACT_CAN_TAKE_LOCK;
 
-    UnsafeEnterCriticalSection(lpCriticalSection);
+    EnterCriticalSection(lpCriticalSection);
     INCTHREADLOCKCOUNT();
 }
 
@@ -393,7 +390,7 @@ inline VOID UnsafeEELeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
     STATIC_CONTRACT_NOTHROW;
     STATIC_CONTRACT_GC_NOTRIGGER;
 
-    UnsafeLeaveCriticalSection(lpCriticalSection);
+    LeaveCriticalSection(lpCriticalSection);
     DECTHREADLOCKCOUNT();
 }
 
@@ -403,7 +400,7 @@ inline BOOL UnsafeEETryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection
     STATIC_CONTRACT_GC_NOTRIGGER;
     STATIC_CONTRACT_CAN_TAKE_LOCK;
 
-    BOOL fEnteredCriticalSection = UnsafeTryEnterCriticalSection(lpCriticalSection);
+    BOOL fEnteredCriticalSection = TryEnterCriticalSection(lpCriticalSection);
     if(fEnteredCriticalSection)
     {
         INCTHREADLOCKCOUNT();
index 36447e2..47602c7 100644 (file)
@@ -42,7 +42,7 @@ VOID CrstBase::InitWorker(INDEBUG_COMMA(CrstType crstType) CrstFlags flags)
     }
 
     {
-        UnsafeInitializeCriticalSection(&m_criticalsection);
+        InitializeCriticalSection(&m_criticalsection);
     }
 
     SetFlags(flags);
@@ -77,7 +77,7 @@ void CrstBase::Destroy()
     GCPreemp __gcHolder((m_dwFlags & CRST_HOST_BREAKABLE) == CRST_HOST_BREAKABLE);
 
     {
-        UnsafeDeleteCriticalSection(&m_criticalsection);
+        DeleteCriticalSection(&m_criticalsection);
     }
 
     LOG((LF_SYNC, INFO3, "Deleting 0x%x\n", this));
@@ -310,7 +310,7 @@ void CrstBase::Enter(INDEBUG(NoLevelCheckFlag noLevelCheckFlag/* = CRST_LEVEL_CH
         }
     }
 
-    UnsafeEnterCriticalSection(&m_criticalsection);
+    EnterCriticalSection(&m_criticalsection);
 
 #ifdef _DEBUG
     PostEnter();
@@ -343,7 +343,7 @@ void CrstBase::Leave()
     Thread * pThread = GetThread();
 #endif
 
-    UnsafeLeaveCriticalSection(&m_criticalsection);
+    LeaveCriticalSection(&m_criticalsection);
 
     // Check for both rare case using one if-check
     if (m_dwFlags & (CRST_TAKEN_DURING_SHUTDOWN | CRST_DEBUGGER_THREAD))
index 32da864..2e5f379 100644 (file)
@@ -397,12 +397,12 @@ CONTEXT *EEDbgInterfaceImpl::GetThreadFilterContext(Thread *thread)
 
 VOID * EEDbgInterfaceImpl::GetThreadDebuggerWord()
 {
-    return UnsafeTlsGetValue(g_debuggerWordTLSIndex);
+    return TlsGetValue(g_debuggerWordTLSIndex);
 }
 
 void EEDbgInterfaceImpl::SetThreadDebuggerWord(VOID *dw)
 {
-    UnsafeTlsSetValue(g_debuggerWordTLSIndex, dw);
+    TlsSetValue(g_debuggerWordTLSIndex, dw);
 }
 
 #endif
index a0d2d77..5658b19 100644 (file)
@@ -1079,28 +1079,28 @@ bool GCToOSInterface::ParseGCHeapAffinitizeRangesEntry(const char** config_strin
 void CLRCriticalSection::Initialize()
 {
     WRAPPER_NO_CONTRACT;
-    UnsafeInitializeCriticalSection(&m_cs);
+    InitializeCriticalSection(&m_cs);
 }
 
 // Destroy the critical section
 void CLRCriticalSection::Destroy()
 {
     WRAPPER_NO_CONTRACT;
-    UnsafeDeleteCriticalSection(&m_cs);
+    DeleteCriticalSection(&m_cs);
 }
 
 // Enter the critical section. Blocks until the section can be entered.
 void CLRCriticalSection::Enter()
 {
     WRAPPER_NO_CONTRACT;
-    UnsafeEnterCriticalSection(&m_cs);
+    EnterCriticalSection(&m_cs);
 }
 
 // Leave the critical section
 void CLRCriticalSection::Leave()
 {
     WRAPPER_NO_CONTRACT;
-    UnsafeLeaveCriticalSection(&m_cs);
+    LeaveCriticalSection(&m_cs);
 }
 
 // An implementatino of GCEvent that delegates to
index 01c216d..3519173 100644 (file)
@@ -1659,7 +1659,7 @@ EXCEPTION_HANDLER_IMPL(COMPlusFrameHandler)
 #ifdef HAVE_GCCOVER // This is a debug only macro
     if (GCStress<cfg_instr_jit>::IsEnabled())
     {
-        // UnsafeTlsGetValue trashes last error. When Complus_GCStress=4, GC is invoked
+        // TlsGetValue trashes last error. When Complus_GCStress=4, GC is invoked
         // on every allowable JITed instruction by means of our exception handling machanism
         // it is very easy to trash the last error. For example, a p/invoke called a native method
         // which sets last error. Before we getting the last error in the IL stub, it is trashed here
index e49428e..8d89415 100644 (file)
@@ -27,7 +27,7 @@ void CLREventBase::CreateAutoEvent (BOOL bInitialState  // If TRUE, initial stat
     SetAutoEvent();
 
     {
-        HANDLE h = UnsafeCreateEvent(NULL,FALSE,bInitialState,NULL);
+        HANDLE h = WszCreateEvent(NULL,FALSE,bInitialState,NULL);
         if (h == NULL) {
             ThrowOutOfMemory();
         }
@@ -77,7 +77,7 @@ void CLREventBase::CreateManualEvent (BOOL bInitialState  // If TRUE, initial st
     CONTRACTL_END;
 
     {
-        HANDLE h = UnsafeCreateEvent(NULL,TRUE,bInitialState,NULL);
+        HANDLE h = WszCreateEvent(NULL,TRUE,bInitialState,NULL);
         if (h == NULL) {
             ThrowOutOfMemory();
         }
@@ -128,7 +128,7 @@ void CLREventBase::CreateMonitorEvent(SIZE_T Cookie)
     FastInterlockOr(&m_dwFlags, CLREVENT_FLAGS_AUTO_EVENT);
 
     {
-        HANDLE h = UnsafeCreateEvent(NULL,FALSE,FALSE,NULL);
+        HANDLE h = WszCreateEvent(NULL,FALSE,FALSE,NULL);
         if (h == NULL) {
             ThrowOutOfMemory();
         }
@@ -226,7 +226,7 @@ void CLREventBase::CreateOSAutoEvent (BOOL bInitialState  // If TRUE, initial st
     SetOSEvent();
     SetAutoEvent();
 
-    HANDLE h = UnsafeCreateEvent(NULL,FALSE,bInitialState,NULL);
+    HANDLE h = WszCreateEvent(NULL,FALSE,bInitialState,NULL);
     if (h == NULL) {
         ThrowOutOfMemory();
     }
@@ -274,7 +274,7 @@ void CLREventBase::CreateOSManualEvent (BOOL bInitialState  // If TRUE, initial
 
     SetOSEvent();
 
-    HANDLE h = UnsafeCreateEvent(NULL,TRUE,bInitialState,NULL);
+    HANDLE h = WszCreateEvent(NULL,TRUE,bInitialState,NULL);
     if (h == NULL) {
         ThrowOutOfMemory();
     }
@@ -342,7 +342,7 @@ BOOL CLREventBase::Set()
     _ASSERTE(Thread::Debug_AllowCallout());
 
     {    
-        return UnsafeSetEvent(m_handle);
+        return SetEvent(m_handle);
     }
 
 }
@@ -365,7 +365,7 @@ BOOL CLREventBase::Reset()
               !"Can not call Reset on AutoEvent");
 
     {
-        return UnsafeResetEvent(m_handle);
+        return ResetEvent(m_handle);
     }
 }
 
@@ -484,7 +484,7 @@ void CLRSemaphore::Create (DWORD dwInitial, DWORD dwMax)
     CONTRACTL_END;
 
     {
-        HANDLE h = UnsafeCreateSemaphore(NULL,dwInitial,dwMax,NULL);
+        HANDLE h = WszCreateSemaphore(NULL,dwInitial,dwMax,NULL);
         if (h == NULL) {
             ThrowOutOfMemory();
         }
@@ -514,7 +514,7 @@ BOOL CLRSemaphore::Release(LONG lReleaseCount, LONG *lpPreviousCount)
     CONTRACTL_END;
 
     {
-        return ::UnsafeReleaseSemaphore(m_handle, lReleaseCount, lpPreviousCount);
+        return ::ReleaseSemaphore(m_handle, lReleaseCount, lpPreviousCount);
     }
 }
 
@@ -589,7 +589,7 @@ void CLRLifoSemaphore::Create(INT32 initialSignalCount, INT32 maximumSignalCount
     _ASSERTE(m_handle == nullptr);
 
 #ifdef FEATURE_PAL
-    HANDLE h = UnsafeCreateSemaphore(nullptr, 0, maximumSignalCount, nullptr);
+    HANDLE h = WszCreateSemaphore(nullptr, 0, maximumSignalCount, nullptr);
 #else // !FEATURE_PAL
     HANDLE h = CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, maximumSignalCount);
 #endif // FEATURE_PAL
@@ -966,7 +966,7 @@ void CLRLifoSemaphore::Release(INT32 releaseCount)
 
     // Wake waiters
 #ifdef FEATURE_PAL
-    BOOL released = UnsafeReleaseSemaphore(m_handle, countOfWaitersToWake, nullptr);
+    BOOL released = ReleaseSemaphore(m_handle, countOfWaitersToWake, nullptr);
     _ASSERTE(released);
 #else // !FEATURE_PAL
     while (--countOfWaitersToWake >= 0)
index 07ea78f..4abc891 100644 (file)
@@ -744,7 +744,7 @@ Thread* SetupThread(BOOL fInternal)
 
 #ifdef FEATURE_INTEROP_DEBUGGING
     // Ensure that debugger word slot is allocated
-    UnsafeTlsSetValue(g_debuggerWordTLSIndex, 0);
+    TlsSetValue(g_debuggerWordTLSIndex, 0);
 #endif
 
     // We now have a Thread object visable to the RS. unmark special status.
@@ -1105,7 +1105,7 @@ void InitThreadManager()
 #endif // !FEATURE_PAL
 
 #ifdef FEATURE_INTEROP_DEBUGGING
-    g_debuggerWordTLSIndex = UnsafeTlsAlloc();
+    g_debuggerWordTLSIndex = TlsAlloc();
     if (g_debuggerWordTLSIndex == TLS_OUT_OF_INDEXES)
         COMPlusThrowWin32();
 #endif
index 5113df6..5d165e6 100644 (file)
@@ -794,8 +794,6 @@ InternalSetupForComCall(-1, -1, -1, true)
 #define SetupForComCallDWORDNoCheckCanRunManagedCode()                      \
 InternalSetupForComCall(-1, -1, -1, false)
 
-#include "unsafe.h"
-
 // A holder for NATIVE_LIBRARY_HANDLE.
 FORCEINLINE void VoidFreeNativeLibrary(NATIVE_LIBRARY_HANDLE h)
 {
index 83d8d4d..2f0625a 100644 (file)
@@ -2981,7 +2981,7 @@ void ThreadpoolMgr::DeleteWait(WaitInfo* waitInfo)
     }
     else if (waitInfo->ExternalCompletionEvent != INVALID_HANDLE)
     {
-        UnsafeSetEvent(waitInfo->ExternalCompletionEvent);
+        SetEvent(waitInfo->ExternalCompletionEvent);
     }
     else if (waitInfo->ExternalEventSafeHandle != NULL)
     {
@@ -4871,7 +4871,7 @@ void ThreadpoolMgr::DeleteTimer(TimerInfo* timerInfo)
 
     if (timerInfo->ExternalCompletionEvent != INVALID_HANDLE)
     {
-        UnsafeSetEvent(timerInfo->ExternalCompletionEvent);
+        SetEvent(timerInfo->ExternalCompletionEvent);
         timerInfo->ExternalCompletionEvent = INVALID_HANDLE;
     }
 
index ff47ea2..e05849e 100644 (file)
@@ -531,7 +531,7 @@ private:
                         HANDLE hEvent = refSH->GetHandle();
                         if (hEvent != INVALID_HANDLE_VALUE)
                         {
-                            UnsafeSetEvent(hEvent);
+                            SetEvent(hEvent);
                         }
                     }
                 }