Commit 81c6be2e authored by Thibaud Michaud's avatar Thibaud Michaud Committed by V8 LUCI CQ

[wasm] Reserve space for runtime in wasm stacks

Set the JS limit at a 40KB offset from the actual limit, like on the
native stack. This is an estimate of the maximum stack space needed for
runtime calls.

R=ahaas@chromium.org

Bug: v8:12191
Change-Id: I709d5b25c5e47d2474cf4205ebcb8ee7fc8e794c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3312485Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78212}
parent 52755f35
...@@ -43,7 +43,7 @@ class StackMemory { ...@@ -43,7 +43,7 @@ class StackMemory {
if (owned_) allocator->DecommitPages(limit_, size_); if (owned_) allocator->DecommitPages(limit_, size_);
} }
void* limit() { return limit_; } void* jslimit() { return limit_ + kJSLimitOffsetKB; }
void* base() { return limit_ + size_; } void* base() { return limit_ + size_; }
// Track external memory usage for Managed<StackMemory> objects. // Track external memory usage for Managed<StackMemory> objects.
...@@ -53,15 +53,18 @@ class StackMemory { ...@@ -53,15 +53,18 @@ class StackMemory {
// This constructor allocates a new stack segment. // This constructor allocates a new stack segment.
StackMemory() : owned_(true) { StackMemory() : owned_(true) {
PageAllocator* allocator = GetPlatformPageAllocator(); PageAllocator* allocator = GetPlatformPageAllocator();
size_ = allocator->AllocatePageSize(); int kJsStackSizeKB = 4;
// TODO(thibaudm): Leave space for runtime functions. size_ = (kJsStackSizeKB + kJSLimitOffsetKB) * KB;
limit_ = static_cast<byte*>(allocator->AllocatePages( limit_ = static_cast<byte*>(
nullptr, size_, size_, PageAllocator::kReadWrite)); allocator->AllocatePages(nullptr, size_, allocator->AllocatePageSize(),
PageAllocator::kReadWrite));
} }
// Overload to represent a view of the libc stack. // Overload to represent a view of the libc stack.
explicit StackMemory(byte* limit) : limit_(limit), size_(0), owned_(false) {} explicit StackMemory(byte* limit) : limit_(limit), size_(0), owned_(false) {}
static constexpr int kJSLimitOffsetKB = 40;
byte* limit_; byte* limit_;
size_t size_; size_t size_;
bool owned_; bool owned_;
......
...@@ -1748,7 +1748,7 @@ Handle<WasmContinuationObject> WasmContinuationObject::New( ...@@ -1748,7 +1748,7 @@ Handle<WasmContinuationObject> WasmContinuationObject::New(
Handle<WasmContinuationObject> result = Handle<WasmContinuationObject>::cast( Handle<WasmContinuationObject> result = Handle<WasmContinuationObject>::cast(
isolate->factory()->NewStruct(WASM_CONTINUATION_OBJECT_TYPE)); isolate->factory()->NewStruct(WASM_CONTINUATION_OBJECT_TYPE));
auto jmpbuf = std::make_unique<wasm::JumpBuffer>(); auto jmpbuf = std::make_unique<wasm::JumpBuffer>();
jmpbuf->stack_limit = stack->limit(); jmpbuf->stack_limit = stack->jslimit();
jmpbuf->sp = stack->base(); jmpbuf->sp = stack->base();
result->set_jmpbuf( result->set_jmpbuf(
*isolate->factory()->NewForeign(reinterpret_cast<Address>(jmpbuf.get()))); *isolate->factory()->NewForeign(reinterpret_cast<Address>(jmpbuf.get())));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment