OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Class for patching compiled code. | 4 // Class for patching compiled code. |
5 | 5 |
6 #ifndef VM_CODE_PATCHER_H_ | 6 #ifndef VM_CODE_PATCHER_H_ |
7 #define VM_CODE_PATCHER_H_ | 7 #define VM_CODE_PATCHER_H_ |
8 | 8 |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 | 10 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
13 // Forward declaration. | 13 // Forward declaration. |
14 class Array; | 14 class Array; |
15 class Code; | 15 class Code; |
16 class ExternalLabel; | 16 class ExternalLabel; |
17 class Function; | 17 class Function; |
18 class ICData; | 18 class ICData; |
19 class RawArray; | 19 class RawArray; |
| 20 class RawCode; |
20 class RawFunction; | 21 class RawFunction; |
21 class RawICData; | 22 class RawICData; |
22 class RawObject; | 23 class RawObject; |
23 class String; | 24 class String; |
24 | 25 |
25 | 26 |
26 // Stack-allocated class to create a scope where the specified region | 27 // Stack-allocated class to create a scope where the specified region |
27 // [address, addresss + size] has write access enabled. This is used | 28 // [address, addresss + size] has write access enabled. This is used |
28 // when patching generated code. Access is reset to read-execute in | 29 // when patching generated code. Access is reset to read-execute in |
29 // the destructor of this scope. | 30 // the destructor of this scope. |
30 class WritableInstructionsScope : public ValueObject { | 31 class WritableInstructionsScope : public ValueObject { |
31 public: | 32 public: |
32 WritableInstructionsScope(uword address, intptr_t size); | 33 WritableInstructionsScope(uword address, intptr_t size); |
33 ~WritableInstructionsScope(); | 34 ~WritableInstructionsScope(); |
34 | 35 |
35 private: | 36 private: |
36 const uword address_; | 37 const uword address_; |
37 const intptr_t size_; | 38 const intptr_t size_; |
38 }; | 39 }; |
39 | 40 |
40 | 41 |
41 class CodePatcher : public AllStatic { | 42 class CodePatcher : public AllStatic { |
42 public: | 43 public: |
43 // Dart static calls have a distinct, machine-dependent code pattern. | 44 // Dart static calls have a distinct, machine-dependent code pattern. |
44 | 45 |
45 // Patch static call before return_address in given code to the new target. | 46 // Patch static call before return_address in given code to the new target. |
46 static void PatchStaticCallAt(uword return_address, | 47 static void PatchStaticCallAt(uword return_address, |
47 const Code& code, | 48 const Code& code, |
48 uword new_target_address); | 49 const Code& new_target); |
49 | 50 |
50 // Patch instance call before return_address in given code to the new target. | 51 // Patch instance call before return_address in given code to the new target. |
51 static void PatchInstanceCallAt(uword return_address, | 52 static void PatchInstanceCallAt(uword return_address, |
52 const Code& code, | 53 const Code& code, |
53 uword new_target_address); | 54 const Code& new_target); |
54 | 55 |
55 // Patch entry point with a jump as specified in the code's patch region. | 56 // Patch entry point with a jump as specified in the code's patch region. |
56 static void PatchEntry(const Code& code); | 57 static void PatchEntry(const Code& code); |
57 | 58 |
58 // Restore entry point with original code (i.e., before patching). | 59 // Restore entry point with original code (i.e., before patching). |
59 static void RestoreEntry(const Code& code); | 60 static void RestoreEntry(const Code& code); |
60 | 61 |
61 // Has the entry been patched? | 62 // Has the entry been patched? |
62 static bool IsEntryPatched(const Code& code); | 63 static bool IsEntryPatched(const Code& code); |
63 | 64 |
64 // Returns true if the code can be patched with a jump at beginning (checks | 65 // Returns true if the code can be patched with a jump at beginning (checks |
65 // that there are no conflicts with object pointers). Used in ASSERTs. | 66 // that there are no conflicts with object pointers). Used in ASSERTs. |
66 static bool CodeIsPatchable(const Code& code); | 67 static bool CodeIsPatchable(const Code& code); |
67 | 68 |
68 // Return the target address of the static call before return_address | 69 // Return the target address of the static call before return_address |
69 // in given code. | 70 // in given code. |
70 static uword GetStaticCallTargetAt(uword return_address, const Code& code); | 71 static RawCode* GetStaticCallTargetAt(uword return_address, const Code& code); |
71 | 72 |
72 // Get instance call information. Returns the call target and sets each | 73 // Get instance call information. Returns the call target and sets each |
73 // of the output parameters ic_data and arguments_descriptor if they are | 74 // of the output parameters ic_data and arguments_descriptor if they are |
74 // non-NULL. | 75 // non-NULL. |
75 static uword GetInstanceCallAt(uword return_address, | 76 static RawCode* GetInstanceCallAt(uword return_address, |
76 const Code& code, | 77 const Code& code, |
77 ICData* ic_data); | 78 ICData* ic_data); |
78 | 79 |
79 // Return target of an unoptimized static call and its ICData object | 80 // Return target of an unoptimized static call and its ICData object |
80 // (calls target via a stub). | 81 // (calls target via a stub). |
81 static RawFunction* GetUnoptimizedStaticCallAt(uword return_address, | 82 static RawFunction* GetUnoptimizedStaticCallAt(uword return_address, |
82 const Code& code, | 83 const Code& code, |
83 ICData* ic_data); | 84 ICData* ic_data); |
84 | 85 |
85 static intptr_t InstanceCallSizeInBytes(); | 86 static intptr_t InstanceCallSizeInBytes(); |
86 | 87 |
87 static void InsertCallAt(uword start, uword target); | 88 static void InsertCallAt(uword start, uword target); |
88 | 89 |
89 static RawObject* GetEdgeCounterAt(uword pc, const Code& code); | 90 static RawObject* GetEdgeCounterAt(uword pc, const Code& code); |
90 | 91 |
91 static int32_t GetPoolOffsetAt(uword return_address); | 92 static int32_t GetPoolOffsetAt(uword return_address); |
92 static void SetPoolOffsetAt(uword return_address, int32_t offset); | 93 static void SetPoolOffsetAt(uword return_address, int32_t offset); |
93 static void PatchPoolPointerCallAt(uword return_address, | 94 static void PatchPoolPointerCallAt(uword return_address, |
94 const Code& code, | 95 const Code& code, |
95 uword new_target); | 96 const Code& new_target); |
96 }; | 97 }; |
97 | 98 |
98 } // namespace dart | 99 } // namespace dart |
99 | 100 |
100 #endif // VM_CODE_PATCHER_H_ | 101 #endif // VM_CODE_PATCHER_H_ |
OLD | NEW |