2012-01-16 12:28:10 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// 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"
|
|
|
|
|
2012-01-16 12:28:10 +00:00
|
|
|
#include "platform/assert.h"
|
2012-01-16 13:23:40 +00:00
|
|
|
#include "platform/utils.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2014-02-10 12:18:06 +00:00
|
|
|
bool VirtualMemory::InSamePage(uword address0, uword address1) {
|
|
|
|
return (Utils::RoundDown(address0, PageSize()) ==
|
|
|
|
Utils::RoundDown(address1, PageSize()));
|
|
|
|
}
|
|
|
|
|
2019-01-31 21:01:48 +00:00
|
|
|
void VirtualMemory::Truncate(intptr_t new_size) {
|
|
|
|
ASSERT(Utils::IsAligned(new_size, PageSize()));
|
2011-10-05 05:20:07 +00:00
|
|
|
ASSERT(new_size <= size());
|
2019-03-12 20:45:45 +00:00
|
|
|
if (reserved_.size() ==
|
|
|
|
region_.size()) { // Don't create holes in reservation.
|
2021-02-22 19:58:49 +00:00
|
|
|
if (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);
|
|
|
|
}
|
2019-03-12 20:45:45 +00:00
|
|
|
}
|
2014-10-09 15:59:28 +00:00
|
|
|
}
|
2011-10-05 05:20:07 +00:00
|
|
|
region_.Subregion(region_, 0, new_size);
|
2019-03-12 20:45:45 +00:00
|
|
|
alias_.Subregion(alias_, 0, new_size);
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 17:53:06 +00:00
|
|
|
VirtualMemory* VirtualMemory::ForImagePage(void* pointer, uword size) {
|
2015-09-16 18:22:57 +00:00
|
|
|
// Memory for precompilated instructions was allocated by the embedder, so
|
|
|
|
// create a VirtualMemory without allocating.
|
|
|
|
MemoryRegion region(pointer, size);
|
2017-10-30 22:02:20 +00:00
|
|
|
MemoryRegion reserved(0, 0); // NULL reservation indicates VM should not
|
|
|
|
// attempt to free this memory.
|
2019-03-12 20:45:45 +00:00
|
|
|
VirtualMemory* memory = new VirtualMemory(region, region, reserved);
|
2017-10-30 22:02:20 +00:00
|
|
|
ASSERT(!memory->vm_owns_region());
|
2015-10-26 22:43:27 +00:00
|
|
|
return memory;
|
2015-09-16 18:22:57 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
} // namespace dart
|