Flutter Engine
The Flutter Engine
code_patcher.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/code_patcher.h"
6#include "vm/cpu.h"
7#include "vm/instructions.h"
8#include "vm/object.h"
9#include "vm/virtual_memory.h"
10
11namespace dart {
12
13#if defined(DART_HOST_OS_MACOS) || defined(DART_HOST_OS_MACOS_IOS)
14// On iOS even with debugger attached we must still guarantee that memory
15// is never executable and writable at the same time. On Mac OS X
16// com.apple.security.cs.allow-jit entitelement allows WX memory regions to be
17// created - but we should not rely on this entitelement to be present.
18static constexpr bool kShouldWriteProtectCodeByDefault = true;
19#else
20static constexpr bool kShouldWriteProtectCodeByDefault = false;
21#endif
22
24 write_protect_code,
26 "Write protect jitted code");
27
28#if defined(TARGET_ARCH_IA32)
29WritableInstructionsScope::WritableInstructionsScope(uword address,
30 intptr_t size)
31 : address_(address), size_(size) {
32 if (FLAG_write_protect_code) {
33 VirtualMemory::Protect(reinterpret_cast<void*>(address), size,
35 }
36}
37
38WritableInstructionsScope::~WritableInstructionsScope() {
39 if (FLAG_write_protect_code) {
40 VirtualMemory::Protect(reinterpret_cast<void*>(address_), size_,
41 VirtualMemory::kReadExecute);
42 }
43}
44#endif // defined(TARGET_ARCH_IA32)
45
46bool MatchesPattern(uword end, const int16_t* pattern, intptr_t size) {
47 // When breaking within generated code in GDB, it may overwrite individual
48 // instructions with trap instructions, which can cause this test to fail.
49 //
50 // Ignoring trap instructions would work well enough within GDB alone, but it
51 // doesn't work in RR, because the check for the trap instruction itself will
52 // cause replay to diverge from the original record.
53 if (FLAG_support_rr) return true;
54
55 uint8_t* bytes = reinterpret_cast<uint8_t*>(end - size);
56 for (intptr_t i = 0; i < size; i++) {
57 int16_t val = pattern[i];
58 if ((val >= 0) && (val != bytes[i])) {
59 return false;
60 }
61 }
62 return true;
63}
64
65} // namespace dart
static void Protect(void *address, intptr_t size, Protection mode)
glong glong end
Definition: dart_vm.cc:33
uintptr_t uword
Definition: globals.h:501
bool MatchesPattern(uword end, const int16_t *pattern, intptr_t size)
Definition: code_patcher.cc:46
DEFINE_FLAG(bool, print_cluster_information, false, "Print information about clusters written to snapshot")
static constexpr bool kShouldWriteProtectCodeByDefault
Definition: code_patcher.cc:20
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259