|
1 | 1 | /* |
2 | | - * Copyright (C) 2008-2021 Apple Inc. All rights reserved. |
| 2 | + * Copyright (C) 2008-2022 Apple Inc. All rights reserved. |
3 | 3 | * |
4 | 4 | * Redistribution and use in source and binary forms, with or without |
5 | 5 | * modification, are permitted provided that the following conditions |
@@ -242,9 +242,8 @@ VM::VM(VMType vmType, HeapType heapType, WTF::RunLoop* runLoop, bool* success) |
242 | 242 | CRASH_WITH_INFO(0x4242424220202020, 0xbadbeef0badbeef, 0x1234123412341234, 0x1337133713371337); |
243 | 243 |
|
244 | 244 | interpreter = new Interpreter(*this); |
245 | | - StackBounds stack = Thread::current().stack(); |
246 | 245 | updateSoftReservedZoneSize(Options::softReservedZoneSize()); |
247 | | - setLastStackTop(stack.origin()); |
| 246 | + setLastStackTop(Thread::current()); |
248 | 247 |
|
249 | 248 | JSRunLoopTimer::Manager::shared().registerVM(*this); |
250 | 249 |
|
@@ -503,9 +502,11 @@ void VM::primitiveGigacageDisabled() |
503 | 502 | m_needToFirePrimitiveGigacageEnabled = true; |
504 | 503 | } |
505 | 504 |
|
506 | | -void VM::setLastStackTop(void* lastStackTop) |
507 | | -{ |
508 | | - m_lastStackTop = lastStackTop; |
| 505 | +void VM::setLastStackTop(const Thread& thread) |
| 506 | +{ |
| 507 | + m_lastStackTop = thread.savedLastStackTop(); |
| 508 | + auto& stack = thread.stack(); |
| 509 | + RELEASE_ASSERT(stack.contains(m_lastStackTop), 0x5510, m_lastStackTop, stack.origin(), stack.end()); |
509 | 510 | } |
510 | 511 |
|
511 | 512 | Ref<VM> VM::createContextGroup(HeapType heapType) |
@@ -1050,16 +1051,11 @@ void VM::popAllCheckpointOSRSideStateUntil(CallFrame* target) |
1050 | 1051 | m_checkpointSideState.shrinkToFit(); |
1051 | 1052 | } |
1052 | 1053 |
|
1053 | | -void logSanitizeStack(VM& vm) |
| 1054 | +static void logSanitizeStack(VM& vm) |
1054 | 1055 | { |
1055 | | - if (Options::verboseSanitizeStack() && vm.topCallFrame) { |
1056 | | - int dummy; |
| 1056 | + if (UNLIKELY(Options::verboseSanitizeStack())) { |
1057 | 1057 | auto& stackBounds = Thread::current().stack(); |
1058 | | - dataLog( |
1059 | | - "Sanitizing stack for VM = ", RawPointer(&vm), " with top call frame at ", RawPointer(vm.topCallFrame), |
1060 | | - ", current stack pointer at ", RawPointer(&dummy), ", in ", |
1061 | | - pointerDump(vm.topCallFrame->codeBlock()), ", last code origin = ", |
1062 | | - vm.topCallFrame->codeOrigin(), ", last stack top = ", RawPointer(vm.lastStackTop()), ", in stack range [", RawPointer(stackBounds.origin()), ", ", RawPointer(stackBounds.end()), "]\n"); |
| 1058 | + dataLogLn("Sanitizing stack for VM = ", RawPointer(&vm), ", current stack pointer at ", RawPointer(currentStackPointer()), ", last stack top = ", RawPointer(vm.lastStackTop()), ", in stack range (", RawPointer(stackBounds.end()), ", ", RawPointer(stackBounds.origin()), "]"); |
1063 | 1059 | } |
1064 | 1060 | } |
1065 | 1061 |
|
@@ -1270,17 +1266,20 @@ void QueuedTask::run() |
1270 | 1266 |
|
1271 | 1267 | void sanitizeStackForVM(VM& vm) |
1272 | 1268 | { |
| 1269 | + auto& thread = Thread::current(); |
| 1270 | + auto& stack = thread.stack(); |
| 1271 | + if (!vm.currentThreadIsHoldingAPILock()) |
| 1272 | + return; // vm.lastStackTop() may not be set up correctly if JSLock is not held. |
| 1273 | + |
1273 | 1274 | logSanitizeStack(vm); |
1274 | | - if (vm.topCallFrame) { |
1275 | | - auto& stackBounds = Thread::current().stack(); |
1276 | | - ASSERT(vm.currentThreadIsHoldingAPILock()); |
1277 | | - ASSERT_UNUSED(stackBounds, stackBounds.contains(vm.lastStackTop())); |
1278 | | - } |
| 1275 | + |
| 1276 | + RELEASE_ASSERT(stack.contains(vm.lastStackTop()), 0xaa10, vm.lastStackTop(), stack.origin(), stack.end()); |
1279 | 1277 | #if ENABLE(C_LOOP) |
1280 | 1278 | vm.interpreter->cloopStack().sanitizeStack(); |
1281 | 1279 | #else |
1282 | 1280 | sanitizeStackForVMImpl(&vm); |
1283 | 1281 | #endif |
| 1282 | + RELEASE_ASSERT(stack.contains(vm.lastStackTop()), 0xaa20, vm.lastStackTop(), stack.origin(), stack.end()); |
1284 | 1283 | } |
1285 | 1284 |
|
1286 | 1285 | size_t VM::committedStackByteCount() |
|
0 commit comments