97886e6dbf
Require the embedder to place a blob containing the FFI callback stub at pkg/lib/ffi_callback_stub.bin. All blobs in the package can be loaded as executable VMOs. Also reapply "Remove special case for simulator FFI callback thunks." TEST=ci Change-Id: I6ab4a73fc28fb750e45e67797b0bf9deee9d8b53 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495840 Reviewed-by: Liam Appelbe <liama@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "vm/virtual_memory.h"
|
|
|
|
#include "platform/assert.h"
|
|
#include "platform/utils.h"
|
|
|
|
namespace dart {
|
|
|
|
bool VirtualMemory::InSamePage(uword address0, uword address1) {
|
|
return (Utils::RoundDown(address0, PageSize()) ==
|
|
Utils::RoundDown(address1, PageSize()));
|
|
}
|
|
|
|
void VirtualMemory::Truncate(intptr_t new_size) {
|
|
ASSERT(Utils::IsAligned(new_size, PageSize()));
|
|
ASSERT(new_size <= size());
|
|
// We are not expected to call this with executable pages.
|
|
ASSERT(OffsetToExecutableAlias() == 0);
|
|
if (reserved_.size() ==
|
|
region_.size()) { // Don't create holes in reservation.
|
|
if (FreeSubSegment(reinterpret_cast<void*>(start() + new_size),
|
|
size() - new_size)) {
|
|
reserved_.set_size(new_size);
|
|
}
|
|
}
|
|
region_.Subregion(region_, 0, new_size);
|
|
}
|
|
|
|
VirtualMemory* VirtualMemory::ForImagePage(void* pointer, uword size) {
|
|
// Memory for precompilated instructions was allocated by the embedder, so
|
|
// create a VirtualMemory without allocating.
|
|
MemoryRegion region(pointer, size);
|
|
MemoryRegion reserved(nullptr, 0); // null reservation indicates VM should
|
|
// not attempt to free this memory.
|
|
VirtualMemory* memory = new VirtualMemory(region, reserved);
|
|
ASSERT(!memory->vm_owns_region());
|
|
return memory;
|
|
}
|
|
|
|
VirtualMemory* VirtualMemory::Adopt(void* pointer, uword size) {
|
|
MemoryRegion region(pointer, size);
|
|
VirtualMemory* memory = new VirtualMemory(region, region);
|
|
ASSERT(memory->vm_owns_region());
|
|
return memory;
|
|
}
|
|
|
|
} // namespace dart
|