Flutter Engine
The Flutter Engine
code_patcher.h
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// Class for patching compiled code.
5
6#ifndef RUNTIME_VM_CODE_PATCHER_H_
7#define RUNTIME_VM_CODE_PATCHER_H_
8
9#include "vm/allocation.h"
10#include "vm/native_entry.h"
11
12namespace dart {
13
14// Forward declaration.
15class Code;
16class ICData;
17
18#if defined(TARGET_ARCH_IA32)
19// Stack-allocated class to create a scope where the specified region
20// [address, address + size] has write access enabled. This is used
21// when patching generated code. Access is reset to read-execute in
22// the destructor of this scope.
23// Dual mapping of instructions pages is not supported on these target arch.
24class WritableInstructionsScope : public ValueObject {
25 public:
26 WritableInstructionsScope(uword address, intptr_t size);
27 ~WritableInstructionsScope();
28
29 private:
30 const uword address_;
31 const intptr_t size_;
32};
33#endif // defined(TARGET_ARCH_IA32)
34
35class CodePatcher : public AllStatic {
36 public:
37 // Dart static calls have a distinct, machine-dependent code pattern.
38
39 // Patch static call before return_address in given code to the new target.
40 static void PatchStaticCallAt(uword return_address,
41 const Code& code,
42 const Code& new_target);
43
44 // Return the target address of the static call before return_address
45 // in given code.
46 static CodePtr GetStaticCallTargetAt(uword return_address, const Code& code);
47
48 // Get instance call information. Returns the call target and sets the output
49 // parameter data if non-null.
50 static CodePtr GetInstanceCallAt(uword return_address,
51 const Code& caller_code,
52 Object* data);
53
54 // Change the state of an instance call by patching the corresponding object
55 // pool entries (non-IA32) or instructions (IA32).
56 static void PatchInstanceCallAt(uword return_address,
57 const Code& caller_code,
58 const Object& data,
59 const Code& target);
61 uword return_address,
62 const Code& caller_code,
63 const Object& data,
64 const Code& target);
65
66 // Return target of an unoptimized static call and its ICData object
67 // (calls target via a stub).
68 static FunctionPtr GetUnoptimizedStaticCallAt(uword return_address,
69 const Code& code,
70 ICData* ic_data);
71
73
74 static void PatchPoolPointerCallAt(uword return_address,
75 const Code& code,
76 const Code& new_target);
77
78 static void PatchSwitchableCallAt(uword return_address,
79 const Code& caller_code,
80 const Object& data,
81 const Code& target);
83 uword return_address,
84 const Code& caller_code,
85 const Object& data,
86 const Code& target);
88 const Code& caller_code);
90 const Code& caller_code);
91
92 static CodePtr GetNativeCallAt(uword return_address,
93 const Code& caller_code,
95
96 static void PatchNativeCallAt(uword return_address,
97 const Code& caller_code,
99 const Code& trampoline);
100
101 static intptr_t GetSubtypeTestCachePoolIndex(uword return_address);
102};
103
104// Beginning from [end - size] we compare [size] bytes with [pattern]. All
105// [0..255] values in [pattern] have to match, negative values are skipped.
106//
107// Example pattern: `[0x3d, 0x8b, -1, -1]`.
108bool MatchesPattern(uword end, const int16_t* pattern, intptr_t size);
109
110} // namespace dart
111
112#endif // RUNTIME_VM_CODE_PATCHER_H_
static void PatchInstanceCallAt(uword return_address, const Code &caller_code, const Object &data, const Code &target)
static void PatchPoolPointerCallAt(uword return_address, const Code &code, const Code &new_target)
static CodePtr GetStaticCallTargetAt(uword return_address, const Code &code)
static void PatchSwitchableCallAtWithMutatorsStopped(Thread *thread, uword return_address, const Code &caller_code, const Object &data, const Code &target)
static void PatchInstanceCallAtWithMutatorsStopped(Thread *thread, uword return_address, const Code &caller_code, const Object &data, const Code &target)
static void PatchSwitchableCallAt(uword return_address, const Code &caller_code, const Object &data, const Code &target)
static FunctionPtr GetUnoptimizedStaticCallAt(uword return_address, const Code &code, ICData *ic_data)
static uword GetSwitchableCallTargetEntryAt(uword return_address, const Code &caller_code)
static intptr_t GetSubtypeTestCachePoolIndex(uword return_address)
static ObjectPtr GetSwitchableCallDataAt(uword return_address, const Code &caller_code)
static void InsertDeoptimizationCallAt(uword start)
static CodePtr GetInstanceCallAt(uword return_address, const Code &caller_code, Object *data)
static CodePtr GetNativeCallAt(uword return_address, const Code &caller_code, NativeFunction *target)
static void PatchStaticCallAt(uword return_address, const Code &code, const Code &new_target)
static void PatchNativeCallAt(uword return_address, const Code &caller_code, NativeFunction target, const Code &trampoline)
uint32_t * target
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
static int8_t data[kExtLength]
void(* NativeFunction)(NativeArguments *arguments)
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