// Copyright 2009 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
// static
Stack* Stack::New() { #ifdef V8_ENABLE_SANDBOX_HARDWARE_SUPPORT // TODO(426514762): Stack objects must currently be accessible to // sandboxed code (which is unsafe). As such we need to register them as // sandbox extension memory, which requires allocating them on full OS pages.
VirtualAddressSpace* vas = GetPlatformVirtualAddressSpace();
CHECK_LT(sizeof(Stack), vas->allocation_granularity());
Address regexp_stack_memory = vas->AllocatePages(
VirtualAddressSpace::kNoHint, vas->allocation_granularity(),
vas->allocation_granularity(), PagePermissions::kReadWrite);
SandboxHardwareSupport::RegisterUnsafeSandboxExtensionMemory(
regexp_stack_memory, vas->allocation_granularity()); returnnew (reinterpret_cast<void*>(regexp_stack_memory)) Stack(); #else returnnew Stack(); #endif// V8_ENABLE_SANDBOX_HARDWARE_SUPPORT
}
// static void Stack::Delete(Stack* instance) { #ifdef V8_ENABLE_SANDBOX_HARDWARE_SUPPORT // TODO(426514762): we currently allocate Stack objects on full pages.
instance->~Stack();
VirtualAddressSpace* vas = GetPlatformVirtualAddressSpace();
Address page = reinterpret_cast<Address>(instance);
DCHECK(IsAligned(page, vas->allocation_granularity()));
vas->FreePages(page, vas->allocation_granularity()); #else delete instance; #endif
}
char* Stack::ArchiveStack(char* to) { if (!thread_local_.owns_memory_) { // Force dynamic stacks prior to archiving. Any growth will do. A dynamic // stack is needed because stack archival & restoration rely on `memory_` // pointing at a fixed-location backing store, whereas the static stack is // tied to a Stack instance.
EnsureCapacity(thread_local_.memory_size_ + 1);
DCHECK(thread_local_.owns_memory_);
}
// This stack may not be used after being freed. Just reset to invalid values // to ensure we don't accidentally use old memory areas.
memory_ = nullptr;
memory_top_ = nullptr;
memory_size_ = 0;
stack_pointer_ = nullptr;
limit_ = kMemoryTop;
}
// static
uint8_t* Stack::ThreadLocal::NewDynamicStack(size_t size) { #ifdef V8_ENABLE_SANDBOX_HARDWARE_SUPPORT // Stack memory must be accessible to sandboxed code, so we must register it // as sandbox extension memory. As such, we need to allocate full OS pages. // TODO(426514762): determine if stack memory is always safe to be // corrupted by an attacker. If so, consider moving it into the sandbox. // TODO(426514762): if we're anyway switching this to full OS pages, would // there be a benefit from adding guard regions around the stack memory to // catch stack overflows and similar bugs?
VirtualAddressSpace* vas = GetPlatformVirtualAddressSpace();
size_t allocation_size = RoundUp(size, vas->allocation_granularity());
uint8_t* new_memory = reinterpret_cast<uint8_t*>(vas->AllocatePages(
VirtualAddressSpace::kNoHint, allocation_size,
vas->allocation_granularity(), PagePermissions::kReadWrite));
SandboxHardwareSupport::RegisterUnsafeSandboxExtensionMemory( reinterpret_cast<Address>(new_memory), allocation_size); #else
uint8_t* new_memory = NewArray<uint8_t>(size); #endif// V8_ENABLE_SANDBOX_HARDWARE_SUPPORT return new_memory;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.