From 9f707068f946240a9dee7aeb3b4b654286f8fc17 Mon Sep 17 00:00:00 2001 From: Curtis Man Date: Mon, 15 Feb 2021 10:24:19 -0800 Subject: [PATCH 1/6] Partially enable build with GCC: PAL and WABT --- CMakeLists.txt | 73 ++-- lib/Backend/JnHelperMethodList.h | 4 +- lib/Common/Common/MathUtil.cpp | 2 +- lib/Common/Common/MathUtil.h | 2 +- lib/Common/Exceptions/Throw.h | 22 +- lib/Parser/Hash.cpp | 2 +- lib/Parser/Hash.h | 2 +- lib/Parser/Parse.h | 8 +- lib/Parser/Scan.h | 2 +- lib/Runtime/Base/ScriptContext.h | 2 +- lib/Runtime/Debug/TTSupport.h | 2 +- .../Language/JavascriptExceptionOperators.cpp | 2 +- .../Language/JavascriptExceptionOperators.h | 16 +- lib/Runtime/Library/JSONScanner.h | 2 +- lib/Runtime/Library/JavascriptError.cpp | 24 +- lib/Runtime/Library/JavascriptError.h | 24 +- .../RuntimePlatformAgnosticPch.h | 2 +- lib/Runtime/Types/ArrayObject.h | 2 +- lib/SCACore/SCAEngine.h | 8 +- lib/WasmReader/WasmParseTree.h | 2 +- lib/wabt/CMakeLists.txt | 20 +- lib/wabt/chakra/wabtapi.h | 6 +- pal/inc/pal.h | 331 ++++++++++-------- pal/inc/pal_mstypes.h | 11 +- pal/src/debug/debug.cpp | 4 +- pal/src/include/pal/context.h | 4 +- pal/src/misc/bstr.cpp | 5 +- pal/src/misc/random.cpp | 2 +- pal/src/safecrt/memmove_s.c | 22 +- pal/src/safecrt/safecrt_output_s.c | 1 + pal/src/safecrt/safecrt_woutput_s.c | 1 + pal/src/thread/context.cpp | 2 +- 32 files changed, 339 insertions(+), 273 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66a1db6a98d..4a8fa23cd05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,17 @@ cmake_minimum_required(VERSION 3.2) project (CHAKRACORE) +if (CMAKE_C_COMPILER_ID MATCHES "Clang") + set(COMPILER_IS_CLANG 1) + set(COMPILER_IS_GNU 0) +elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU") + set(COMPILER_IS_CLANG 0) + set(COMPILER_IS_GNU 1) +else () + set(COMPILER_IS_CLANG 0) + set(COMPILER_IS_GNU 0) +endif () + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g") # Disable expected CMake workflow @@ -355,32 +366,42 @@ if(CLR_CMAKE_PLATFORM_XPLAT) # CXX WARNING FLAGS set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ -Wno-ignored-attributes\ - -Wno-parentheses-equality\ -Wno-reorder\ - -Wno-microsoft\ -Wno-unused-value\ - -Wno-int-to-void-pointer-cast\ -Wno-invalid-offsetof\ - -Wno-undefined-inline\ - -Wno-inconsistent-missing-override\ - -Wno-c++14-extensions\ - -Wno-macro-redefined\ -Wno-pragmas\ - -Wno-invalid-token-paste\ -Wno-format\ - -Wno-invalid-noreturn\ - -Wno-null-arithmetic\ - -Wno-tautological-constant-out-of-range-compare\ - -Wno-tautological-undefined-compare\ - -Wno-address-of-temporary\ - -Wno-null-conversion\ -Wno-return-type\ -Wno-switch\ - -Wno-int-to-pointer-cast\ - -Wno-tautological-constant-compare\ - -Wno-enum-compare-switch\ - -Wno-unknown-warning-option" + -Wno-int-to-pointer-cast" ) + + if (COMPILER_IS_CLANG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + -Wno-address-of-temporary\ + -Wno-c++14-extensions\ + -Wno-enum-compare-switch\ + -Wno-inconsistent-missing-override\ + -Wno-int-to-void-pointer-cast\ + -Wno-invalid-noreturn\ + -Wno-invalid-token-paste\ + -Wno-macro-redefined\ + -Wno-microsoft\ + -Wno-null-conversion\ + -Wno-null-arithmetic\ + -Wno-parentheses-equality\ + -Wno-tautological-constant-compare\ + -Wno-tautological-constant-out-of-range-compare\ + -Wno-tautological-undefined-compare\ + -Wno-undefined-inline\ + -Wno-unknown-warning-option" + ) + elseif(COMPILER_IS_GNU) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + -Wno-conversion-null" + ) + endif() + # notes.. # -Wno-address-of-temporary # vtinfo.h, VirtualTableInfo::RegisterVirtualTable # -Wno-null-conversion # Check shmemory.cpp and cs.cpp here... @@ -395,17 +416,23 @@ if(CLR_CMAKE_PLATFORM_XPLAT) # -Wno-unknown-warning-option ... well, some of the new switches are not # recognized by older compilers and they fail. So, put this one and not fail + + include(Build/CMakeFeatureDetect.cmake) + # CXX / CC COMPILER FLAGS set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ ${CXX_DO_NOT_OPTIMIZE_SIBLING_CALLS} \ - -fno-omit-frame-pointer \ - -fdelayed-template-parsing" - ) + -fno-omit-frame-pointer" + ) + + if (COMPILER_IS_CLANG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + -fdelayed-template-parsing \ + -fasm-blocks") + endif() - # CXX / CC COMPILER FLAGS add_compile_options( - -fasm-blocks -fms-extensions -fwrapv # Treat signed integer overflow as two's complement ) diff --git a/lib/Backend/JnHelperMethodList.h b/lib/Backend/JnHelperMethodList.h index 7f4adcf08ab..e91fc5d8357 100644 --- a/lib/Backend/JnHelperMethodList.h +++ b/lib/Backend/JnHelperMethodList.h @@ -11,10 +11,10 @@ #endif #define HELPERCALL_MATH(Name, Address, Attributes) \ - HELPERCALLCHK(Name##, Address##, Attributes) + HELPERCALLCHK(Name, Address, Attributes) #define HELPERCALL_FULL_OR_INPLACE_MATH(Name, Address, Attributes) \ - HELPERCALLCHK(Name##, Address##, Attributes) \ + HELPERCALLCHK(Name, Address, Attributes) \ HELPERCALLCHK(Name##_Full, Address##_Full, Attributes) \ HELPERCALLCHK(Name##InPlace, Address##_InPlace, Attributes) diff --git a/lib/Common/Common/MathUtil.cpp b/lib/Common/Common/MathUtil.cpp index 05e8194f150..18b6f2b3455 100644 --- a/lib/Common/Common/MathUtil.cpp +++ b/lib/Common/Common/MathUtil.cpp @@ -32,7 +32,7 @@ Math::Rand() return newRand; } -__declspec(noreturn) void Math::DefaultOverflowPolicy() +DECLSPEC_NORETURN void Math::DefaultOverflowPolicy() { Js::Throw::OutOfMemory(); } diff --git a/lib/Common/Common/MathUtil.h b/lib/Common/Common/MathUtil.h index 18e514bff9e..d0b5b8e7731 100644 --- a/lib/Common/Common/MathUtil.h +++ b/lib/Common/Common/MathUtil.h @@ -72,7 +72,7 @@ class Math // Define a couple of overflow policies for the UInt32Math routines. // The default policy for overflow is to throw an OutOfMemory exception - __declspec(noreturn) static void DefaultOverflowPolicy(); + DECLSPEC_NORETURN static void DefaultOverflowPolicy(); // A functor (class with operator()) which records whether a the calculation // encountered an overflow condition. diff --git a/lib/Common/Exceptions/Throw.h b/lib/Common/Exceptions/Throw.h index d92cfcdae8d..67a65a87f87 100644 --- a/lib/Common/Exceptions/Throw.h +++ b/lib/Common/Exceptions/Throw.h @@ -15,20 +15,20 @@ namespace Js { class Throw { public: - static void __declspec(noreturn) OutOfMemory(); - static void __declspec(noreturn) StackOverflow(ScriptContext *scriptContext, PVOID returnAddress); - static void __declspec(noreturn) NotImplemented(); - static void __declspec(noreturn) InternalError(); - static void __declspec(noreturn) FatalInternalError(HRESULT hr = E_FAIL); - static void __declspec(noreturn) FatalInternalErrorEx(int scenario); - static void __declspec(noreturn) FatalInternalGlobalizationError(); - - static void __declspec(noreturn) FatalProjectionError(); + static void DECLSPEC_NORETURN OutOfMemory(); + static void DECLSPEC_NORETURN StackOverflow(ScriptContext *scriptContext, PVOID returnAddress); + static void DECLSPEC_NORETURN NotImplemented(); + static void DECLSPEC_NORETURN InternalError(); + static void DECLSPEC_NORETURN FatalInternalError(HRESULT hr = E_FAIL); + static void DECLSPEC_NORETURN FatalInternalErrorEx(int scenario); + static void DECLSPEC_NORETURN FatalInternalGlobalizationError(); + + static void DECLSPEC_NORETURN FatalProjectionError(); #if ENABLE_JS_REENTRANCY_CHECK - static void __declspec(noreturn) FatalJsReentrancyError(); + static void DECLSPEC_NORETURN FatalJsReentrancyError(); #endif #ifdef ENABLE_JS_BUILTINS - static void __declspec(noreturn) FatalJsBuiltInError(); + static void DECLSPEC_NORETURN FatalJsBuiltInError(); #endif #if !defined(_M_IX86) && defined(_WIN32) diff --git a/lib/Parser/Hash.cpp b/lib/Parser/Hash.cpp index 1ab6460590e..e6ce2739d2d 100644 --- a/lib/Parser/Hash.cpp +++ b/lib/Parser/Hash.cpp @@ -425,7 +425,7 @@ bool HashTbl::Contains(_In_reads_(cch) LPCOLESTR prgch, int32 cch) #include "HashFunc.cpp" -__declspec(noreturn) void HashTbl::OutOfMemory() +DECLSPEC_NORETURN void HashTbl::OutOfMemory() { throw ParseExceptionObject(ERRnoMemory); } diff --git a/lib/Parser/Hash.h b/lib/Parser/Hash.h index 6b8754820f7..d00d7915390 100644 --- a/lib/Parser/Hash.h +++ b/lib/Parser/Hash.h @@ -474,7 +474,7 @@ class HashTbl static const KWD * KwdOfTok(tokens tk) { return (unsigned int)tk < tkLimKwd ? g_mptkkwd + tk : nullptr; } - static __declspec(noreturn) void OutOfMemory(); + static DECLSPEC_NORETURN void OutOfMemory(); #if PROFILE_DICTIONARY DictionaryStats *stats; #endif diff --git a/lib/Parser/Parse.h b/lib/Parser/Parse.h index bcbc9413c13..3e0c6894a5f 100644 --- a/lib/Parser/Parse.h +++ b/lib/Parser/Parse.h @@ -315,11 +315,11 @@ class Parser HashTbl * GetHashTbl() { return this->GetScanner()->GetHashTbl(); } LPCWSTR GetTokenString(tokens token); - __declspec(noreturn) void Error(HRESULT hr, LPCWSTR stringOne = _u(""), LPCWSTR stringTwo = _u("")); + DECLSPEC_NORETURN void Error(HRESULT hr, LPCWSTR stringOne = _u(""), LPCWSTR stringTwo = _u("")); private: - __declspec(noreturn) void Error(HRESULT hr, ParseNodePtr pnode); - __declspec(noreturn) void Error(HRESULT hr, charcount_t ichMin, charcount_t ichLim, LPCWSTR stringOne = _u(""), LPCWSTR stringTwo = _u("")); - __declspec(noreturn) static void OutOfMemory(); + DECLSPEC_NORETURN void Error(HRESULT hr, ParseNodePtr pnode); + DECLSPEC_NORETURN void Error(HRESULT hr, charcount_t ichMin, charcount_t ichLim, LPCWSTR stringOne = _u(""), LPCWSTR stringTwo = _u("")); + DECLSPEC_NORETURN static void OutOfMemory(); void EnsureStackAvailable(); diff --git a/lib/Parser/Scan.h b/lib/Parser/Scan.h index b928e5de7f8..2fa4b02a8ac 100644 --- a/lib/Parser/Scan.h +++ b/lib/Parser/Scan.h @@ -774,7 +774,7 @@ class Scanner : public IScanner, public EncodingPolicy return m_ptoken->tk = tkScanError; } - __declspec(noreturn) void Error(HRESULT hr) + DECLSPEC_NORETURN void Error(HRESULT hr) { m_pchMinTok = m_currentCharacter; m_cMinTokMultiUnits = this->m_cMultiUnits; diff --git a/lib/Runtime/Base/ScriptContext.h b/lib/Runtime/Base/ScriptContext.h index 30c345c8ec2..a8a71b48d00 100644 --- a/lib/Runtime/Base/ScriptContext.h +++ b/lib/Runtime/Base/ScriptContext.h @@ -1385,7 +1385,7 @@ namespace Js bool HasRecordedException() const { return threadContext->GetRecordedException() != nullptr; } Js::JavascriptExceptionObject * GetAndClearRecordedException(bool *considerPassingToDebugger = nullptr); void RecordException(Js::JavascriptExceptionObject * exceptionObject, bool propagateToDebugger = false); - __declspec(noreturn) void RethrowRecordedException(JavascriptExceptionObject::HostWrapperCreateFuncType hostWrapperCreateFunc); + DECLSPEC_NORETURN void RethrowRecordedException(JavascriptExceptionObject::HostWrapperCreateFuncType hostWrapperCreateFunc); #if ENABLE_NATIVE_CODEGEN BOOL IsNativeAddress(void * codeAddr); diff --git a/lib/Runtime/Debug/TTSupport.h b/lib/Runtime/Debug/TTSupport.h index ac7557490f3..dd33dcd2cad 100644 --- a/lib/Runtime/Debug/TTSupport.h +++ b/lib/Runtime/Debug/TTSupport.h @@ -62,7 +62,7 @@ namespace TTD class TTDebuggerSourceLocation; } -void _NOINLINE __declspec(noreturn) TTDAbort_unrecoverable_error(const char* msg); +void _NOINLINE DECLSPEC_NORETURN TTDAbort_unrecoverable_error(const char* msg); //////// //Memory allocators used by the TT code diff --git a/lib/Runtime/Language/JavascriptExceptionOperators.cpp b/lib/Runtime/Language/JavascriptExceptionOperators.cpp index 5bb2fb808ea..063c47d6510 100644 --- a/lib/Runtime/Language/JavascriptExceptionOperators.cpp +++ b/lib/Runtime/Language/JavascriptExceptionOperators.cpp @@ -996,7 +996,7 @@ namespace Js } #endif - void __declspec(noreturn) JavascriptExceptionOperators::OP_Throw(Var object, ScriptContext* scriptContext) + void DECLSPEC_NORETURN JavascriptExceptionOperators::OP_Throw(Var object, ScriptContext* scriptContext) { Throw(object, scriptContext); } diff --git a/lib/Runtime/Language/JavascriptExceptionOperators.h b/lib/Runtime/Language/JavascriptExceptionOperators.h index 0ca74dfa76d..f5c3c93efea 100644 --- a/lib/Runtime/Language/JavascriptExceptionOperators.h +++ b/lib/Runtime/Language/JavascriptExceptionOperators.h @@ -75,13 +75,13 @@ namespace Js ~PendingFinallyExceptionStack(); }; - static void __declspec(noreturn) OP_Throw(Var object, ScriptContext* scriptContext); - static void __declspec(noreturn) Throw(Var object, ScriptContext* scriptContext); - static void __declspec(noreturn) ThrowExceptionObject(Js::JavascriptExceptionObject* exceptionObject, ScriptContext* scriptContext, bool considerPassingToDebugger = false, PVOID returnAddress = NULL, bool resetStack = false); - static void __declspec(noreturn) RethrowExceptionObject(Js::JavascriptExceptionObject* exceptionObject, ScriptContext* scriptContext, bool considerPassingToDebugger = false); + static void DECLSPEC_NORETURN OP_Throw(Var object, ScriptContext* scriptContext); + static void DECLSPEC_NORETURN Throw(Var object, ScriptContext* scriptContext); + static void DECLSPEC_NORETURN ThrowExceptionObject(Js::JavascriptExceptionObject* exceptionObject, ScriptContext* scriptContext, bool considerPassingToDebugger = false, PVOID returnAddress = NULL, bool resetStack = false); + static void DECLSPEC_NORETURN RethrowExceptionObject(Js::JavascriptExceptionObject* exceptionObject, ScriptContext* scriptContext, bool considerPassingToDebugger = false); - static void __declspec(noreturn) DoThrow(JavascriptExceptionObject* exceptionObject, ScriptContext* scriptContext); - static void __declspec(noreturn) DoThrowCheckClone(JavascriptExceptionObject* exceptionObject, ScriptContext* scriptContext); + static void DECLSPEC_NORETURN DoThrow(JavascriptExceptionObject* exceptionObject, ScriptContext* scriptContext); + static void DECLSPEC_NORETURN DoThrowCheckClone(JavascriptExceptionObject* exceptionObject, ScriptContext* scriptContext); #ifdef _M_X64 static void *OP_TryCatch(void *try_, void *catch_, void *frame, size_t spillSize, size_t argsSize, int hasBailedOutOffset, ScriptContext *scriptContext); @@ -105,8 +105,8 @@ namespace Js static Var OP_RuntimeRangeError(MessageId messageId, ScriptContext* scriptContext); static Var OP_RuntimeReferenceError(MessageId messageId, ScriptContext* scriptContext); static Var OP_WebAssemblyRuntimeError(MessageId messageId, ScriptContext* scriptContext); - static void __declspec(noreturn) ThrowOutOfMemory(ScriptContext* scriptContext); - static void __declspec(noreturn) ThrowStackOverflow(ScriptContext* scriptContext, PVOID returnAddress); + static void DECLSPEC_NORETURN ThrowOutOfMemory(ScriptContext* scriptContext); + static void DECLSPEC_NORETURN ThrowStackOverflow(ScriptContext* scriptContext, PVOID returnAddress); static uint64 GetStackTraceLimit(Var thrownObject, ScriptContext* scriptContext); static Var ThrowTypeErrorRestrictedPropertyAccessor(RecyclableObject* function, CallInfo callInfo, ...); diff --git a/lib/Runtime/Library/JSONScanner.h b/lib/Runtime/Library/JSONScanner.h index e379519be48..40f4c3b7852 100644 --- a/lib/Runtime/Library/JSONScanner.h +++ b/lib/Runtime/Library/JSONScanner.h @@ -24,7 +24,7 @@ namespace JSON uint GetCurrentStringLen() { return currentIndex; } uint GetScanPosition() { return uint(currentChar - inputText); } - void __declspec(noreturn) ThrowSyntaxError(int wErr) + void DECLSPEC_NORETURN ThrowSyntaxError(int wErr) { char16 scanPos[16]; ::_itow_s(GetScanPosition(), scanPos, _countof(scanPos), 10); diff --git a/lib/Runtime/Library/JavascriptError.cpp b/lib/Runtime/Library/JavascriptError.cpp index d24f0145a7d..736e2b80577 100644 --- a/lib/Runtime/Library/JavascriptError.cpp +++ b/lib/Runtime/Library/JavascriptError.cpp @@ -204,7 +204,7 @@ namespace Js return outputStr; } - void __declspec(noreturn) JavascriptError::MapAndThrowError(ScriptContext* scriptContext, HRESULT hr) + void DECLSPEC_NORETURN JavascriptError::MapAndThrowError(ScriptContext* scriptContext, HRESULT hr) { ErrorTypeEnum errorType; hr = MapHr(hr, &errorType); @@ -212,13 +212,13 @@ namespace Js JavascriptError::MapAndThrowError(scriptContext, hr, errorType, nullptr); } - void __declspec(noreturn) JavascriptError::MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO* pei) + void DECLSPEC_NORETURN JavascriptError::MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO* pei) { JavascriptError* pError = MapError(scriptContext, errorType); SetMessageAndThrowError(scriptContext, pError, hr, pei); } - void __declspec(noreturn) JavascriptError::SetMessageAndThrowError(ScriptContext* scriptContext, JavascriptError *pError, int32 hCode, EXCEPINFO* pei) + void DECLSPEC_NORETURN JavascriptError::SetMessageAndThrowError(ScriptContext* scriptContext, JavascriptError *pError, int32 hCode, EXCEPINFO* pei) { PCWSTR varName = (pei ? pei->bstrDescription : nullptr); @@ -240,13 +240,13 @@ namespace Js return pError; \ } \ \ - void __declspec(noreturn) JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, EXCEPINFO* pei) \ + void DECLSPEC_NORETURN JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, EXCEPINFO* pei) \ { \ JavascriptError *pError = create_method(scriptContext); \ SetMessageAndThrowError(scriptContext, pError, hCode, pei); \ } \ \ - void __declspec(noreturn) JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, PCWSTR varName) \ + void DECLSPEC_NORETURN JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, PCWSTR varName) \ { \ JavascriptLibrary *library = scriptContext->GetLibrary(); \ JavascriptError *pError = library->create_method(); \ @@ -254,7 +254,7 @@ namespace Js JavascriptExceptionOperators::Throw(pError, scriptContext); \ } \ \ - void __declspec(noreturn) JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, JavascriptString* varName) \ + void DECLSPEC_NORETURN JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, JavascriptString* varName) \ { \ JavascriptLibrary *library = scriptContext->GetLibrary(); \ JavascriptError *pError = library->create_method(); \ @@ -262,7 +262,7 @@ namespace Js JavascriptExceptionOperators::Throw(pError, scriptContext); \ } \ \ - void __declspec(noreturn) JavascriptError::err_method##Var(ScriptContext* scriptContext, int32 hCode, ...) \ + void DECLSPEC_NORETURN JavascriptError::err_method##Var(ScriptContext* scriptContext, int32 hCode, ...) \ { \ JavascriptLibrary *library = scriptContext->GetLibrary(); \ JavascriptError *pError = library->create_method(); \ @@ -284,7 +284,7 @@ namespace Js THROW_ERROR_IMPL(ThrowWebAssemblyLinkError, CreateWebAssemblyLinkError, GetWebAssemblyLinkErrorType, kjstWebAssemblyLinkError) #undef THROW_ERROR_IMPL - void __declspec(noreturn) JavascriptError::ThrowUnreachable(ScriptContext* scriptContext) { ThrowWebAssemblyRuntimeError(scriptContext, WASMERR_Unreachable); } + void DECLSPEC_NORETURN JavascriptError::ThrowUnreachable(ScriptContext* scriptContext) { ThrowWebAssemblyRuntimeError(scriptContext, WASMERR_Unreachable); } JavascriptError* JavascriptError::MapError(ScriptContext* scriptContext, ErrorTypeEnum errorType) { switch (errorType) @@ -313,7 +313,7 @@ namespace Js }; } - void __declspec(noreturn) JavascriptError::ThrowDispatchError(ScriptContext* scriptContext, HRESULT hCode, PCWSTR message) + void DECLSPEC_NORETURN JavascriptError::ThrowDispatchError(ScriptContext* scriptContext, HRESULT hCode, PCWSTR message) { JavascriptError *pError = scriptContext->GetLibrary()->CreateError(); JavascriptError::SetErrorMessageProperties(pError, hCode, message, scriptContext); @@ -571,17 +571,17 @@ namespace Js END_JS_RUNTIME_CALL(scriptContext); } - void __declspec(noreturn) JavascriptError::ThrowOutOfMemoryError(ScriptContext *scriptContext) + void DECLSPEC_NORETURN JavascriptError::ThrowOutOfMemoryError(ScriptContext *scriptContext) { JavascriptExceptionOperators::ThrowOutOfMemory(scriptContext); } - void __declspec(noreturn) JavascriptError::ThrowStackOverflowError(ScriptContext *scriptContext, PVOID returnAddress) + void DECLSPEC_NORETURN JavascriptError::ThrowStackOverflowError(ScriptContext *scriptContext, PVOID returnAddress) { JavascriptExceptionOperators::ThrowStackOverflow(scriptContext, returnAddress); } - void __declspec(noreturn) JavascriptError::ThrowParserError(ScriptContext* scriptContext, HRESULT hrParser, CompileScriptException* se) + void DECLSPEC_NORETURN JavascriptError::ThrowParserError(ScriptContext* scriptContext, HRESULT hrParser, CompileScriptException* se) { Assert(FAILED(hrParser)); diff --git a/lib/Runtime/Library/JavascriptError.h b/lib/Runtime/Library/JavascriptError.h index 0292c923cd5..638ad3358e4 100644 --- a/lib/Runtime/Library/JavascriptError.h +++ b/lib/Runtime/Library/JavascriptError.h @@ -71,19 +71,19 @@ namespace Js static Var EntryToString(RecyclableObject* function, CallInfo callInfo, ...); - static void __declspec(noreturn) MapAndThrowError(ScriptContext* scriptContext, HRESULT hr); - static void __declspec(noreturn) MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO *ei); - static void __declspec(noreturn) SetMessageAndThrowError(ScriptContext* scriptContext, JavascriptError *pError, int32 hCode, EXCEPINFO* pei); + static void DECLSPEC_NORETURN MapAndThrowError(ScriptContext* scriptContext, HRESULT hr); + static void DECLSPEC_NORETURN MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO *ei); + static void DECLSPEC_NORETURN SetMessageAndThrowError(ScriptContext* scriptContext, JavascriptError *pError, int32 hCode, EXCEPINFO* pei); static JavascriptError* MapError(ScriptContext* scriptContext, ErrorTypeEnum errorType); //HELPERCALL needs a non-overloaded function pointer - static void __declspec(noreturn) ThrowUnreachable(ScriptContext* scriptContext); + static void DECLSPEC_NORETURN ThrowUnreachable(ScriptContext* scriptContext); #define THROW_ERROR_DECL(err_method) \ - static void __declspec(noreturn) err_method(ScriptContext* scriptContext, int32 hCode, EXCEPINFO* ei); \ - static void __declspec(noreturn) err_method(ScriptContext* scriptContext, int32 hCode, PCWSTR varName = nullptr); \ - static void __declspec(noreturn) err_method(ScriptContext* scriptContext, int32 hCode, JavascriptString* varName); \ - static void __declspec(noreturn) err_method##Var(ScriptContext* scriptContext, int32 hCode, ...); + static void DECLSPEC_NORETURN err_method(ScriptContext* scriptContext, int32 hCode, EXCEPINFO* ei); \ + static void DECLSPEC_NORETURN err_method(ScriptContext* scriptContext, int32 hCode, PCWSTR varName = nullptr); \ + static void DECLSPEC_NORETURN err_method(ScriptContext* scriptContext, int32 hCode, JavascriptString* varName); \ + static void DECLSPEC_NORETURN err_method##Var(ScriptContext* scriptContext, int32 hCode, ...); THROW_ERROR_DECL(ThrowError) THROW_ERROR_DECL(ThrowRangeError) @@ -96,14 +96,14 @@ namespace Js THROW_ERROR_DECL(ThrowWebAssemblyLinkError) #undef THROW_ERROR_DECL - static void __declspec(noreturn) ThrowDispatchError(ScriptContext* scriptContext, HRESULT hCode, PCWSTR message); - static void __declspec(noreturn) ThrowOutOfMemoryError(ScriptContext *scriptContext); - static void __declspec(noreturn) ThrowParserError(ScriptContext* scriptContext, HRESULT hrParser, CompileScriptException* se); + static void DECLSPEC_NORETURN ThrowDispatchError(ScriptContext* scriptContext, HRESULT hCode, PCWSTR message); + static void DECLSPEC_NORETURN ThrowOutOfMemoryError(ScriptContext *scriptContext); + static void DECLSPEC_NORETURN ThrowParserError(ScriptContext* scriptContext, HRESULT hrParser, CompileScriptException* se); static ErrorTypeEnum MapParseError(int32 hCode); static JavascriptError* MapParseError(ScriptContext* scriptContext, int32 hCode); static HRESULT GetRuntimeError(RecyclableObject* errorObject, __out_opt LPCWSTR * pMessage); static HRESULT GetRuntimeErrorWithScriptEnter(RecyclableObject* errorObject, __out_opt LPCWSTR * pMessage); - static void __declspec(noreturn) ThrowStackOverflowError(ScriptContext *scriptContext, PVOID returnAddress = nullptr); + static void DECLSPEC_NORETURN ThrowStackOverflowError(ScriptContext *scriptContext, PVOID returnAddress = nullptr); static void SetErrorMessageProperties(JavascriptError *pError, HRESULT errCode, PCWSTR message, ScriptContext* scriptContext); static void SetErrorMessage(JavascriptError *pError, HRESULT errCode, PCWSTR varName, ScriptContext* scriptContext); static void SetErrorMessage(JavascriptError *pError, HRESULT hr, ScriptContext* scriptContext, va_list argList); diff --git a/lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h b/lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h index b71ce84e4f3..cc07edb4d79 100644 --- a/lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h +++ b/lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h @@ -49,7 +49,7 @@ class Throw public: static bool ReportAssert(const char* fileName, unsigned int lineNumber, const char* error, const char* message); static void LogAssert(); - static void __declspec(noreturn) FatalInternalError(); + static void DECLSPEC_NORETURN FatalInternalError(); }; } diff --git a/lib/Runtime/Types/ArrayObject.h b/lib/Runtime/Types/ArrayObject.h index 617b4845e23..f0b07d97e0b 100644 --- a/lib/Runtime/Types/ArrayObject.h +++ b/lib/Runtime/Types/ArrayObject.h @@ -36,7 +36,7 @@ namespace Js // For boxing stack instance ArrayObject(ArrayObject * instance, bool deepCopy); - void __declspec(noreturn) ThrowItemNotConfigurableError(PropertyId propId = Constants::NoProperty); + void DECLSPEC_NORETURN ThrowItemNotConfigurableError(PropertyId propId = Constants::NoProperty); void VerifySetItemAttributes(PropertyId propId, PropertyAttributes attributes); public: diff --git a/lib/SCACore/SCAEngine.h b/lib/SCACore/SCAEngine.h index d591c62c89f..ed600619a14 100644 --- a/lib/SCACore/SCAEngine.h +++ b/lib/SCACore/SCAEngine.h @@ -169,25 +169,25 @@ namespace Js void ThrowIfFailed(HRESULT hr) const; - void __declspec(noreturn) ThrowSCAUnsupported() const + void DECLSPEC_NORETURN ThrowSCAUnsupported() const { // E_SCA_UNSUPPORTED ThrowIfFailed(E_FAIL); } - void __declspec(noreturn) ThrowSCANewVersion() const + void DECLSPEC_NORETURN ThrowSCANewVersion() const { // E_SCA_NEWVERSION ThrowIfFailed(E_FAIL); } - void __declspec(noreturn) ThrowSCADataCorrupt() const + void DECLSPEC_NORETURN ThrowSCADataCorrupt() const { // E_SCA_DATACORRUPT ThrowIfFailed(E_FAIL); } - void __declspec(noreturn) ThrowSCAObjectDetached() const + void DECLSPEC_NORETURN ThrowSCAObjectDetached() const { // E_SCA_TRANSFERABLE_NEUTERED ThrowIfFailed(E_FAIL); diff --git a/lib/WasmReader/WasmParseTree.h b/lib/WasmReader/WasmParseTree.h index eb06ee991e7..41b508292de 100644 --- a/lib/WasmReader/WasmParseTree.h +++ b/lib/WasmReader/WasmParseTree.h @@ -90,7 +90,7 @@ namespace Wasm #endif template - __declspec(noreturn) void CompileAssertCases() + DECLSPEC_NORETURN void CompileAssertCases() { CompileAssertMsg(SwitchCaseChecks::bv::value == AllLocalTypes, "WasmTypes missing in switch-case"); AssertOrFailFastMsg(UNREACHED, "The WasmType case should have been handled"); diff --git a/lib/wabt/CMakeLists.txt b/lib/wabt/CMakeLists.txt index 994533f300e..7ee38f16c91 100644 --- a/lib/wabt/CMakeLists.txt +++ b/lib/wabt/CMakeLists.txt @@ -17,9 +17,23 @@ cmake_minimum_required(VERSION 2.6) project(WABT) -set(COMPILER_IS_CLANG 1) -set(COMPILER_IS_GNU 0) -set(COMPILER_IS_MSVC 0) +if (MSVC) + set(COMPILER_IS_CLANG 0) + set(COMPILER_IS_GNU 0) + set(COMPILER_IS_MSVC 1) +elseif (CMAKE_C_COMPILER_ID MATCHES "Clang") + set(COMPILER_IS_CLANG 1) + set(COMPILER_IS_GNU 0) + set(COMPILER_IS_MSVC 0) +elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU") + set(COMPILER_IS_CLANG 0) + set(COMPILER_IS_GNU 1) + set(COMPILER_IS_MSVC 0) +else () + set(COMPILER_IS_CLANG 0) + set(COMPILER_IS_GNU 0) + set(COMPILER_IS_MSVC 0) +endif () include(CheckIncludeFile) include(CheckSymbolExists) diff --git a/lib/wabt/chakra/wabtapi.h b/lib/wabt/chakra/wabtapi.h index c8f5353af65..1ca45a7b04f 100644 --- a/lib/wabt/chakra/wabtapi.h +++ b/lib/wabt/chakra/wabtapi.h @@ -8,9 +8,11 @@ namespace Js { typedef void* Var; } + +#include typedef unsigned int uint; -typedef __int32 int32; -typedef __int64 int64; +typedef int32_t int32; +typedef int64_t int64; typedef int32 PropertyId; namespace ChakraWabt diff --git a/pal/inc/pal.h b/pal/inc/pal.h index 6415392dad0..7cb2d6b9721 100644 --- a/pal/inc/pal.h +++ b/pal/inc/pal.h @@ -47,10 +47,6 @@ Module Name: #include #endif -#if !defined(static_assert) -#define static_assert _Static_assert -#endif - #if defined(__APPLE__) #ifndef __IOS__ #include "TargetConditionals.h" @@ -214,7 +210,12 @@ extern "C" { /******************* Compiler-specific glue *******************************/ #define FEATURE_PAL_SXS 1 +#if defined(_MSC_VER) #define DECLSPEC_ALIGN(x) __declspec(align(x)) +#else +#define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x))) +#endif + #define DECLSPEC_NORETURN PAL_NORETURN #define __assume(x) (void)0 #define __annotation(x) @@ -2490,13 +2491,10 @@ typedef struct _CONTEXT { #define CONTEXT_EXCEPTION_REQUEST 0x40000000 #define CONTEXT_EXCEPTION_REPORTING 0x80000000 -typedef struct _M128U { +typedef struct DECLSPEC_ALIGN(16) _M128A { ULONGLONG Low; LONGLONG High; -} M128U, *PM128U; - -// Same as _M128U but aligned to a 16-byte boundary -typedef DECLSPEC_ALIGN(16) M128U M128A, *PM128A; +} M128A, *PM128A; typedef struct _XMM_SAVE_AREA32 { WORD ControlWord; @@ -5020,10 +5018,10 @@ typedef EXCEPTION_DISPOSITION (PALAPI *PVECTORED_EXCEPTION_HANDLER)( // Define BitScanForward64 and BitScanForward // Per MSDN, BitScanForward64 will search the mask data from LSB to MSB for a set bit. -// If one is found, its bit position is returned in the out PDWORD argument and 1 is returned. -// Otherwise, 0 is returned. +// If one is found, its bit position is stored in the out PDWORD argument and 1 is returned; +// otherwise, an undefined value is stored in the out PDWORD argument and 0 is returned. // -// On GCC, the equivalent function is __builtin_ffsl. It returns 1+index of the least +// On GCC, the equivalent function is __builtin_ffsll. It returns 1+index of the least // significant set bit, or 0 if if mask is zero. // // The same is true for BitScanForward, except that the GCC function is __builtin_ffs. @@ -5036,18 +5034,12 @@ BitScanForward( IN OUT PDWORD Index, IN UINT qwMask) { - unsigned char bRet = FALSE; - static_assert(sizeof(qwMask) <= sizeof(int), - "use correct __builtin_ffs??? variant"); int iIndex = __builtin_ffs(qwMask); - if (iIndex != 0) - { - // Set the Index after deducting unity - *Index = (DWORD)(iIndex - 1); - bRet = TRUE; - } - - return bRet; + // Set the Index after deducting unity + *Index = (DWORD)(iIndex - 1); + // Both GCC and Clang generate better, smaller code if we check whether the + // mask was/is zero rather than the equivalent check that iIndex is zero. + return qwMask != 0 ? TRUE : FALSE; } EXTERN_C @@ -5059,21 +5051,25 @@ BitScanForward64( IN OUT PDWORD Index, IN UINT64 qwMask) { - unsigned char bRet = FALSE; - static_assert(sizeof(qwMask) <= sizeof(long long), - "use correct __builtin_ffs??? variant"); int iIndex = __builtin_ffsll(qwMask); - if (iIndex != 0) - { - // Set the Index after deducting unity - *Index = (DWORD)(iIndex - 1); - bRet = TRUE; - } - - return bRet; + // Set the Index after deducting unity + *Index = (DWORD)(iIndex - 1); + // Both GCC and Clang generate better, smaller code if we check whether the + // mask was/is zero rather than the equivalent check that iIndex is zero. + return qwMask != 0 ? TRUE : FALSE; } -// xplat-todo: review this implementation +// Define BitScanReverse64 and BitScanReverse +// Per MSDN, BitScanReverse64 will search the mask data from MSB to LSB for a set bit. +// If one is found, its bit position is stored in the out PDWORD argument and 1 is returned. +// Otherwise, an undefined value is stored in the out PDWORD argument and 0 is returned. +// +// GCC/clang don't have a directly equivalent intrinsic; they do provide the __builtin_clzll +// intrinsic, which returns the number of leading 0-bits in x starting at the most significant +// bit position (the result is undefined when x = 0). +// +// The same is true for BitScanReverse, except that the GCC function is __builtin_clzl. + EXTERN_C PALIMPORT inline @@ -5083,20 +5079,16 @@ BitScanReverse( IN OUT PDWORD Index, IN UINT qwMask) { - unsigned char bRet = FALSE; - if (qwMask != 0) - { - static_assert(sizeof(qwMask) <= sizeof(unsigned int), - "use correct __builtin_clz??? variant"); - int countLeadingZero = __builtin_clz(qwMask); - *Index = (DWORD)(sizeof(qwMask) * 8 - 1 - countLeadingZero); - bRet = TRUE; - } - - return bRet; + // The result of __builtin_clzl is undefined when qwMask is zero, + // but it's still OK to call the intrinsic in that case (just don't use the output). + // Unconditionally calling the intrinsic in this way allows the compiler to + // emit branchless code for this function when possible (depending on how the + // intrinsic is implemented for the target platform). + int lzcount = __builtin_clzl(qwMask); + *Index = (DWORD)(31 - lzcount); + return qwMask != 0; } -// xplat-todo: review this implementation EXTERN_C PALIMPORT inline @@ -5106,17 +5098,32 @@ BitScanReverse64( IN OUT PDWORD Index, IN UINT64 qwMask) { - unsigned char bRet = FALSE; - if (qwMask != 0) - { - static_assert(sizeof(qwMask) <= sizeof(unsigned long long), - "use correct __builtin_clz??? variant"); - int countLeadingZero = __builtin_clzll(qwMask); - *Index = (DWORD)(sizeof(qwMask) * 8 - 1 - countLeadingZero); - bRet = TRUE; - } + // The result of __builtin_clzll is undefined when qwMask is zero, + // but it's still OK to call the intrinsic in that case (just don't use the output). + // Unconditionally calling the intrinsic in this way allows the compiler to + // emit branchless code for this function when possible (depending on how the + // intrinsic is implemented for the target platform). + int lzcount = __builtin_clzll(qwMask); + *Index = (DWORD)(63 - lzcount); + return qwMask != 0; +} - return bRet; +FORCEINLINE void PAL_ArmInterlockedOperationBarrier() +{ +#ifdef HOST_ARM64 + // On arm64, most of the __sync* functions generate a code sequence like: + // loop: + // ldaxr (load acquire exclusive) + // ... + // stlxr (store release exclusive) + // cbnz loop + // + // It is possible for a load following the code sequence above to be reordered to occur prior to the store above due to the + // release barrier, this is substantiated by https://github.com/dotnet/coreclr/pull/17508. Interlocked operations in the PAL + // require the load to occur after the store. This memory barrier should be used following a call to a __sync* function to + // prevent that reordering. Code generated for arm32 includes a 'dmb' after 'cbnz', so no issue there at the moment. + __sync_synchronize(); +#endif // HOST_ARM64 } /*++ @@ -5144,20 +5151,11 @@ inline LONG PALAPI InterlockedIncrement( - IN OUT LONG volatile *lpAddend) + IN OUT LONG volatile* lpAddend) { - return __sync_add_and_fetch(lpAddend, (LONG)1); -} - -EXTERN_C -PALIMPORT -inline -LONGLONG -PALAPI -InterlockedIncrement16( - IN OUT SHORT volatile *lpAddend) -{ - return __sync_add_and_fetch(lpAddend, (SHORT)1); + LONG result = __sync_add_and_fetch(lpAddend, (LONG)1); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5166,9 +5164,11 @@ inline LONGLONG PALAPI InterlockedIncrement64( - IN OUT LONGLONG volatile *lpAddend) + IN OUT LONGLONG volatile* lpAddend) { - return __sync_add_and_fetch(lpAddend, (LONGLONG)1); + LONGLONG result = __sync_add_and_fetch(lpAddend, (LONGLONG)1); + PAL_ArmInterlockedOperationBarrier(); + return result; } /*++ @@ -5196,9 +5196,11 @@ inline LONG PALAPI InterlockedDecrement( - IN OUT LONG volatile *lpAddend) + IN OUT LONG volatile* lpAddend) { - return __sync_sub_and_fetch(lpAddend, (LONG)1); + LONG result = __sync_sub_and_fetch(lpAddend, (LONG)1); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5207,9 +5209,11 @@ inline LONGLONG PALAPI InterlockedDecrement64( - IN OUT LONGLONG volatile *lpAddend) + IN OUT LONGLONG volatile* lpAddend) { - return __sync_sub_and_fetch(lpAddend, (LONGLONG)1); + LONGLONG result = __sync_sub_and_fetch(lpAddend, (LONGLONG)1); + PAL_ArmInterlockedOperationBarrier(); + return result; } /*++ @@ -5242,7 +5246,9 @@ InterlockedExchange8( IN OUT char volatile *Target, IN char Value) { - return __sync_swap(Target, Value); + char result = __atomic_exchange_n(Target, Value, __ATOMIC_ACQ_REL); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5254,7 +5260,9 @@ InterlockedExchange16( IN OUT short volatile *Target, IN short Value) { - return __sync_swap(Target, Value); + short result = __atomic_exchange_n(Target, Value, __ATOMIC_ACQ_REL); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5263,10 +5271,12 @@ inline LONG PALAPI InterlockedExchange( - IN OUT LONG volatile *Target, + IN OUT LONG volatile* Target, IN LONG Value) { - return __sync_swap(Target, Value); + LONG result = __atomic_exchange_n(Target, Value, __ATOMIC_ACQ_REL); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5275,10 +5285,12 @@ inline LONGLONG PALAPI InterlockedExchange64( - IN OUT LONGLONG volatile *Target, + IN OUT LONGLONG volatile* Target, IN LONGLONG Value) { - return __sync_swap(Target, Value); + LONGLONG result = __atomic_exchange_n(Target, Value, __ATOMIC_ACQ_REL); + PAL_ArmInterlockedOperationBarrier(); + return result; } /*++ @@ -5314,10 +5326,13 @@ InterlockedCompareExchange8( IN char Exchange, IN char Comperand) { - return __sync_val_compare_and_swap( - Destination, /* The pointer to a variable whose value is to be compared with. */ - Comperand, /* The value to be compared */ - Exchange /* The value to be stored */); + char result = + __sync_val_compare_and_swap( + Destination, /* The pointer to a variable whose value is to be compared with. */ + Comperand, /* The value to be compared */ + Exchange /* The value to be stored */); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5330,10 +5345,13 @@ InterlockedCompareExchange16( IN short Exchange, IN short Comperand) { - return __sync_val_compare_and_swap( - Destination, /* The pointer to a variable whose value is to be compared with. */ - Comperand, /* The value to be compared */ - Exchange /* The value to be stored */); + short result = + __sync_val_compare_and_swap( + Destination, /* The pointer to a variable whose value is to be compared with. */ + Comperand, /* The value to be compared */ + Exchange /* The value to be stored */); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5342,49 +5360,21 @@ inline LONG PALAPI InterlockedCompareExchange( - IN OUT LONG volatile *Destination, + IN OUT LONG volatile* Destination, IN LONG Exchange, IN LONG Comperand) { - return __sync_val_compare_and_swap( - Destination, /* The pointer to a variable whose value is to be compared with. */ - Comperand, /* The value to be compared */ - Exchange /* The value to be stored */); + LONG result = + __sync_val_compare_and_swap( + Destination, /* The pointer to a variable whose value is to be compared with. */ + Comperand, /* The value to be compared */ + Exchange /* The value to be stored */); + PAL_ArmInterlockedOperationBarrier(); + return result; } -EXTERN_C -PALIMPORT -inline -LONG -PALAPI -InterlockedCompareExchangeAcquire( - IN OUT LONG volatile *Destination, - IN LONG Exchange, - IN LONG Comperand) -{ - // TODO: implement the version with only the acquire semantics - return __sync_val_compare_and_swap( - Destination, /* The pointer to a variable whose value is to be compared with. */ - Comperand, /* The value to be compared */ - Exchange /* The value to be stored */); -} - -EXTERN_C -PALIMPORT -inline -LONG -PALAPI -InterlockedCompareExchangeRelease( - IN OUT LONG volatile *Destination, - IN LONG Exchange, - IN LONG Comperand) -{ - // TODO: implement the version with only the release semantics - return __sync_val_compare_and_swap( - Destination, /* The pointer to a variable whose value is to be compared with. */ - Comperand, /* The value to be compared */ - Exchange /* The value to be stored */); -} +#define InterlockedCompareExchangeAcquire InterlockedCompareExchange +#define InterlockedCompareExchangeRelease InterlockedCompareExchange // See the 32-bit variant in interlock2.s EXTERN_C @@ -5393,14 +5383,17 @@ inline LONGLONG PALAPI InterlockedCompareExchange64( - IN OUT LONGLONG volatile *Destination, + IN OUT LONGLONG volatile* Destination, IN LONGLONG Exchange, IN LONGLONG Comperand) { - return __sync_val_compare_and_swap( - Destination, /* The pointer to a variable whose value is to be compared with. */ - Comperand, /* The value to be compared */ - Exchange /* The value to be stored */); + LONGLONG result = + __sync_val_compare_and_swap( + Destination, /* The pointer to a variable whose value is to be compared with. */ + Comperand, /* The value to be compared */ + Exchange /* The value to be stored */); + PAL_ArmInterlockedOperationBarrier(); + return result; } /*++ @@ -5429,7 +5422,9 @@ InterlockedExchangeAdd8( IN OUT char volatile *Addend, IN char Value) { - return __sync_fetch_and_add(Addend, Value); + char result = __sync_fetch_and_add(Addend, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5441,7 +5436,9 @@ InterlockedExchangeAdd16( IN OUT short volatile *Addend, IN short Value) { - return __sync_fetch_and_add(Addend, Value); + short result = __sync_fetch_and_add(Addend, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5450,10 +5447,12 @@ inline LONG PALAPI InterlockedExchangeAdd( - IN OUT LONG volatile *Addend, + IN OUT LONG volatile* Addend, IN LONG Value) { - return __sync_fetch_and_add(Addend, Value); + LONG result = __sync_fetch_and_add(Addend, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5474,10 +5473,12 @@ inline LONGLONG PALAPI InterlockedExchangeAdd64( - IN OUT LONGLONG volatile *Addend, + IN OUT LONGLONG volatile* Addend, IN LONGLONG Value) { - return __sync_fetch_and_add(Addend, Value); + LONGLONG result = __sync_fetch_and_add(Addend, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5489,7 +5490,9 @@ InterlockedAnd8( IN OUT char volatile *Destination, IN char Value) { - return __sync_fetch_and_and(Destination, Value); + char result = __sync_fetch_and_and(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5501,7 +5504,9 @@ InterlockedAnd16( IN OUT short volatile *Destination, IN short Value) { - return __sync_fetch_and_and(Destination, Value); + short result = __sync_fetch_and_and(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5510,10 +5515,12 @@ inline LONG PALAPI InterlockedAnd( - IN OUT LONG volatile *Destination, + IN OUT LONG volatile* Destination, IN LONG Value) { - return __sync_fetch_and_and(Destination, Value); + LONG result = __sync_fetch_and_and(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5525,7 +5532,9 @@ InterlockedAnd64( IN OUT LONGLONG volatile *Destination, IN LONGLONG Value) { - return __sync_fetch_and_and(Destination, Value); + LONGLONG result = __sync_fetch_and_and(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5537,7 +5546,9 @@ InterlockedOr8( IN OUT char volatile *Destination, IN char Value) { - return __sync_fetch_and_or(Destination, Value); + char result = __sync_fetch_and_or(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5549,7 +5560,9 @@ InterlockedOr16( IN OUT short volatile *Destination, IN short Value) { - return __sync_fetch_and_or(Destination, Value); + short result = __sync_fetch_and_or(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5558,10 +5571,12 @@ inline LONG PALAPI InterlockedOr( - IN OUT LONG volatile *Destination, + IN OUT LONG volatile* Destination, IN LONG Value) { - return __sync_fetch_and_or(Destination, Value); + LONG result = __sync_fetch_and_or(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5573,7 +5588,9 @@ InterlockedOr64( IN OUT LONGLONG volatile *Destination, IN LONGLONG Value) { - return __sync_fetch_and_or(Destination, Value); + LONGLONG result = __sync_fetch_and_or(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5585,7 +5602,9 @@ InterlockedXor8( IN OUT char volatile *Destination, IN char Value) { - return __sync_fetch_and_xor(Destination, Value); + char result = __sync_fetch_and_xor(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5597,7 +5616,9 @@ InterlockedXor16( IN OUT short volatile *Destination, IN short Value) { - return __sync_fetch_and_xor(Destination, Value); + short result = __sync_fetch_and_xor(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5609,7 +5630,9 @@ InterlockedXor( IN OUT LONG volatile *Destination, IN LONG Value) { - return __sync_fetch_and_xor(Destination, Value); + LONG result = __sync_fetch_and_xor(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } EXTERN_C @@ -5621,7 +5644,9 @@ InterlockedXor64( IN OUT LONGLONG volatile *Destination, IN LONGLONG Value) { - return __sync_fetch_and_xor(Destination, Value); + LONGLONG result = __sync_fetch_and_xor(Destination, Value); + PAL_ArmInterlockedOperationBarrier(); + return result; } #define BITS_IN_BYTE 8 diff --git a/pal/inc/pal_mstypes.h b/pal/inc/pal_mstypes.h index 620c033f542..d8d4a299661 100644 --- a/pal/inc/pal_mstypes.h +++ b/pal/inc/pal_mstypes.h @@ -83,10 +83,19 @@ extern "C" { #define __inline inline #endif +#ifndef __forceinline +#define __forceinline inline +#endif + #endif // !_MSC_VER #define PALIMPORT -#define PAL_NORETURN __attribute__((noreturn)) + +#ifdef _MSC_VER +#define PAL_NORETURN __declspec(noreturn) +#else +#define PAL_NORETURN __attribute__((noreturn)) +#endif #define PALAPI __stdcall #define PALAPIV __cdecl diff --git a/pal/src/debug/debug.cpp b/pal/src/debug/debug.cpp index a2f3ea1dfab..51a8ce3b56f 100644 --- a/pal/src/debug/debug.cpp +++ b/pal/src/debug/debug.cpp @@ -93,6 +93,8 @@ static const char PAL_OUTPUTDEBUGSTRING[] = "PAL_OUTPUTDEBUGSTRING"; static const char PAL_RUN_ON_DEBUG_BREAK[] = "PAL_RUN_ON_DEBUG_BREAK"; #endif // ENABLE_RUN_ON_DEBUG_BREAK +extern "C" { + /* ------------------- Static function prototypes ----------------------------*/ #if !HAVE_VM_READ && !HAVE_PROCFS_CTL && !HAVE_TTRACE @@ -116,8 +118,6 @@ DBGSetProcessAttached(CPalThread *pThread, HANDLE hProcess, BOOL bAttach); #endif // !HAVE_VM_READ && !HAVE_PROCFS_CTL -extern "C" { - /*++ Function: FlushInstructionCache diff --git a/pal/src/include/pal/context.h b/pal/src/include/pal/context.h index 907d1349217..2a6f952b7d2 100644 --- a/pal/src/include/pal/context.h +++ b/pal/src/include/pal/context.h @@ -397,7 +397,7 @@ inline static DWORD64 CONTEXTGetPC(LPCONTEXT pContext) #elif defined(_ARM64_) || defined(_ARM_) return pContext->Pc; #else -#error don't know how to get the program counter for this architecture +#error "don't know how to get the program counter for this architecture" #endif } @@ -410,7 +410,7 @@ inline static void CONTEXTSetPC(LPCONTEXT pContext, DWORD64 pc) #elif defined(_ARM64_) || defined(_ARM_) pContext->Pc = pc; #else -#error don't know how to set the program counter for this architecture +#error "don't know how to set the program counter for this architecture" #endif } diff --git a/pal/src/misc/bstr.cpp b/pal/src/misc/bstr.cpp index 5048377ab09..1d5ad141627 100644 --- a/pal/src/misc/bstr.cpp +++ b/pal/src/misc/bstr.cpp @@ -25,7 +25,10 @@ Module Name: #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0) #define FAILED(Status) ((HRESULT)(Status)<0) #define STDAPICALLTYPE __stdcall -#define NULL 0 +#ifdef NULL +#undef NULL +#endif +#define NULL 0 #define STDAPI_(type) EXTERN_C type STDAPICALLTYPE #include "pal_assert.h" diff --git a/pal/src/misc/random.cpp b/pal/src/misc/random.cpp index a5a3fc608ce..c6b39c53e85 100644 --- a/pal/src/misc/random.cpp +++ b/pal/src/misc/random.cpp @@ -91,7 +91,7 @@ static void GetRandom(unsigned int *result) noexcept } extern "C" -errno_t __cdecl rand_s(unsigned int* randomValue) noexcept +errno_t rand_s(unsigned int* randomValue) noexcept { if (randomValue == nullptr) return 1; diff --git a/pal/src/safecrt/memmove_s.c b/pal/src/safecrt/memmove_s.c index e2f1b3b2fca..adc037c32a4 100644 --- a/pal/src/safecrt/memmove_s.c +++ b/pal/src/safecrt/memmove_s.c @@ -18,26 +18,10 @@ * Return ENOMEM when there is no memory for buffer *******************************************************************************/ -// use stdlib instead of PAL defined malloc to avoid forced Wint-to-pointer warning -#include #include - -#ifndef _VALIDATE_RETURN_ERRCODE -#define _VALIDATE_RETURN_ERRCODE(c, e) \ - if (!(c)) return e -#endif - -#ifndef ENOMEM -#define ENOMEM 12 -#endif - -#ifndef EINVAL -#define EINVAL 22 -#endif - -#ifndef ERANGE -#define ERANGE 34 -#endif +#include +#include "internal_securecrt.h" +#include "mbusafecrt_internal.h" /* usage: see https://msdn.microsoft.com/en-us/library/8k35d1fx.aspx diff --git a/pal/src/safecrt/safecrt_output_s.c b/pal/src/safecrt/safecrt_output_s.c index f6cfec47fe4..1a5b445d238 100644 --- a/pal/src/safecrt/safecrt_output_s.c +++ b/pal/src/safecrt/safecrt_output_s.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "internal_securecrt.h" #include "mbusafecrt_internal.h" diff --git a/pal/src/safecrt/safecrt_woutput_s.c b/pal/src/safecrt/safecrt_woutput_s.c index b0de006a9a7..4f3d33d8dce 100644 --- a/pal/src/safecrt/safecrt_woutput_s.c +++ b/pal/src/safecrt/safecrt_woutput_s.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "internal_securecrt.h" #include "mbusafecrt_internal.h" diff --git a/pal/src/thread/context.cpp b/pal/src/thread/context.cpp index cbd53646f9e..7b5843bc178 100644 --- a/pal/src/thread/context.cpp +++ b/pal/src/thread/context.cpp @@ -147,7 +147,7 @@ typedef int __ptrace_request; ASSIGN_REG(X28) #else -#error Don't know how to assign registers on this architecture +#error "Don't know how to assign registers on this architecture" #endif #define ASSIGN_ALL_REGS \ From b88d68765a22251daa8324aa034b8d151b478ce5 Mon Sep 17 00:00:00 2001 From: Curtis Man Date: Mon, 15 Feb 2021 10:51:55 -0800 Subject: [PATCH 2/6] add back InterlockedIncrement16 --- pal/inc/pal.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pal/inc/pal.h b/pal/inc/pal.h index 7cb2d6b9721..c71b58e2220 100644 --- a/pal/inc/pal.h +++ b/pal/inc/pal.h @@ -5158,6 +5158,19 @@ InterlockedIncrement( return result; } +EXTERN_C +PALIMPORT +inline +LONGLONG +PALAPI +InterlockedIncrement16( + IN OUT SHORT volatile *lpAddend) +{ + SHORT result = __sync_add_and_fetch(lpAddend, (SHORT)1); + PAL_ArmInterlockedOperationBarrier(); + return result; +} + EXTERN_C PALIMPORT inline From f03288d9a0acc50ef8959c47e0d1b2528c2c5969 Mon Sep 17 00:00:00 2001 From: Curtis Man Date: Mon, 15 Feb 2021 11:14:55 -0800 Subject: [PATCH 3/6] copyright --- lib/Backend/JnHelperMethodList.h | 1 + lib/Common/Common/MathUtil.cpp | 1 + lib/Common/Common/MathUtil.h | 1 + lib/Common/Exceptions/Throw.h | 1 + lib/Parser/Hash.cpp | 1 + lib/Parser/Hash.h | 1 + lib/Parser/Parse.h | 1 + lib/Parser/Scan.h | 1 + lib/Runtime/Base/ScriptContext.h | 1 + lib/Runtime/Debug/TTSupport.h | 1 + lib/Runtime/Language/JavascriptExceptionOperators.cpp | 1 + lib/Runtime/Language/JavascriptExceptionOperators.h | 1 + lib/Runtime/Library/JSONScanner.h | 1 + lib/Runtime/Library/JavascriptError.cpp | 1 + lib/Runtime/Library/JavascriptError.h | 1 + lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h | 1 + lib/Runtime/Types/ArrayObject.h | 1 + lib/SCACore/SCAEngine.h | 1 + lib/WasmReader/WasmParseTree.h | 1 + 19 files changed, 19 insertions(+) diff --git a/lib/Backend/JnHelperMethodList.h b/lib/Backend/JnHelperMethodList.h index e91fc5d8357..6f7c729d116 100644 --- a/lib/Backend/JnHelperMethodList.h +++ b/lib/Backend/JnHelperMethodList.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft Corporation and contributors. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #ifndef HELPERCALL diff --git a/lib/Common/Common/MathUtil.cpp b/lib/Common/Common/MathUtil.cpp index 18b6f2b3455..b5039d5be1f 100644 --- a/lib/Common/Common/MathUtil.cpp +++ b/lib/Common/Common/MathUtil.cpp @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #include "CommonCommonPch.h" diff --git a/lib/Common/Common/MathUtil.h b/lib/Common/Common/MathUtil.h index d0b5b8e7731..75299016f3c 100644 --- a/lib/Common/Common/MathUtil.h +++ b/lib/Common/Common/MathUtil.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Common/Exceptions/Throw.h b/lib/Common/Exceptions/Throw.h index 67a65a87f87..1df460597fa 100644 --- a/lib/Common/Exceptions/Throw.h +++ b/lib/Common/Exceptions/Throw.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Parser/Hash.cpp b/lib/Parser/Hash.cpp index e6ce2739d2d..c791c0ef7a7 100644 --- a/lib/Parser/Hash.cpp +++ b/lib/Parser/Hash.cpp @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #include "ParserPch.h" diff --git a/lib/Parser/Hash.h b/lib/Parser/Hash.h index d00d7915390..c685263117a 100644 --- a/lib/Parser/Hash.h +++ b/lib/Parser/Hash.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Parser/Parse.h b/lib/Parser/Parse.h index 3e0c6894a5f..90cf37616d6 100644 --- a/lib/Parser/Parse.h +++ b/lib/Parser/Parse.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Parser/Scan.h b/lib/Parser/Scan.h index 2fa4b02a8ac..525818d1db5 100644 --- a/lib/Parser/Scan.h +++ b/lib/Parser/Scan.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Runtime/Base/ScriptContext.h b/lib/Runtime/Base/ScriptContext.h index a8a71b48d00..9be5609e0a5 100644 --- a/lib/Runtime/Base/ScriptContext.h +++ b/lib/Runtime/Base/ScriptContext.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Runtime/Debug/TTSupport.h b/lib/Runtime/Debug/TTSupport.h index dd33dcd2cad..65b1bfb7ef5 100644 --- a/lib/Runtime/Debug/TTSupport.h +++ b/lib/Runtime/Debug/TTSupport.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Runtime/Language/JavascriptExceptionOperators.cpp b/lib/Runtime/Language/JavascriptExceptionOperators.cpp index 063c47d6510..4e9a901dd6d 100644 --- a/lib/Runtime/Language/JavascriptExceptionOperators.cpp +++ b/lib/Runtime/Language/JavascriptExceptionOperators.cpp @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #include "RuntimeLanguagePch.h" diff --git a/lib/Runtime/Language/JavascriptExceptionOperators.h b/lib/Runtime/Language/JavascriptExceptionOperators.h index f5c3c93efea..40089a0db96 100644 --- a/lib/Runtime/Language/JavascriptExceptionOperators.h +++ b/lib/Runtime/Language/JavascriptExceptionOperators.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Runtime/Library/JSONScanner.h b/lib/Runtime/Library/JSONScanner.h index 40f4c3b7852..d4efca58c47 100644 --- a/lib/Runtime/Library/JSONScanner.h +++ b/lib/Runtime/Library/JSONScanner.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Runtime/Library/JavascriptError.cpp b/lib/Runtime/Library/JavascriptError.cpp index 736e2b80577..87d7389be51 100644 --- a/lib/Runtime/Library/JavascriptError.cpp +++ b/lib/Runtime/Library/JavascriptError.cpp @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #include "RuntimeLibraryPch.h" diff --git a/lib/Runtime/Library/JavascriptError.h b/lib/Runtime/Library/JavascriptError.h index 638ad3358e4..282932bff33 100644 --- a/lib/Runtime/Library/JavascriptError.h +++ b/lib/Runtime/Library/JavascriptError.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h b/lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h index cc07edb4d79..58d0e652637 100644 --- a/lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h +++ b/lib/Runtime/PlatformAgnostic/RuntimePlatformAgnosticPch.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/Runtime/Types/ArrayObject.h b/lib/Runtime/Types/ArrayObject.h index f0b07d97e0b..e714006a74a 100644 --- a/lib/Runtime/Types/ArrayObject.h +++ b/lib/Runtime/Types/ArrayObject.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once diff --git a/lib/SCACore/SCAEngine.h b/lib/SCACore/SCAEngine.h index ed600619a14..b233245e680 100644 --- a/lib/SCACore/SCAEngine.h +++ b/lib/SCACore/SCAEngine.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- diff --git a/lib/WasmReader/WasmParseTree.h b/lib/WasmReader/WasmParseTree.h index 41b508292de..2b34c2515b7 100644 --- a/lib/WasmReader/WasmParseTree.h +++ b/lib/WasmReader/WasmParseTree.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft Corporation and contributors. All rights reserved. +// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- From 73d5839d41b825907a3467babe0b1c2b5a49eda5 Mon Sep 17 00:00:00 2001 From: Curtis Man Date: Mon, 15 Feb 2021 11:23:50 -0800 Subject: [PATCH 4/6] Remove apple/openbsd version of memmove in PAL --- pal/src/safecrt/memmove_s.c | 81 ++++++++++++------------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/pal/src/safecrt/memmove_s.c b/pal/src/safecrt/memmove_s.c index adc037c32a4..24b4973e1fb 100644 --- a/pal/src/safecrt/memmove_s.c +++ b/pal/src/safecrt/memmove_s.c @@ -23,60 +23,31 @@ #include "internal_securecrt.h" #include "mbusafecrt_internal.h" -/* -usage: see https://msdn.microsoft.com/en-us/library/8k35d1fx.aspx - -notes: uses extra buffer in case the src/dst overlaps (osx/bsd) - -dest - Destination object. - -src - Source object. - -count - Number of bytes (memmove) to copy. -*/ -void* __cdecl memmove_xplat( - void * dst, - const void * src, - size_t count -) -{ -#if defined(__APPLE__) || defined(__FreeBSD__) - if (src <= dst && src + count > dst) - { - char *temp = (char*) malloc(count); - _VALIDATE_RETURN_ERRCODE(temp != NULL, NULL); - - memcpy(temp, src, count); - memcpy(dst, temp, count); - - free(temp); - return dst; - } -#endif - - return memmove(dst, src, count); -} - - -/* -usage: see https://msdn.microsoft.com/en-us/library/e2851we8.aspx - -dest - Destination object. - -sizeInBytes - Size of the destination buffer. - -src - Source object. +/*** +*memmove - Copy source buffer to destination buffer +* +*Purpose: +* memmove() copies a source memory buffer to a destination memory buffer. +* This routine recognize overlapping buffers to avoid propagation. +* +* For cases where propagation is not a problem, memcpy_s() can be used. +* +*Entry: +* void *dst = pointer to destination buffer +* size_t sizeInBytes = size in bytes of the destination buffer +* const void *src = pointer to source buffer +* size_t count = number of bytes to copy +* +*Exit: +* Returns 0 if everything is ok, else return the error code. +* +*Exceptions: +* Input parameters are validated. Refer to the validation section of the function. +* On error, the error code is returned. Nothing is written to the destination buffer. +* +*******************************************************************************/ -count - Number of bytes (memmove_s) or characters (wmemmove_s) to copy. -*/ -int __cdecl memmove_s( +errno_t __cdecl memmove_s( void * dst, size_t sizeInBytes, const void * src, @@ -94,6 +65,6 @@ int __cdecl memmove_s( _VALIDATE_RETURN_ERRCODE(src != NULL, EINVAL); _VALIDATE_RETURN_ERRCODE(sizeInBytes >= count, ERANGE); - void *ret_val = memmove_xplat(dst, src, count); - return ret_val != NULL ? 0 : ENOMEM; // memmove_xplat returns `NULL` only if ENOMEM + memmove(dst, src, count); + return 0; } From 6ba156de09886500af6a6e138c2ed242e7ce40c4 Mon Sep 17 00:00:00 2001 From: Curtis Man Date: Mon, 15 Feb 2021 13:34:52 -0800 Subject: [PATCH 5/6] remove memmove -> memmove_xplat #define --- pal/inc/pal.h | 1 - 1 file changed, 1 deletion(-) diff --git a/pal/inc/pal.h b/pal/inc/pal.h index c71b58e2220..029f40f181c 100644 --- a/pal/inc/pal.h +++ b/pal/inc/pal.h @@ -6159,7 +6159,6 @@ CoCreateGuid(OUT GUID * pguid); #define ungetc PAL_ungetc #define setvbuf PAL_setvbuf #define atol PAL_atol -#define memmove memmove_xplat #define mkstemp PAL_mkstemp #define rename PAL_rename #define unlink PAL_unlink From 8170bc75d948bad0c701d6b226fd620547cb83a3 Mon Sep 17 00:00:00 2001 From: Curtis Man Date: Mon, 15 Feb 2021 18:12:41 -0800 Subject: [PATCH 6/6] fix clz32 tests --- pal/inc/pal.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pal/inc/pal.h b/pal/inc/pal.h index 029f40f181c..fcef81092fd 100644 --- a/pal/inc/pal.h +++ b/pal/inc/pal.h @@ -5084,7 +5084,10 @@ BitScanReverse( // Unconditionally calling the intrinsic in this way allows the compiler to // emit branchless code for this function when possible (depending on how the // intrinsic is implemented for the target platform). - int lzcount = __builtin_clzl(qwMask); + + // NOTE: this is different from the dotnet CLR version, where they use __builtin_clzl + // instead of __builtin_clz but gets the wrong result for Math::Clz32 + int lzcount = __builtin_clz(qwMask); *Index = (DWORD)(31 - lzcount); return qwMask != 0; }