| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- #include "Backend.h"
- ThreadContextInfo::ThreadContextInfo(ThreadContextData * data) :
- m_threadContextData(*data),
- m_policyManager(true),
- m_pageAlloc(&m_policyManager, Js::Configuration::Global.flags, PageAllocatorType_BGJIT,
- AutoSystemInfo::Data.IsLowMemoryProcess() ?
- PageAllocator::DefaultLowMaxFreePageCount :
- PageAllocator::DefaultMaxFreePageCount),
- m_codeGenAlloc(&m_policyManager, nullptr, (HANDLE)data->processHandle),
- m_isAllJITCodeInPreReservedRegion(true),
- m_jitChakraBaseAddress((intptr_t)GetModuleHandle(L"Chakra.dll")), // TODO: OOP JIT, don't hardcode name
- m_jitCRTBaseAddress((intptr_t)GetModuleHandle(UCrtC99MathApis::LibraryName)),
- m_delayLoadWinCoreProcessThreads()
- {
- }
- intptr_t
- ThreadContextInfo::GetNullFrameDisplayAddr() const
- {
- return SHIFT_ADDR(this, &Js::NullFrameDisplay);
- }
- intptr_t
- ThreadContextInfo::GetStrictNullFrameDisplayAddr() const
- {
- return SHIFT_ADDR(this, &Js::StrictNullFrameDisplay);
- }
- intptr_t
- ThreadContextInfo::GetAbsDoubleCstAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::AbsDoubleCst);
- }
- intptr_t
- ThreadContextInfo::GetAbsFloatCstAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::AbsFloatCst);
- }
- intptr_t
- ThreadContextInfo::GetMaskNegFloatAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::MaskNegFloat);
- }
- intptr_t
- ThreadContextInfo::GetMaskNegDoubleAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::MaskNegDouble);
- }
- intptr_t
- ThreadContextInfo::GetUIntConvertConstAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::UIntConvertConst);
- }
- intptr_t
- ThreadContextInfo::GetUint8ClampedArraySetItemAddr() const
- {
- return SHIFT_ADDR(this, (BOOL(*)(Js::Uint8ClampedArray * arr, uint32 index, Js::Var value))&Js::Uint8ClampedArray::DirectSetItem);
- }
- intptr_t
- ThreadContextInfo::GetConstructorCacheDefaultInstanceAddr() const
- {
- return SHIFT_ADDR(this, &Js::ConstructorCache::DefaultInstance);
- }
- intptr_t
- ThreadContextInfo::GetJavascriptObjectNewInstanceAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptObject::EntryInfo::NewInstance);
- }
- intptr_t
- ThreadContextInfo::GetDoubleOnePointZeroAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::ONE_POINT_ZERO);
- }
- intptr_t
- ThreadContextInfo::GetDoublePointFiveAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_PointFive);
- }
- intptr_t
- ThreadContextInfo::GetFloatPointFiveAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_Float32PointFive);
- }
- intptr_t
- ThreadContextInfo::GetDoubleNegPointFiveAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_NegPointFive);
- }
- intptr_t
- ThreadContextInfo::GetFloatNegPointFiveAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_Float32NegPointFive);
- }
- intptr_t
- ThreadContextInfo::GetDoubleTwoToFractionAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_TwoToFraction);
- }
- intptr_t
- ThreadContextInfo::GetFloatTwoToFractionAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_Float32TwoToFraction);
- }
- intptr_t
- ThreadContextInfo::GetDoubleNegTwoToFractionAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_NegTwoToFraction);
- }
- intptr_t
- ThreadContextInfo::GetFloatNegTwoToFractionAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_Float32NegTwoToFraction);
- }
- intptr_t
- ThreadContextInfo::GetDoubleZeroAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_Zero);
- }
- intptr_t
- ThreadContextInfo::GetFloatZeroAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNumber::k_Float32Zero);
- }
- intptr_t
- ThreadContextInfo::GetNativeFloatArrayMissingItemAddr() const
- {
- return SHIFT_ADDR(this, &Js::JavascriptNativeFloatArray::MissingItem);
- }
- intptr_t
- ThreadContextInfo::GetThreadStackLimitAddr() const
- {
- return static_cast<intptr_t>(m_threadContextData.threadStackLimitAddr);
- }
- size_t
- ThreadContextInfo::GetScriptStackLimit() const
- {
- return static_cast<size_t>(m_threadContextData.scriptStackLimit);
- }
- bool
- ThreadContextInfo::IsThreadBound() const
- {
- return m_threadContextData.isThreadBound != FALSE;
- }
- PageAllocator *
- ThreadContextInfo::GetPageAllocator()
- {
- return &m_pageAlloc;
- }
- CodeGenAllocators *
- ThreadContextInfo::GetCodeGenAllocators()
- {
- return &m_codeGenAlloc;
- }
- AllocationPolicyManager *
- ThreadContextInfo::GetAllocationPolicyManager()
- {
- return &m_policyManager;
- }
- HANDLE
- ThreadContextInfo::GetProcessHandle() const
- {
- return reinterpret_cast<HANDLE>(m_threadContextData.processHandle);
- }
- bool
- ThreadContextInfo::IsAllJITCodeInPreReservedRegion() const
- {
- return m_isAllJITCodeInPreReservedRegion;
- }
- void
- ThreadContextInfo::ResetIsAllJITCodeInPreReservedRegion()
- {
- m_isAllJITCodeInPreReservedRegion = false;
- }
- intptr_t
- ThreadContextInfo::GetRuntimeChakraBaseAddress() const
- {
- return static_cast<intptr_t>(m_threadContextData.chakraBaseAddress);
- }
- intptr_t
- ThreadContextInfo::GetRuntimeCRTBaseAddress() const
- {
- return static_cast<intptr_t>(m_threadContextData.crtBaseAddress);
- }
- ptrdiff_t
- ThreadContextInfo::GetChakraBaseAddressDifference() const
- {
- return m_jitChakraBaseAddress - GetRuntimeChakraBaseAddress();
- }
- ptrdiff_t
- ThreadContextInfo::GetCRTBaseAddressDifference() const
- {
- return m_jitCRTBaseAddress - GetRuntimeCRTBaseAddress();
- }
- bool
- ThreadContextInfo::IsCFGEnabled()
- {
- #if defined(_CONTROL_FLOW_GUARD)
- PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY CfgPolicy;
- m_delayLoadWinCoreProcessThreads.EnsureFromSystemDirOnly();
- BOOL isGetMitigationPolicySucceeded = m_delayLoadWinCoreProcessThreads.GetMitigationPolicyForProcess(
- this->GetProcessHandle(),
- ProcessControlFlowGuardPolicy,
- &CfgPolicy,
- sizeof(CfgPolicy));
- Assert(isGetMitigationPolicySucceeded || !AutoSystemInfo::Data.IsCFGEnabled());
- return CfgPolicy.EnableControlFlowGuard && AutoSystemInfo::Data.IsCFGEnabled();
- #else
- return false;
- #endif
- }
|