mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
![Régis Crelier](/assets/img/avatar_default.png)
This is a reland of6da340bf76
Original change's description: > Reland "[VM runtime] Dual mapping of executable pages." > > This is a reland of44186dfdcd
> > Original change's description: > > [VM runtime] Dual mapping of executable pages. > > > > Change-Id: Iaad78d324e25462ce951f4df26974a6a368c50b7 > > Reviewed-on: https://dart-review.googlesource.com/c/93377 > > Commit-Queue: Régis Crelier <regis@google.com> > > Reviewed-by: Ryan Macnak <rmacnak@google.com> > > Change-Id: I7a0caa078950637d9fe831732577fd2467061099 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95263 > Reviewed-by: Ryan Macnak <rmacnak@google.com> Change-Id: I3a01f0e67d733c5db41618f691431e72c1e1cb2e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96422 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Régis Crelier <regis@google.com>
46 lines
1.6 KiB
C++
46 lines
1.6 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());
|
|
if (reserved_.size() ==
|
|
region_.size()) { // Don't create holes in reservation.
|
|
FreeSubSegment(reinterpret_cast<void*>(start() + new_size),
|
|
size() - new_size);
|
|
reserved_.set_size(new_size);
|
|
if (AliasOffset() != 0) {
|
|
FreeSubSegment(reinterpret_cast<void*>(alias_.start() + new_size),
|
|
alias_.size() - new_size);
|
|
}
|
|
}
|
|
region_.Subregion(region_, 0, new_size);
|
|
alias_.Subregion(alias_, 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(0, 0); // NULL reservation indicates VM should not
|
|
// attempt to free this memory.
|
|
VirtualMemory* memory = new VirtualMemory(region, region, reserved);
|
|
ASSERT(!memory->vm_owns_region());
|
|
return memory;
|
|
}
|
|
|
|
} // namespace dart
|