diff --git a/src/gc/env/common.h b/src/gc/env/common.h index 39e97b3e7a96..35df7e014192 100644 --- a/src/gc/env/common.h +++ b/src/gc/env/common.h @@ -15,6 +15,7 @@ #include <stdint.h> #include <stddef.h> #include <stdio.h> +#include <string.h> #include <wchar.h> #include <assert.h> #include <stdarg.h> diff --git a/src/gc/env/gcenv.base.h b/src/gc/env/gcenv.base.h index fdfa0fc5ebdc..83376f5d110b 100644 --- a/src/gc/env/gcenv.base.h +++ b/src/gc/env/gcenv.base.h @@ -37,18 +37,6 @@ typedef uint32_t BOOL; typedef uint32_t DWORD; typedef void* LPVOID; -typedef uint32_t UINT; -typedef int32_t LONG; -typedef uintptr_t ULONG_PTR; -typedef void VOID; -typedef void* PVOID; -typedef void * LPSECURITY_ATTRIBUTES; -typedef void const * LPCVOID; -typedef wchar_t * PWSTR, *LPWSTR; -typedef const wchar_t *LPCWSTR, *PCWSTR; -typedef size_t SIZE_T; - -typedef void * HANDLE; // ----------------------------------------------------------------------------------------------------------- // HRESULT subset. @@ -105,14 +93,24 @@ inline HRESULT HRESULT_FROM_WIN32(unsigned long x) #define UNREFERENCED_PARAMETER(P) (void)(P) -#define INVALID_HANDLE_VALUE ((HANDLE)-1) - #ifdef PLATFORM_UNIX #define _vsnprintf vsnprintf #define sprintf_s snprintf #define swprintf_s swprintf #endif +#ifdef UNICODE +#define _tcslen wcslen +#define _tcscpy wcscpy +#define _stprintf_s swprintf_s +#define _tfopen _wfopen +#else +#define _tcslen strlen +#define _tcscpy strcpy +#define _stprintf_s sprintf_s +#define _tfopen fopen +#endif + #define WINAPI __stdcall typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter); @@ -123,12 +121,12 @@ typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter); #if defined(_MSC_VER) #if defined(_ARM_) - + __forceinline void YieldProcessor() { } extern "C" void __emit(const unsigned __int32 opcode); #pragma intrinsic(__emit) #define MemoryBarrier() { __emit(0xF3BF); __emit(0x8F5F); } - + #elif defined(_ARM64_) extern "C" void __yield(void); @@ -141,26 +139,26 @@ typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter); #elif defined(_AMD64_) - extern "C" VOID + extern "C" void _mm_pause ( - VOID + void ); - extern "C" VOID + extern "C" void _mm_mfence ( - VOID + void ); - + #pragma intrinsic(_mm_pause) #pragma intrinsic(_mm_mfence) #define YieldProcessor _mm_pause #define MemoryBarrier _mm_mfence - + #elif defined(_X86_) #define YieldProcessor() __asm { rep nop } - + __forceinline void MemoryBarrier() { int32_t Barrier; @@ -168,7 +166,7 @@ typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter); xchg Barrier, eax } } - + #else // !_ARM_ && !_AMD64_ && !_X86_ #error Unsupported architecture #endif @@ -465,15 +463,6 @@ class FinalizerThread #ifdef FEATURE_REDHAWK typedef uint32_t (__stdcall *BackgroundCallback)(void* pCallbackContext); REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartBackgroundGCThread(BackgroundCallback callback, void* pCallbackContext); - -enum PalCapability -{ - WriteWatchCapability = 0x00000001, // GetWriteWatch() and friends - LowMemoryNotificationCapability = 0x00000002, // CreateMemoryResourceNotification() and friends - GetCurrentProcessorNumberCapability = 0x00000004, // GetCurrentProcessorNumber() -}; - -REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalHasCapability(PalCapability capability); #endif // FEATURE_REDHAWK void DestroyThread(Thread * pThread); @@ -530,7 +519,7 @@ namespace ETW #define LOG(x) -VOID LogSpewAlways(const char *fmt, ...); +void LogSpewAlways(const char *fmt, ...); #define LL_INFO10 4 @@ -581,7 +570,7 @@ class CLRConfig typedef CLRConfigTypes ConfigStringInfo; static uint32_t GetConfigValue(ConfigDWORDInfo eType); - static HRESULT GetConfigValue(ConfigStringInfo /*eType*/, wchar_t * * outVal); + static HRESULT GetConfigValue(ConfigStringInfo /*eType*/, TCHAR * * outVal); }; inline bool FitsInU1(uint64_t val) diff --git a/src/gc/env/gcenv.interlocked.inl b/src/gc/env/gcenv.interlocked.inl index 62e171cadff4..ea4ff88de498 100644 --- a/src/gc/env/gcenv.interlocked.inl +++ b/src/gc/env/gcenv.interlocked.inl @@ -188,12 +188,12 @@ __forceinline T Interlocked::CompareExchangePointer(T volatile *destination, T e { #ifdef _MSC_VER #ifdef BIT64 - return (T)(TADDR)_InterlockedCompareExchangePointer((void* volatile *)destination, exchange, comparand); + return (T)(TADDR)_InterlockedCompareExchangePointer((void* volatile *)destination, (void*)exchange, (void*)comparand); #else return (T)(TADDR)_InterlockedCompareExchange((long volatile *)(void* volatile *)destination, (long)(void*)exchange, (long)(void*)comparand); #endif #else - return (T)(TADDR)__sync_val_compare_and_swap((void* volatile *)destination, comparand, exchange); + return (T)(TADDR)__sync_val_compare_and_swap((void* volatile *)destination, (void*)comparand, (void*)exchange); #endif } diff --git a/src/gc/env/gcenv.os.h b/src/gc/env/gcenv.os.h index c1ae87a0429f..9ffd97b89a7d 100644 --- a/src/gc/env/gcenv.os.h +++ b/src/gc/env/gcenv.os.h @@ -257,18 +257,6 @@ class GCToOSInterface // Return: // Time stamp in milliseconds static uint32_t GetLowPrecisionTimeStamp(); - - // - // File - // - - // Open a file - // Parameters: - // filename - name of the file to open - // mode - mode to open the file in (like in the CRT fopen) - // Return: - // FILE* of the opened file - static FILE* OpenFile(const WCHAR* filename, const WCHAR* mode); }; #endif // __GCENV_OS_H__ diff --git a/src/gc/env/gcenv.structs.h b/src/gc/env/gcenv.structs.h index 7c576a5928f8..8593e5efa1be 100644 --- a/src/gc/env/gcenv.structs.h +++ b/src/gc/env/gcenv.structs.h @@ -33,6 +33,20 @@ typedef void * HANDLE; #ifdef PLATFORM_UNIX +typedef char TCHAR; +#define _T(s) s + +#else + +#ifndef _INC_WINDOWS +typedef wchar_t TCHAR; +#define _T(s) L##s +#endif + +#endif + +#ifdef PLATFORM_UNIX + class EEThreadId { pthread_t m_id; @@ -76,7 +90,7 @@ class EEThreadId void SetToCurrentThread() { - m_uiId = ::GetCurrentThreadId(); + m_uiId = ::GetCurrentThreadId(); } void Clear() diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index b329f894ed32..0add1a9b8ff3 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -168,7 +168,7 @@ size_t GetHighPrecisionTimeStamp() GCStatistics g_GCStatistics; GCStatistics g_LastGCStatistics; -WCHAR* GCStatistics::logFileName = NULL; +TCHAR* GCStatistics::logFileName = NULL; FILE* GCStatistics::logFile = NULL; void GCStatistics::AddGCStats(const gc_mechanisms& settings, size_t timeInMSec) @@ -9507,21 +9507,22 @@ void gc_heap::adjust_ephemeral_limits () FILE* CreateLogFile(const CLRConfig::ConfigStringInfo & info, BOOL is_config) { FILE* logFile; - LPWSTR temp_logfile_name = NULL; + TCHAR * temp_logfile_name = NULL; CLRConfig::GetConfigValue(info, &temp_logfile_name); - WCHAR logfile_name[MAX_LONGPATH+1]; + TCHAR logfile_name[MAX_LONGPATH+1]; if (temp_logfile_name != 0) { - wcscpy(logfile_name, temp_logfile_name); + _tcscpy(logfile_name, temp_logfile_name); } - size_t logfile_name_len = wcslen(logfile_name); - WCHAR* szPid = logfile_name + logfile_name_len; + size_t logfile_name_len = _tcslen(logfile_name); + TCHAR* szPid = logfile_name + logfile_name_len; size_t remaining_space = MAX_LONGPATH + 1 - logfile_name_len; - swprintf_s(szPid, remaining_space, W(".%d%s"), GCToOSInterface::GetCurrentProcessId(), (is_config ? W(".config.log") : W(".log"))); - logFile = GCToOSInterface::OpenFile(logfile_name, W("wb")); + _stprintf_s(szPid, remaining_space, _T(".%d%s"), GCToOSInterface::GetCurrentProcessId(), (is_config ? _T(".config.log") : _T(".log"))); + + logFile = _tfopen(logfile_name, _T("wb")); delete temp_logfile_name; @@ -9614,9 +9615,8 @@ HRESULT gc_heap::initialize_gc (size_t segment_size, GCStatistics::logFileName = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_GCMixLog); if (GCStatistics::logFileName != NULL) { - GCStatistics::logFile = GCToOSInterface::OpenFile((LPCWSTR)GCStatistics::logFileName, W("a")); + GCStatistics::logFile = _tfopen(GCStatistics::logFileName, _T("a")); } - #endif // GC_STATS HRESULT hres = S_OK; @@ -14567,7 +14567,7 @@ int gc_heap::generation_to_condemn (int n_initial, // Need to get it early enough for all heaps to use. available_physical_mem = ms.ullAvailPhys; local_settings->entry_memory_load = ms.dwMemoryLoad; - + // @TODO: Force compaction more often under GCSTRESS if (ms.dwMemoryLoad >= high_memory_load_th || low_memory_detected) { diff --git a/src/gc/gcee.cpp b/src/gc/gcee.cpp index 498c3be7fde3..8da9690a9135 100755 --- a/src/gc/gcee.cpp +++ b/src/gc/gcee.cpp @@ -421,7 +421,7 @@ BOOL ProfilerShouldTrackConditionalWeakTableElements() { #if defined(GC_PROFILING) return CORProfilerTrackConditionalWeakTableElements(); #else - return FALSE; + return FALSE; #endif // defined (GC_PROFILING) } diff --git a/src/gc/gcpriv.h b/src/gc/gcpriv.h index fe40c0ccd74f..9aa864ad6019 100644 --- a/src/gc/gcpriv.h +++ b/src/gc/gcpriv.h @@ -611,7 +611,7 @@ struct GCStatistics : public StatisticsBase { // initialized to the contents of COMPLUS_GcMixLog, or NULL, if not present - static WCHAR* logFileName; + static TCHAR* logFileName; static FILE* logFile; // number of times we executed a background GC, a foreground GC, or a diff --git a/src/gc/handletable.cpp b/src/gc/handletable.cpp index 7ded7832115a..597aeb9dcc8c 100644 --- a/src/gc/handletable.cpp +++ b/src/gc/handletable.cpp @@ -391,7 +391,7 @@ void ValidateFetchObjrefForHandle(OBJECTREF objref, ADIndex appDomainIndex) _ASSERTE(!pDomain->NoAccessToHandleTable()); #if CHECK_APP_DOMAIN_LEAKS - if (g_pConfig->AppDomainLeaks() && objref != NULL) + if (g_pConfig->AppDomainLeaks() && objref != NULL) { if (appDomainIndex.m_dwIndex) objref->TryAssignAppDomain(pDomain); diff --git a/src/gc/sample/CMakeLists.txt b/src/gc/sample/CMakeLists.txt index a46f9aeb8b67..45cdbb2b9d2d 100644 --- a/src/gc/sample/CMakeLists.txt +++ b/src/gc/sample/CMakeLists.txt @@ -22,6 +22,7 @@ set(SOURCES if(WIN32) list(APPEND SOURCES gcenv.windows.cpp) + add_definitions(-DUNICODE=1) else() list(APPEND SOURCES gcenv.unix.cpp) diff --git a/src/gc/sample/gcenv.ee.cpp b/src/gc/sample/gcenv.ee.cpp index e17bb834fa27..cc809e7f869a 100644 --- a/src/gc/sample/gcenv.ee.cpp +++ b/src/gc/sample/gcenv.ee.cpp @@ -250,7 +250,7 @@ void StompWriteBarrierResize(bool /*bReqUpperBoundsCheck*/) { } -VOID LogSpewAlways(const char * /*fmt*/, ...) +void LogSpewAlways(const char * /*fmt*/, ...) { } @@ -282,7 +282,7 @@ uint32_t CLRConfig::GetConfigValue(ConfigDWORDInfo eType) } } -HRESULT CLRConfig::GetConfigValue(ConfigStringInfo /*eType*/, wchar_t * * outVal) +HRESULT CLRConfig::GetConfigValue(ConfigStringInfo /*eType*/, TCHAR * * outVal) { *outVal = NULL; return 0; diff --git a/src/gc/sample/gcenv.h b/src/gc/sample/gcenv.h index c09d012ec471..9920f69e175f 100644 --- a/src/gc/sample/gcenv.h +++ b/src/gc/sample/gcenv.h @@ -16,9 +16,6 @@ #define _ASSERTE(_expr) ASSERT(_expr) #endif -typedef wchar_t WCHAR; -#define W(s) L##s - #include "gcenv.structs.h" #include "gcenv.base.h" #include "gcenv.ee.h" diff --git a/src/gc/sample/gcenv.unix.cpp b/src/gc/sample/gcenv.unix.cpp index f3c502c78c58..51ae723548a7 100644 --- a/src/gc/sample/gcenv.unix.cpp +++ b/src/gc/sample/gcenv.unix.cpp @@ -307,12 +307,6 @@ bool IsGCSpecialThread() #endif // 0 -bool PalHasCapability(PalCapability capability) -{ - // TODO: Implement for background GC - return false; -} - WINBASEAPI UINT WINAPI diff --git a/src/gc/sample/gcenv.windows.cpp b/src/gc/sample/gcenv.windows.cpp index bce8496fdaf3..70157707ee09 100644 --- a/src/gc/sample/gcenv.windows.cpp +++ b/src/gc/sample/gcenv.windows.cpp @@ -85,7 +85,7 @@ bool GCToOSInterface::SetCurrentThreadIdealAffinity(GCThreadAffinity* affinity) proc.Group = (WORD)affinity->Group; proc.Number = (BYTE)affinity->Processor; proc.Reserved = 0; - + success = !!SetThreadIdealProcessorEx(GetCurrentThread(), &proc, NULL); } else @@ -94,7 +94,7 @@ bool GCToOSInterface::SetCurrentThreadIdealAffinity(GCThreadAffinity* affinity) { proc.Number = affinity->Processor; success = !!SetThreadIdealProcessorEx(GetCurrentThread(), &proc, NULL); - } + } } #endif @@ -414,17 +414,6 @@ bool GCToOSInterface::CreateThread(GCThreadFunction function, void* param, GCThr return true; } -// Open a file -// Parameters: -// filename - name of the file to open -// mode - mode to open the file in (like in the CRT fopen) -// Return: -// FILE* of the opened file -FILE* GCToOSInterface::OpenFile(const WCHAR* filename, const WCHAR* mode) -{ - return _wfopen(filename, mode); -} - // Initialize the critical section void CLRCriticalSection::Initialize() { diff --git a/src/inc/winwrap.h b/src/inc/winwrap.h index c0c43eb74c59..00940eb87e0e 100644 --- a/src/inc/winwrap.h +++ b/src/inc/winwrap.h @@ -721,7 +721,7 @@ #endif // FEATURE_CORESYSTEM #ifndef _T -#define _T(str) L ## str +#define _T(str) W(str) #endif diff --git a/src/vm/gcenv.h b/src/vm/gcenv.h index 7ddbe5e46a30..c9d07043af94 100644 --- a/src/vm/gcenv.h +++ b/src/vm/gcenv.h @@ -66,4 +66,10 @@ namespace ETW } GC_ROOT_KIND; }; +#ifdef PLATFORM_UNIX +#define _tcslen wcslen +#define _tcscpy wcscpy +#define _tfopen _wfopen +#endif + #endif // GCENV_H_ diff --git a/src/vm/gcenv.os.cpp b/src/vm/gcenv.os.cpp index 20fb179fe8b5..e54c3714efb6 100644 --- a/src/vm/gcenv.os.cpp +++ b/src/vm/gcenv.os.cpp @@ -484,19 +484,6 @@ bool GCToOSInterface::CreateThread(GCThreadFunction function, void* param, GCThr return true; } -// Open a file -// Parameters: -// filename - name of the file to open -// mode - mode to open the file in (like in the CRT fopen) -// Return: -// FILE* of the opened file -FILE* GCToOSInterface::OpenFile(const WCHAR* filename, const WCHAR* mode) -{ - LIMITED_METHOD_CONTRACT; - - return _wfopen(filename, mode); -} - // Initialize the critical section void CLRCriticalSection::Initialize() {