dart-sdk/runtime/vm/code_patcher.cc
Régis Crelier a39833d957 Reland "Reland "[VM runtime] Dual mapping of executable pages.""
This is a reland of 6da340bf76

Original change's description:
> Reland "[VM runtime] Dual mapping of executable pages."
> 
> This is a reland of 44186dfdcd
> 
> 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>
2019-03-12 20:45:45 +00:00

59 lines
2 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/code_patcher.h"
#include "vm/cpu.h"
#include "vm/instructions.h"
#include "vm/object.h"
#include "vm/virtual_memory.h"
namespace dart {
DEFINE_FLAG(bool, write_protect_code, true, "Write protect jitted code");
#if defined(DUAL_MAPPING_SUPPORTED)
DEFINE_FLAG(bool, dual_map_code, true, "Dual map jitted code, RW and RX");
#else
DEFINE_FLAG(bool, dual_map_code, false, "Dual map jitted code, RW and RX");
#endif // defined(DUAL_MAPPING_SUPPORTED)
#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_DBC)
WritableInstructionsScope::WritableInstructionsScope(uword address,
intptr_t size)
: address_(address), size_(size) {
if (FLAG_write_protect_code) {
VirtualMemory::Protect(reinterpret_cast<void*>(address), size,
VirtualMemory::kReadWrite);
}
}
WritableInstructionsScope::~WritableInstructionsScope() {
if (FLAG_write_protect_code) {
VirtualMemory::Protect(reinterpret_cast<void*>(address_), size_,
VirtualMemory::kReadExecute);
}
}
#endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_DBC)
bool MatchesPattern(uword end, const int16_t* pattern, intptr_t size) {
// When breaking within generated code in GDB, it may overwrite individual
// instructions with trap instructions, which can cause this test to fail.
//
// Ignoring trap instructions would work well enough within GDB alone, but it
// doesn't work in RR, because the check for the trap instrution itself will
// cause replay to diverge from the original record.
if (FLAG_support_rr) return true;
uint8_t* bytes = reinterpret_cast<uint8_t*>(end - size);
for (intptr_t i = 0; i < size; i++) {
int16_t val = pattern[i];
if ((val >= 0) && (val != bytes[i])) {
return false;
}
}
return true;
}
} // namespace dart