Changeset 268170 in webkit
- Timestamp:
- Oct 7, 2020, 9:18:58 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r268165 r268170 1 2020-10-07 Yusuke Suzuki <[email protected]> 2 3 [JSC] Restrict more ptr-tagging and avoid using OperationPtrTag for JIT code 4 https://bugs.webkit.org/show_bug.cgi?id=217460 5 6 Reviewed by Saam Barati. 7 8 This patch makes tagging / untagging pointer functions solid by using PtrTag in template parameter. 9 Later, we will introduce compile time behavior change for different kind of PtrTag so that we can insert OperationPtrTag validation 10 when tagging a function with OperationPtrTag. 11 12 We also found that FTL is tagging JIT code with OperationPtrTag wrongly. We should tag it with JITThunkPtrTag. 13 14 * assembler/AbstractMacroAssembler.h: 15 (JSC::AbstractMacroAssembler::getLinkerAddress): 16 * assembler/AssemblerBuffer.h: 17 (JSC::ARM64EHash::update): 18 (JSC::ARM64EHash::finalHash const): 19 * assembler/JITOperationList.cpp: 20 (JSC::addPointers): 21 * assembler/MacroAssemblerARM64.cpp: 22 (JSC::MacroAssembler::probe): 23 * assembler/MacroAssemblerCodeRef.h: 24 (JSC::MacroAssemblerCodePtr::MacroAssemblerCodePtr): 25 (JSC::MacroAssemblerCodePtr::createFromExecutableAddress): 26 * assembler/testmasm.cpp: 27 (JSC::testProbeModifiesProgramCounter): 28 * b3/air/testair.cpp: 29 * ftl/FTLOutput.h: 30 (JSC::FTL::Output::callWithoutSideEffects): 31 (JSC::FTL::Output::operation): 32 * ftl/FTLSlowPathCall.cpp: 33 (JSC::FTL::SlowPathCallContext::makeCall): 34 * jit/JITCode.cpp: 35 (JSC::JITCodeWithCodeRef::executableAddressAtOffset): 36 * jit/JITExceptions.cpp: 37 (JSC::genericUnwind): 38 * jit/JITOperations.cpp: 39 * jit/Repatch.cpp: 40 (JSC::readPutICCallTarget): 41 (JSC::ftlThunkAwareRepatchCall): 42 (JSC::tryCacheGetBy): 43 (JSC::tryCachePutByID): 44 * llint/LLIntData.cpp: 45 (JSC::LLInt::initialize): 46 * llint/LLIntPCRanges.h: 47 (JSC::LLInt::isLLIntPC): 48 * llint/LLIntSlowPaths.cpp: 49 (JSC::LLInt::setUpCall): 50 * llint/LLIntThunks.cpp: 51 (JSC::LLInt::generateThunkWithJumpTo): 52 * runtime/MachineContext.h: 53 (JSC::MachineContext::instructionPointer): 54 * runtime/NativeExecutable.cpp: 55 (JSC::NativeExecutable::finishCreation): 56 * runtime/PutPropertySlot.h: 57 (JSC::PutPropertySlot::setCustomValue): 58 (JSC::PutPropertySlot::setCustomAccessor): 59 (JSC::PutPropertySlot::customSetter const): 60 * wasm/WasmAirIRGenerator.cpp: 61 (JSC::Wasm::AirIRGenerator::emitCCall): 62 * wasm/WasmSlowPaths.cpp: 63 1 64 2020-10-07 Ross Kirsling <[email protected]> 2 65 -
trunk/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h
r266530 r268170 878 878 static void* getLinkerAddress(void* code, AssemblerLabel label) 879 879 { 880 return tagCodePtr (AssemblerType::getRelocatedAddress(code, label), tag);880 return tagCodePtr<tag>(AssemblerType::getRelocatedAddress(code, label)); 881 881 } 882 882 -
trunk/Source/JavaScriptCore/assembler/AssemblerBuffer.h
r262402 r268170 188 188 { 189 189 uint64_t input = value ^ m_hash; 190 uint64_t a = static_cast<uint32_t>(tagInt (input, static_cast<PtrTag>(0)) >> 39);191 uint64_t b = tagInt (input, static_cast<PtrTag>(0xb7e151628aed2a6a)) >> 23;190 uint64_t a = static_cast<uint32_t>(tagInt<static_cast<PtrTag>(0)>(input) >> 39); 191 uint64_t b = tagInt<static_cast<PtrTag>(0xb7e151628aed2a6a)>(input) >> 23; 192 192 m_hash = a ^ b; 193 193 } … … 195 195 { 196 196 uint64_t hash = m_hash; 197 uint64_t a = static_cast<uint32_t>(tagInt (hash, static_cast<PtrTag>(0xbf7158809cf4f3c7)) >> 39);198 uint64_t b = tagInt (hash, static_cast<PtrTag>(0x62e7160f38b4da56)) >> 23;197 uint64_t a = static_cast<uint32_t>(tagInt<static_cast<PtrTag>(0xbf7158809cf4f3c7)>(hash) >> 39); 198 uint64_t b = tagInt<static_cast<PtrTag>(0x62e7160f38b4da56)>(hash) >> 23; 199 199 return static_cast<uint32_t>(a ^ b); 200 200 } -
trunk/Source/JavaScriptCore/assembler/JITOperationList.cpp
r268013 r268170 49 49 void* codePtr = removeCodePtrTag(bitwise_cast<void*>(*current)); 50 50 if (codePtr) { 51 auto result = map.add(codePtr, tagCodePtr (codePtr, JSEntryPtrTag));51 auto result = map.add(codePtr, tagCodePtr<JSEntryPtrTag>(codePtr)); 52 52 ASSERT(result.isNewEntry); 53 53 } … … 56 56 void* codePtr = removeCodePtrTag(bitwise_cast<void*>(*current)); 57 57 if (codePtr) { 58 auto result = map.add(codePtr, tagCodePtr (codePtr, OperationPtrTag));58 auto result = map.add(codePtr, tagCodePtr<OperationPtrTag>(codePtr)); 59 59 ASSERT(result.isNewEntry); 60 60 } -
trunk/Source/JavaScriptCore/assembler/MacroAssemblerARM64.cpp
r267938 r268170 546 546 move(TrustedImmPtr(tagCFunction<JITProbeExecutorPtrTag>(Probe::executeProbe)), x28); 547 547 #if CPU(ARM64E) 548 ASSERT(isTaggedWith(function, JITProbePtrTag));548 assertIsTaggedWith<JITProbePtrTag>(function); 549 549 #endif 550 550 move(TrustedImmPtr(reinterpret_cast<void*>(function)), x24); -
trunk/Source/JavaScriptCore/assembler/MacroAssemblerCodeRef.h
r265142 r268170 279 279 #endif 280 280 { 281 assertIsTaggedWith (value, tag);281 assertIsTaggedWith<tag>(value); 282 282 ASSERT(value); 283 283 #if CPU(ARM_THUMB2) … … 291 291 ASSERT(value); 292 292 ASSERT_VALID_CODE_POINTER(value); 293 assertIsTaggedWith (value, tag);293 assertIsTaggedWith<tag>(value); 294 294 MacroAssemblerCodePtr result; 295 295 result.m_value = value; -
trunk/Source/JavaScriptCore/assembler/testmasm.cpp
r265186 r268170 2124 2124 jit.probe([&] (Probe::Context& context) { 2125 2125 probeCallCount++; 2126 context.cpu.pc() = untagCodePtr (continuation.code().executableAddress(), JSEntryPtrTag);2126 context.cpu.pc() = untagCodePtr<JSEntryPtrTag>(continuation.code().executableAddress()); 2127 2127 }); 2128 2128 -
trunk/Source/JavaScriptCore/b3/air/testair.cpp
r263635 r268170 100 100 T invoke(const B3::Compilation& code, Arguments... arguments) 101 101 { 102 void* executableAddress = untagCFunctionPtr (code.code().executableAddress(), B3CompilationPtrTag);102 void* executableAddress = untagCFunctionPtr<B3CompilationPtrTag>(code.code().executableAddress()); 103 103 T (*function)(Arguments...) = bitwise_cast<T(*)(Arguments...)>(executableAddress); 104 104 return function(arguments...); -
trunk/Source/JavaScriptCore/ftl/FTLOutput.h
r267783 r268170 396 396 static_assert(!std::is_same<Function, LValue>::value); 397 397 return m_block->appendNew<B3::CCallValue>(m_proc, type, origin(), B3::Effects::none(), 398 constIntPtr(tagCFunctionPtr<void* >(function, OperationPtrTag)), arg1, args...);398 constIntPtr(tagCFunctionPtr<void*, OperationPtrTag>(function)), arg1, args...); 399 399 } 400 400 … … 402 402 // https://bugs.webkit.org/show_bug.cgi?id=184324 403 403 template<typename FunctionType> 404 LValue operation(FunctionType function) { return constIntPtr(tagCFunctionPtr<void* >(function, OperationPtrTag)); }404 LValue operation(FunctionType function) { return constIntPtr(tagCFunctionPtr<void*, OperationPtrTag>(function)); } 405 405 406 406 void jump(LBasicBlock); -
trunk/Source/JavaScriptCore/ftl/FTLSlowPathCall.cpp
r262920 r268170 121 121 { 122 122 SlowPathCallKey key = keyWithTarget(callTarget); 123 SlowPathCall result = SlowPathCall(m_jit.call( OperationPtrTag), key);123 SlowPathCall result = SlowPathCall(m_jit.call(JITThunkPtrTag), key); 124 124 125 125 m_jit.addLinkTask( … … 128 128 vm.ftlThunks->getSlowPathCallThunk(vm, result.key()); 129 129 130 linkBuffer.link(result.call(), CodeLocationLabel< OperationPtrTag>(thunk.retaggedCode<OperationPtrTag>()));130 linkBuffer.link(result.call(), CodeLocationLabel<JITThunkPtrTag>(thunk.code())); 131 131 }); 132 132 -
trunk/Source/JavaScriptCore/jit/JITCode.cpp
r261755 r268170 117 117 { 118 118 RELEASE_ASSERT(m_ref); 119 assertIsTaggedWith (m_ref.code().executableAddress(), JSEntryPtrTag);119 assertIsTaggedWith<JSEntryPtrTag>(m_ref.code().executableAddress()); 120 120 if (!offset) 121 121 return m_ref.code().executableAddress(); -
trunk/Source/JavaScriptCore/jit/JITExceptions.cpp
r268077 r268170 83 83 ASSERT(bitwise_cast<uintptr_t>(callFrame) < bitwise_cast<uintptr_t>(vm.topEntryFrame)); 84 84 85 assertIsTaggedWith (catchRoutine, ExceptionHandlerPtrTag);85 assertIsTaggedWith<ExceptionHandlerPtrTag>(catchRoutine); 86 86 vm.callFrameForCatch = callFrame; 87 87 vm.targetMachinePCForThrow = catchRoutine; -
trunk/Source/JavaScriptCore/jit/JITOperations.cpp
r267846 r268170 2624 2624 } 2625 2625 2626 assertIsTaggedWith (result, JSSwitchPtrTag);2626 assertIsTaggedWith<JSSwitchPtrTag>(result); 2627 2627 return reinterpret_cast<char*>(result); 2628 2628 } … … 2644 2644 else 2645 2645 result = jumpTable.ctiDefault.executableAddress(); 2646 assertIsTaggedWith (result, JSSwitchPtrTag);2646 assertIsTaggedWith<JSSwitchPtrTag>(result); 2647 2647 return reinterpret_cast<char*>(result); 2648 2648 } … … 2669 2669 result = jumpTable.ctiDefault.executableAddress(); 2670 2670 2671 assertIsTaggedWith (result, JSSwitchPtrTag);2671 assertIsTaggedWith<JSSwitchPtrTag>(result); 2672 2672 return reinterpret_cast<char*>(result); 2673 2673 } -
trunk/Source/JavaScriptCore/jit/Repatch.cpp
r267489 r268170 74 74 static FunctionPtr<CFunctionPtrTag> readPutICCallTarget(CodeBlock* codeBlock, CodeLocationCall<JSInternalPtrTag> call) 75 75 { 76 FunctionPtr<OperationPtrTag> target = MacroAssembler::readCallTarget<OperationPtrTag>(call);77 76 #if ENABLE(FTL_JIT) 78 77 if (codeBlock->jitType() == JITType::FTLJIT) { 79 MacroAssemblerCodePtr<JITThunkPtrTag> thunk = MacroAssemblerCodePtr<OperationPtrTag>::createFromExecutableAddress(target.executableAddress()).retagged<JITThunkPtrTag>(); 78 FunctionPtr<JITThunkPtrTag> target = MacroAssembler::readCallTarget<JITThunkPtrTag>(call); 79 MacroAssemblerCodePtr<JITThunkPtrTag> thunk = MacroAssemblerCodePtr<JITThunkPtrTag>::createFromExecutableAddress(target.executableAddress()); 80 80 return codeBlock->vm().ftlThunks->keyForSlowPathCallThunk(thunk).callTarget().retagged<CFunctionPtrTag>(); 81 81 } … … 83 83 UNUSED_PARAM(codeBlock); 84 84 #endif // ENABLE(FTL_JIT) 85 FunctionPtr<OperationPtrTag> target = MacroAssembler::readCallTarget<OperationPtrTag>(call); 85 86 return target.retagged<CFunctionPtrTag>(); 86 87 } … … 92 93 VM& vm = codeBlock->vm(); 93 94 FTL::Thunks& thunks = *vm.ftlThunks; 94 FunctionPtr< OperationPtrTag> target = MacroAssembler::readCallTarget<OperationPtrTag>(call);95 auto slowPathThunk = MacroAssemblerCodePtr<JITThunkPtrTag>::createFromExecutableAddress(target. retaggedExecutableAddress<JITThunkPtrTag>());95 FunctionPtr<JITThunkPtrTag> target = MacroAssembler::readCallTarget<JITThunkPtrTag>(call); 96 auto slowPathThunk = MacroAssemblerCodePtr<JITThunkPtrTag>::createFromExecutableAddress(target.executableAddress()); 96 97 FTL::SlowPathCallKey key = thunks.keyForSlowPathCallThunk(slowPathThunk); 97 98 key = key.withCallTarget(newCalleeFunction); … … 406 407 newCase = GetterSetterAccessCase::create( 407 408 vm, codeBlock, type, propertyName, offset, structure, conditionSet, loadTargetFromProxy, 408 slot.watchpointSet(), slot.isCacheableCustom() ? slot.customGetter() : nullptr,409 slot.watchpointSet(), slot.isCacheableCustom() ? FunctionPtr<OperationPtrTag>(slot.customGetter()) : nullptr, 409 410 slot.isCacheableCustom() && slot.slotBase() != baseValue ? slot.slotBase() : nullptr, 410 411 domAttribute, WTFMove(prototypeAccessChain)); … … 742 743 newCase = GetterSetterAccessCase::create( 743 744 vm, codeBlock, slot.isCustomAccessor() ? AccessCase::CustomAccessorSetter : AccessCase::CustomValueSetter, oldStructure, propertyName, 744 invalidOffset, conditionSet, WTFMove(prototypeAccessChain), isProxy, slot.customSetter() , slot.base() != baseValue ? slot.base() : nullptr);745 invalidOffset, conditionSet, WTFMove(prototypeAccessChain), isProxy, slot.customSetter().retagged<OperationPtrTag>(), slot.base() != baseValue ? slot.base() : nullptr); 745 746 } else { 746 747 ASSERT(slot.isCacheableSetter()); -
trunk/Source/JavaScriptCore/llint/LLIntData.cpp
r267371 r268170 63 63 64 64 for (int i = 0; i < numOpcodeIDs + numWasmOpcodeIDs; ++i) { 65 g_jscConfig.llint.opcodeMap[i] = tagCodePtr (g_jscConfig.llint.opcodeMap[i], BytecodePtrTag);66 g_jscConfig.llint.opcodeMapWide16[i] = tagCodePtr (g_jscConfig.llint.opcodeMapWide16[i], BytecodePtrTag);67 g_jscConfig.llint.opcodeMapWide32[i] = tagCodePtr (g_jscConfig.llint.opcodeMapWide32[i], BytecodePtrTag);65 g_jscConfig.llint.opcodeMap[i] = tagCodePtr<BytecodePtrTag>(g_jscConfig.llint.opcodeMap[i]); 66 g_jscConfig.llint.opcodeMapWide16[i] = tagCodePtr<BytecodePtrTag>(g_jscConfig.llint.opcodeMapWide16[i]); 67 g_jscConfig.llint.opcodeMapWide32[i] = tagCodePtr<BytecodePtrTag>(g_jscConfig.llint.opcodeMapWide32[i]); 68 68 } 69 69 -
trunk/Source/JavaScriptCore/llint/LLIntPCRanges.h
r251263 r268170 41 41 { 42 42 uintptr_t pcAsInt = bitwise_cast<uintptr_t>(pc); 43 uintptr_t llintStart = untagCodePtr<uintptr_t >(llintPCRangeStart, CFunctionPtrTag);44 uintptr_t llintEnd = untagCodePtr<uintptr_t >(llintPCRangeEnd, CFunctionPtrTag);43 uintptr_t llintStart = untagCodePtr<uintptr_t, CFunctionPtrTag>(llintPCRangeStart); 44 uintptr_t llintEnd = untagCodePtr<uintptr_t, CFunctionPtrTag>(llintPCRangeEnd); 45 45 RELEASE_ASSERT(llintStart < llintEnd); 46 46 return llintStart <= pcAsInt && pcAsInt <= llintEnd; -
trunk/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
r268077 r268170 156 156 157 157 #define LLINT_CALL_END_IMPL(callFrame, callTarget, callTargetTag) \ 158 LLINT_RETURN_TWO( retagCodePtr((callTarget), callTargetTag, SlowPathPtrTag), (callFrame))158 LLINT_RETURN_TWO((retagCodePtr<callTargetTag, SlowPathPtrTag>(callTarget)), (callFrame)) 159 159 160 160 #define LLINT_CALL_THROW(globalObject, exceptionToThrow) do { \ … … 1723 1723 } 1724 1724 1725 assertIsTaggedWith (codePtr.executableAddress(), JSEntryPtrTag);1725 assertIsTaggedWith<JSEntryPtrTag>(codePtr.executableAddress()); 1726 1726 LLINT_CALL_RETURN(globalObject, calleeFrame, codePtr.executableAddress(), JSEntryPtrTag); 1727 1727 } … … 1766 1766 } 1767 1767 1768 assertIsTaggedWith (codePtr.executableAddress(), JSEntryPtrTag);1768 assertIsTaggedWith<JSEntryPtrTag>(codePtr.executableAddress()); 1769 1769 LLINT_CALL_RETURN(globalObject, calleeFrame, codePtr.executableAddress(), JSEntryPtrTag); 1770 1770 } -
trunk/Source/JavaScriptCore/llint/LLIntThunks.cpp
r268077 r268170 53 53 JSInterfaceJIT jit; 54 54 55 assertIsTaggedWith (target, JSEntryPtrTag);55 assertIsTaggedWith<JSEntryPtrTag>(target); 56 56 57 57 #if ENABLE(WEBASSEMBLY) -
trunk/Source/JavaScriptCore/runtime/JSCPtrTag.h
r267867 r268170 51 51 v(OSREntryPtrTag) \ 52 52 v(OSRExitPtrTag) \ 53 v(PutValuePtrTag) \ 53 54 v(SlowPathPtrTag) \ 54 55 v(WasmEntryPtrTag) \ -
trunk/Source/JavaScriptCore/runtime/MachineContext.h
r261546 r268170 458 458 if (!usesPointerTagging()) 459 459 return makeOptional(MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>(value)); 460 if (isTaggedWith (value, PlatformRegistersPCPtrTag))460 if (isTaggedWith<PlatformRegistersPCPtrTag>(value)) 461 461 return makeOptional(MacroAssemblerCodePtr<PlatformRegistersPCPtrTag>(value)); 462 462 return WTF::nullopt; -
trunk/Source/JavaScriptCore/runtime/NativeExecutable.cpp
r267239 r268170 61 61 m_name = name; 62 62 63 assertIsTaggedWith (m_jitCodeForCall->addressForCall(ArityCheckNotRequired).executableAddress(), JSEntryPtrTag);64 assertIsTaggedWith (m_jitCodeForConstruct->addressForCall(ArityCheckNotRequired).executableAddress(), JSEntryPtrTag);65 assertIsTaggedWith (m_jitCodeForCallWithArityCheck.executableAddress(), JSEntryPtrTag);66 assertIsTaggedWith (m_jitCodeForConstructWithArityCheck.executableAddress(), JSEntryPtrTag);63 assertIsTaggedWith<JSEntryPtrTag>(m_jitCodeForCall->addressForCall(ArityCheckNotRequired).executableAddress()); 64 assertIsTaggedWith<JSEntryPtrTag>(m_jitCodeForConstruct->addressForCall(ArityCheckNotRequired).executableAddress()); 65 assertIsTaggedWith<JSEntryPtrTag>(m_jitCodeForCallWithArityCheck.executableAddress()); 66 assertIsTaggedWith<JSEntryPtrTag>(m_jitCodeForConstructWithArityCheck.executableAddress()); 67 67 } 68 68 -
trunk/Source/JavaScriptCore/runtime/PutPropertySlot.h
r267163 r268170 67 67 } 68 68 69 void setCustomValue(JSObject* base, FunctionPtr<OperationPtrTag>function)69 void setCustomValue(JSObject* base, PutValueFunc function) 70 70 { 71 71 m_type = CustomValue; … … 74 74 } 75 75 76 void setCustomAccessor(JSObject* base, FunctionPtr<OperationPtrTag>function)76 void setCustomAccessor(JSObject* base, PutValueFunc function) 77 77 { 78 78 m_type = CustomAccessor; … … 98 98 } 99 99 100 FunctionPtr< OperationPtrTag> customSetter() const100 FunctionPtr<PutValuePtrTag> customSetter() const 101 101 { 102 102 ASSERT(isCacheableCustom()); … … 138 138 uint8_t m_context; 139 139 CacheabilityType m_cacheability; 140 FunctionPtr< OperationPtrTag> m_putFunction;140 FunctionPtr<PutValuePtrTag> m_putFunction; 141 141 }; 142 142 -
trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp
r267783 r268170 599 599 600 600 Tmp callee = g64(); 601 append(block, Move, Arg::immPtr(tagCFunctionPtr<void* >(func, OperationPtrTag)), callee);601 append(block, Move, Arg::immPtr(tagCFunctionPtr<void*, OperationPtrTag>(func)), callee); 602 602 inst.args.append(callee); 603 603 -
trunk/Source/JavaScriptCore/wasm/WasmSlowPaths.cpp
r263117 r268170 65 65 66 66 #define WASM_CALL_RETURN(targetInstance, callTarget, callTargetTag) do { \ 67 WASM_RETURN_TWO( retagCodePtr(callTarget, callTargetTag, SlowPathPtrTag), targetInstance); \67 WASM_RETURN_TWO((retagCodePtr<callTargetTag, SlowPathPtrTag>(callTarget)), targetInstance); \ 68 68 } while (false) 69 69 -
trunk/Source/WTF/ChangeLog
r268163 r268170 1 2020-10-07 Yusuke Suzuki <[email protected]> 2 3 [JSC] Restrict more ptr-tagging and avoid using OperationPtrTag for JIT code 4 https://bugs.webkit.org/show_bug.cgi?id=217460 5 6 Reviewed by Saam Barati. 7 8 * wtf/PlatformRegisters.cpp: 9 (WTF::threadStateLRInternal): 10 (WTF::threadStatePCInternal): 11 * wtf/PtrTag.h: 12 (WTF::tagCFunctionPtr): 13 (WTF::tagCFunction): 14 (WTF::untagCFunctionPtr): 15 (WTF::tagInt): 16 (WTF::isTaggedWith): 17 (WTF::assertIsTaggedWith): 18 (WTF::assertIsNullOrTaggedWith): 19 1 20 2020-10-07 Keith Rollin <[email protected]> 2 21 -
trunk/Source/WTF/wtf/PlatformRegisters.cpp
r243254 r268170 40 40 41 41 #if USE(UNTAGGED_THREAD_STATE_PTR) 42 if (candidateLR && isTaggedWith (candidateLR, CFunctionPtrTag))42 if (candidateLR && isTaggedWith<CFunctionPtrTag>(candidateLR)) 43 43 return retagCodePtr<CFunctionPtrTag, PlatformRegistersLRPtrTag>(candidateLR); 44 44 candidateLR = bitwise_cast<void*>(arm_thread_state64_get_lr(regs)); … … 57 57 58 58 #if USE(UNTAGGED_THREAD_STATE_PTR) 59 if (candidatePC && isTaggedWith (candidatePC, CFunctionPtrTag))59 if (candidatePC && isTaggedWith<CFunctionPtrTag>(candidatePC)) 60 60 return retagCodePtr<CFunctionPtrTag, PlatformRegistersPCPtrTag>(candidatePC); 61 61 candidatePC = bitwise_cast<void*>(arm_thread_state64_get_pc(regs)); -
trunk/Source/WTF/wtf/PtrTag.h
r266406 r268170 194 194 } 195 195 196 template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>>197 inline T tagCodePtr(PtrType ptr, PtrTag tag)198 {199 return bitwise_cast<T>(tagCodePtrImpl<PtrTagAction::DebugAssert>(ptr, tag));200 }201 202 196 template<typename T, PtrTag tag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 203 197 inline T tagCodePtr(PtrType ptr) 204 198 { 205 199 return bitwise_cast<T>(tagCodePtrImpl<PtrTagAction::DebugAssert>(ptr, tag)); 206 }207 208 template<typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>>209 inline PtrType tagCodePtr(PtrType ptr, PtrTag tag)210 {211 return tagCodePtrImpl<PtrTagAction::DebugAssert>(ptr, tag);212 200 } 213 201 … … 235 223 } 236 224 237 template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>>238 inline T untagCodePtr(PtrType ptr, PtrTag tag)239 {240 return bitwise_cast<T>(untagCodePtrImpl<PtrTagAction::DebugAssert>(ptr, tag));241 }242 243 225 template<typename T, PtrTag tag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 244 226 inline T untagCodePtr(PtrType ptr) 245 227 { 246 228 return bitwise_cast<T>(untagCodePtrImpl<PtrTagAction::DebugAssert>(ptr, tag)); 247 }248 249 template<typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>>250 inline PtrType untagCodePtr(PtrType ptr, PtrTag tag)251 {252 return untagCodePtrImpl<PtrTagAction::DebugAssert>(ptr, tag);253 229 } 254 230 … … 313 289 } 314 290 315 template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>>316 inline T tagCFunctionPtr(PtrType ptr, PtrTag tag)317 {318 return bitwise_cast<T>(tagCFunctionPtrImpl<PtrTagAction::DebugAssert>(ptr, tag));319 }320 321 291 template<typename T, PtrTag tag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 322 292 inline T tagCFunctionPtr(PtrType ptr) … … 325 295 } 326 296 327 template<typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>>328 inline PtrType tagCFunctionPtr(PtrType ptr, PtrTag tag)329 {330 return tagCFunctionPtrImpl<PtrTagAction::DebugAssert>(ptr, tag);331 }332 333 297 template<PtrTag tag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 334 inline PtrType tagCFunctionPtr(PtrType ptr) { return tagCFunctionPtr (ptr, tag); }298 inline PtrType tagCFunctionPtr(PtrType ptr) { return tagCFunctionPtrImpl<PtrTagAction::DebugAssert>(ptr, tag); } 335 299 336 300 template<PtrTag newTag, typename FunctionType, class = typename std::enable_if<std::is_pointer<FunctionType>::value && std::is_function<typename std::remove_pointer<FunctionType>::type>::value>::type> 337 301 inline FunctionType tagCFunction(FunctionType func) 338 302 { 339 ASSERT(isTaggedWith(func, CFunctionPtrTag));303 assertIsTaggedWith<CFunctionPtrTag>(func); 340 304 ASSERT(newTag != CFunctionPtrTag); 341 305 return ptrauth_auth_and_resign(func, ptrauth_key_function_pointer, 0, ptrauth_key_process_dependent_code, newTag); … … 357 321 } 358 322 359 template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>>360 inline T untagCFunctionPtr(PtrType ptr, PtrTag tag)361 {362 return bitwise_cast<T>(untagCFunctionPtrImpl<PtrTagAction::DebugAssert>(ptr, tag));363 }364 365 323 template<typename T, PtrTag tag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 366 324 inline T untagCFunctionPtr(PtrType ptr) … … 375 333 } 376 334 377 template<typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>>378 inline PtrType untagCFunctionPtr(PtrType ptr, PtrTag tag)379 {380 return untagCFunctionPtrImpl<PtrTagAction::DebugAssert>(ptr, tag);381 }382 383 335 template<PtrTag tag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 384 inline PtrType untagCFunctionPtr(PtrType ptr) { return untagCFunctionPtr (ptr, tag); }385 386 template < typename IntType>387 inline IntType tagInt(IntType ptrInt , PtrTag tag)336 inline PtrType untagCFunctionPtr(PtrType ptr) { return untagCFunctionPtrImpl<PtrTagAction::DebugAssert>(ptr, tag); } 337 338 template <PtrTag tag, typename IntType> 339 inline IntType tagInt(IntType ptrInt) 388 340 { 389 341 static_assert(sizeof(IntType) == sizeof(uintptr_t), ""); … … 426 378 } 427 379 428 template< typename PtrType>429 bool isTaggedWith(PtrType value , PtrTag tag)380 template<PtrTag tag, typename PtrType> 381 bool isTaggedWith(PtrType value) 430 382 { 431 383 void* ptr = bitwise_cast<void*>(value); … … 435 387 } 436 388 437 template< typename PtrType>438 void assertIsTaggedWith(PtrType value , PtrTag tag)389 template<PtrTag tag, typename PtrType> 390 void assertIsTaggedWith(PtrType value) 439 391 { 440 392 WTF_PTRTAG_ASSERT(PtrTagAction::DebugAssert, value, tag, isTaggedWith(value, tag)); 441 393 } 442 394 443 template< typename PtrType>444 void assertIsNullOrTaggedWith(PtrType ptr , PtrTag tag)395 template<PtrTag tag, typename PtrType> 396 void assertIsNullOrTaggedWith(PtrType ptr) 445 397 { 446 398 if (ptr) 447 assertIsTaggedWith (ptr, tag);399 assertIsTaggedWith<tag>(ptr); 448 400 } 449 401 … … 495 447 496 448 497 template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>>498 constexpr T tagCodePtr(PtrType ptr, PtrTag) { return bitwise_cast<T>(ptr); }499 500 449 template<typename T, PtrTag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 501 450 inline T tagCodePtr(PtrType ptr) { return bitwise_cast<T>(ptr); } 502 451 503 template<typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>>504 constexpr PtrType tagCodePtr(PtrType ptr, PtrTag) { return ptr; }505 506 452 template<PtrTag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 507 453 inline PtrType tagCodePtr(PtrType ptr) { return ptr; } 508 454 509 template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>>510 constexpr T untagCodePtr(PtrType ptr, PtrTag) { return bitwise_cast<T>(ptr); }511 512 455 template<typename T, PtrTag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 513 456 inline T untagCodePtr(PtrType ptr) { return bitwise_cast<T>(ptr); } 514 457 515 template<typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>>516 constexpr PtrType untagCodePtr(PtrType ptr, PtrTag) { return ptr; }517 518 458 template<PtrTag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 519 459 inline PtrType untagCodePtr(PtrType ptr) { return ptr; } … … 537 477 constexpr PtrType removeCodePtrTag(PtrType ptr) { return ptr; } 538 478 539 template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>>540 inline T tagCFunctionPtr(PtrType ptr, PtrTag) { return bitwise_cast<T>(ptr); }541 542 479 template<typename T, PtrTag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 543 480 inline T tagCFunctionPtr(PtrType ptr) { return bitwise_cast<T>(ptr); } 544 481 545 template<typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>>546 inline PtrType tagCFunctionPtr(PtrType ptr, PtrTag) { return ptr; }547 548 482 template<PtrTag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 549 483 inline PtrType tagCFunctionPtr(PtrType ptr) { return ptr; } … … 558 492 } 559 493 560 template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>>561 inline T untagCFunctionPtr(PtrType ptr, PtrTag) { return bitwise_cast<T>(ptr); }562 563 494 template<typename T, PtrTag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 564 495 inline T untagCFunctionPtr(PtrType ptr) { return bitwise_cast<T>(ptr); } 565 496 566 template<typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>>567 inline PtrType untagCFunctionPtr(PtrType ptr, PtrTag) { return ptr; }568 569 497 template<PtrTag, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value>> 570 498 inline PtrType untagCFunctionPtr(PtrType ptr) { return ptr; } 571 499 572 template < typename IntType>573 inline IntType tagInt(IntType ptrInt , PtrTag)500 template <PtrTag, typename IntType> 501 inline IntType tagInt(IntType ptrInt) 574 502 { 575 503 static_assert(sizeof(IntType) == sizeof(uintptr_t), ""); … … 584 512 template<typename PtrType> void assertIsNullOrTagged(PtrType) { } 585 513 586 template< typename PtrType> bool isTaggedWith(PtrType, PtrTag) { return false; }587 588 template< typename PtrType> void assertIsTaggedWith(PtrType, PtrTag) { }589 template< typename PtrType> void assertIsNullOrTaggedWith(PtrType, PtrTag) { }514 template<PtrTag, typename PtrType> bool isTaggedWith(PtrType) { return false; } 515 516 template<PtrTag, typename PtrType> void assertIsTaggedWith(PtrType) { } 517 template<PtrTag, typename PtrType> void assertIsNullOrTaggedWith(PtrType) { } 590 518 591 519 inline bool usesPointerTagging() { return false; }
Note:
See TracChangeset
for help on using the changeset viewer.