d6178535b2
Change executable pages to be read/execute but not writable by default. All pages are made temporarily writable just before a full GC, because both the mark and sweep phases write to the pages. When allocating in a page and when patching code, the pages are made temporarily writable. The order of allocation of Code and Instructions objects is changed so that a GC will not occur after Instructions is allocated. (A full GC would render the Instructions unwritable.) A scoped object is used to make memory protection simpler. Original CL: https://codereview.chromium.org/106593002/ I added a cc test that is expected to crash. R=srdjan@google.com Review URL: https://codereview.chromium.org//136563002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32493 260f80e4-7a28-3924-810f-c04153c831b5
50 lines
1.5 KiB
C++
50 lines
1.5 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()));
|
|
}
|
|
|
|
|
|
VirtualMemory* VirtualMemory::ReserveAligned(intptr_t size,
|
|
intptr_t alignment) {
|
|
ASSERT((size & (PageSize() - 1)) == 0);
|
|
ASSERT(Utils::IsPowerOfTwo(alignment));
|
|
ASSERT(alignment >= PageSize());
|
|
VirtualMemory* result = VirtualMemory::Reserve(size + alignment);
|
|
if (result == NULL) {
|
|
FATAL("Out of memory.\n");
|
|
}
|
|
uword start = result->start();
|
|
uword real_start = (start + alignment - 1) & ~(alignment - 1);
|
|
result->Truncate(real_start, size);
|
|
return result;
|
|
}
|
|
|
|
|
|
void VirtualMemory::Truncate(uword new_start, intptr_t new_size) {
|
|
ASSERT(new_start >= start());
|
|
ASSERT((new_size & (PageSize() - 1)) == 0);
|
|
if (new_start > start()) {
|
|
uword split = new_start - start();
|
|
ASSERT((split & (PageSize() - 1)) == 0);
|
|
FreeSubSegment(address(), split);
|
|
region_.Subregion(region_, split, size() - split);
|
|
}
|
|
ASSERT(new_size <= size());
|
|
FreeSubSegment(reinterpret_cast<void*>(start() + new_size),
|
|
size() - new_size);
|
|
region_.Subregion(region_, 0, new_size);
|
|
}
|
|
|
|
} // namespace dart
|