diff --git a/src/coreclr/gc/env/gcenv.os.h b/src/coreclr/gc/env/gcenv.os.h index c37f62509e8bc..25a15e3847d34 100644 --- a/src/coreclr/gc/env/gcenv.os.h +++ b/src/coreclr/gc/env/gcenv.os.h @@ -6,17 +6,6 @@ #ifndef __GCENV_OS_H__ #define __GCENV_OS_H__ -#ifdef Sleep -// This is a funny workaround for the fact that "common.h" defines Sleep to be -// Dont_Use_Sleep, with the hope of causing linker errors whenever someone tries to use sleep. -// -// However, GCToOSInterface defines a function called Sleep, which (due to this define) becomes -// "Dont_Use_Sleep", which the GC in turn happily uses. The symbol that GCToOSInterface actually -// exported was called "GCToOSInterface::Dont_Use_Sleep". While we progress in making the GC standalone, -// we'll need to break the dependency on common.h (the VM header) and this problem will become moot. -#undef Sleep -#endif // Sleep - #ifdef HAS_SYSTEM_YIELDPROCESSOR // YieldProcessor is defined to Dont_Use_YieldProcessor. Restore it to the system-default implementation for the GC. #undef YieldProcessor diff --git a/src/coreclr/vm/comsynchronizable.cpp b/src/coreclr/vm/comsynchronizable.cpp index e38debbebeb69..1d7fcf8b15c2c 100644 --- a/src/coreclr/vm/comsynchronizable.cpp +++ b/src/coreclr/vm/comsynchronizable.cpp @@ -463,7 +463,6 @@ FCIMPL2(FC_BOOL_RET, ThreadNative::Join, ThreadBaseObject* pThisUNSAFE, INT32 Ti } FCIMPLEND -#undef Sleep FCIMPL1(void, ThreadNative::Sleep, INT32 iTime) { FCALL_CONTRACT; @@ -476,8 +475,6 @@ FCIMPL1(void, ThreadNative::Sleep, INT32 iTime) } FCIMPLEND -#define Sleep(dwMilliseconds) Dont_Use_Sleep(dwMilliseconds) - extern "C" void QCALLTYPE ThreadNative_UninterruptibleSleep0() { QCALL_CONTRACT; diff --git a/src/coreclr/vm/comsynchronizable.h b/src/coreclr/vm/comsynchronizable.h index 43fcd25b15e06..43f998d0055af 100644 --- a/src/coreclr/vm/comsynchronizable.h +++ b/src/coreclr/vm/comsynchronizable.h @@ -64,9 +64,7 @@ friend class ThreadBaseObject; static FCDECL1(void, Interrupt, ThreadBaseObject* pThisUNSAFE); static FCDECL1(FC_BOOL_RET, IsAlive, ThreadBaseObject* pThisUNSAFE); static FCDECL2(FC_BOOL_RET, Join, ThreadBaseObject* pThisUNSAFE, INT32 Timeout); -#undef Sleep static FCDECL1(void, Sleep, INT32 iTime); -#define Sleep(a) Dont_Use_Sleep(a) static FCDECL1(void, Initialize, ThreadBaseObject* pThisUNSAFE); static FCDECL2(void, SetBackground, ThreadBaseObject* pThisUNSAFE, CLR_BOOL isBackground); static FCDECL1(FC_BOOL_RET, IsBackground, ThreadBaseObject* pThisUNSAFE); diff --git a/src/coreclr/vm/ecalllist.h b/src/coreclr/vm/ecalllist.h index 0bfdff8c6a10e..7262605554832 100644 --- a/src/coreclr/vm/ecalllist.h +++ b/src/coreclr/vm/ecalllist.h @@ -369,9 +369,7 @@ FCFuncEnd() FCFuncStart(gThreadFuncs) FCFuncElement("InternalGetCurrentThread", GetThread) -#undef Sleep FCFuncElement("SleepInternal", ThreadNative::Sleep) -#define Sleep(a) Dont_Use_Sleep(a) FCFuncElement("Initialize", ThreadNative::Initialize) FCFuncElement("SpinWaitInternal", ThreadNative::SpinWait) FCFuncElement("GetCurrentThreadNative", ThreadNative::GetCurrentThread) diff --git a/src/coreclr/vm/hosting.cpp b/src/coreclr/vm/hosting.cpp index 56ae004c0f10c..4783c4d3c521f 100644 --- a/src/coreclr/vm/hosting.cpp +++ b/src/coreclr/vm/hosting.cpp @@ -8,7 +8,6 @@ #include "corhost.h" #include "threads.h" -#undef VirtualAlloc LPVOID ClrVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) { CONTRACTL { @@ -78,36 +77,18 @@ LPVOID ClrVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, } } -#define VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect) Dont_Use_VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect) - -#undef VirtualFree -BOOL ClrVirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType) { - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; +BOOL ClrVirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType) +{ + WRAPPER_NO_CONTRACT; return (BOOL)(BYTE)::VirtualFree (lpAddress, dwSize, dwFreeType); } -#define VirtualFree(lpAddress, dwSize, dwFreeType) Dont_Use_VirtualFree(lpAddress, dwSize, dwFreeType) -#undef VirtualQuery SIZE_T ClrVirtualQuery(LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength) { - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - { - return ::VirtualQuery(lpAddress, lpBuffer, dwLength); - } + WRAPPER_NO_CONTRACT; + return ::VirtualQuery(lpAddress, lpBuffer, dwLength); } -#define VirtualQuery(lpAddress, lpBuffer, dwLength) Dont_Use_VirtualQuery(lpAddress, lpBuffer, dwLength) #if defined(_DEBUG) && !defined(TARGET_UNIX) static VolatilePtr s_pStartOfUEFSection = NULL; @@ -115,7 +96,6 @@ static VolatilePtr s_pEndOfUEFSectionBoundary = NULL; static Volatile s_dwProtection = 0; #endif // _DEBUG && !TARGET_UNIX -#undef VirtualProtect BOOL ClrVirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect) { CONTRACTL @@ -235,29 +215,12 @@ BOOL ClrVirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWO return ::VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect); } -#define VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect) Dont_Use_VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect) -#undef SleepEx DWORD ClrSleepEx(DWORD dwMilliseconds, BOOL bAlertable) { - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - } - CONTRACTL_END; - - DWORD res; - - { - res = ::SleepEx(dwMilliseconds, bAlertable); - } - - return res; + WRAPPER_NO_CONTRACT; + return ::SleepEx(dwMilliseconds, bAlertable); } -#define SleepEx(dwMilliseconds,bAlertable) \ - Dont_Use_SleepEx(dwMilliseconds,bAlertable) // non-zero return value if this function causes the OS to switch to another thread // See file:spinlock.h#SwitchToThreadSpinning for an explanation of dwSwitchCount diff --git a/src/coreclr/vm/threads.cpp b/src/coreclr/vm/threads.cpp index b02c24dffca70..e7ed60c75a487 100644 --- a/src/coreclr/vm/threads.cpp +++ b/src/coreclr/vm/threads.cpp @@ -1006,10 +1006,8 @@ HRESULT Thread::DetachThread(BOOL fDLLThreadDetach) while (m_dwThreadHandleBeingUsed > 0) { // Another thread is using the handle now. -#undef Sleep // We can not call __SwitchToThread since we can not go back to host. - ::Sleep(10); -#define Sleep(a) Dont_Use_Sleep(a) + ClrSleepEx(10, FALSE); } if (m_WeOwnThreadHandle && m_ThreadHandleForClose == INVALID_HANDLE_VALUE) { @@ -6748,11 +6746,7 @@ BOOL Thread::DoesRegionContainGuardPage(UINT_PTR uLowAddress, UINT_PTR uHighAddr while (uStartOfCurrentRegion < uHighAddress) { -#undef VirtualQuery - // This code can run below YieldTask, which means that it must not call back into the host. - // The reason is that YieldTask is invoked by the host, and the host needs not be reentrant. dwRes = VirtualQuery((const void *)uStartOfCurrentRegion, &meminfo, sizeof(meminfo)); -#define VirtualQuery(lpAddress, lpBuffer, dwLength) Dont_Use_VirtualQuery(lpAddress, lpBuffer, dwLength) // If the query fails then assume we have no guard page. if (sizeof(meminfo) != dwRes) diff --git a/src/coreclr/vm/threadsuspend.cpp b/src/coreclr/vm/threadsuspend.cpp index 305145572dd4d..ea6da19f71c10 100644 --- a/src/coreclr/vm/threadsuspend.cpp +++ b/src/coreclr/vm/threadsuspend.cpp @@ -5198,17 +5198,15 @@ BOOL ThreadCaughtInKernelModeExceptionHandling(Thread *pThread, CONTEXT *ctx) // still has page guard bit set. We can't hit the race in such case so we just leave. Besides, we can't access the // memory with page guard flag or not committed. MEMORY_BASIC_INFORMATION mbi; -#undef VirtualQuery - // This code can run below YieldTask, which means that it must not call back into the host. - // The reason is that YieldTask is invoked by the host, and the host needs not be reentrant. if (VirtualQuery((LPCVOID)(UINT_PTR)ctx->Esp, &mbi, sizeof(mbi)) == sizeof(mbi)) { if (!(mbi.State & MEM_COMMIT) || (mbi.Protect & PAGE_GUARD)) return FALSE; } else + { STRESS_LOG0 (LF_SYNC, ERROR, "VirtualQuery failed!"); -#define VirtualQuery(lpAddress, lpBuffer, dwLength) Dont_Use_VirtualQuery(lpAddress, lpBuffer, dwLength) + } // The first two values on the stack should be a pointer to the EXCEPTION_RECORD and a pointer to the CONTEXT. UINT_PTR Esp = (UINT_PTR)ctx->Esp; diff --git a/src/coreclr/vm/win32threadpool.cpp b/src/coreclr/vm/win32threadpool.cpp index e87e80b2f2f83..e8e49f4179802 100644 --- a/src/coreclr/vm/win32threadpool.cpp +++ b/src/coreclr/vm/win32threadpool.cpp @@ -2456,15 +2456,7 @@ DWORD WINAPI ThreadpoolMgr::WaitThreadStart(LPVOID lpArgs) if (threadCB->NumActiveWaits == 0) { - -#undef SleepEx - // @TODO Consider doing a sleep for an idle period and terminating the thread if no activity - //We use SleepEx instead of CLRSLeepEx because CLRSleepEx calls into SQL(or other hosts) in hosted - //scenarios. SQL does not deliver APC's, and the waithread wait insertion/deletion logic depends on - //APC's being delivered. - status = SleepEx(INFINITE,TRUE); -#define SleepEx(a,b) Dont_Use_SleepEx(a,b) - + status = ClrSleepEx(INFINITE,TRUE); _ASSERTE(status == WAIT_IO_COMPLETION); } else if (IsWaitThreadAPCPending()) @@ -2474,15 +2466,7 @@ DWORD WINAPI ThreadpoolMgr::WaitThreadStart(LPVOID lpArgs) //allow the thread to enter alertable wait and thus cause the APC to fire. ResetWaitThreadAPCPending(); - - //We use SleepEx instead of CLRSLeepEx because CLRSleepEx calls into SQL(or other hosts) in hosted - //scenarios. SQL does not deliver APC's, and the waithread wait insertion/deletion logic depends on - //APC's being delivered. - - #undef SleepEx - status = SleepEx(0,TRUE); - #define SleepEx(a,b) Dont_Use_SleepEx(a,b) - + status = ClrSleepEx(0,TRUE); continue; } else @@ -4480,10 +4464,7 @@ void ThreadpoolMgr::TimerThreadFire() EX_TRY { DWORD timeout = FireTimers(); - -#undef SleepEx - SleepEx(timeout, TRUE); -#define SleepEx(a,b) Dont_Use_SleepEx(a,b) + ClrSleepEx(timeout, TRUE); // the thread could wake up either because an APC completed or the sleep timeout // in both case, we need to sweep the timer queue, firing timers, and readjusting