Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: tests/dynamic_code_loading/templates_x86.S

Issue 5738003: Resurrect Petr's 64-bit dynamic code modification CL:... (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: added test for double-break condition Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2010 The Native Client Authors. All rights reserved. 2 * Copyright 2010 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file. 4 * be found in the LICENSE file.
5 */ 5 */
6 6
7 .global template_func 7 .global template_func
8 .global template_func_end 8 .global template_func_end
9 template_func: 9 template_func:
10 #if defined(__i386__) 10 #if defined(__i386__)
11 movl $1234, %eax 11 movl $1234, %eax
12 popl %ecx 12 popl %ecx
13 nacljmp %ecx 13 and $0xffffffe0,%ecx
14 jmp *%ecx
15 call template_func
14 #elif defined(__x86_64__) 16 #elif defined(__x86_64__)
17 disp = template_func_end - 4
18 xorl %r11d, %r11d
19 movq disp(%r15,%r11,1), %rax
20 popq %r14
21 andl $0xffffffe0,%r14d
22 addq %r15,%r14
23 jmpq *%r14
24 call template_func
25 test $0xffffffff,%r11d
15 movq $1234, %rax 26 movq $1234, %rax
16 popq %r11
17 nacljmp %r11d, %r15
18 #else 27 #else
19 # error "Unsupported architecture" 28 # error "Unsupported architecture"
20 #endif 29 #endif
21 template_func_end: 30 template_func_end:
22 31
32
23 .global template_func_replacement 33 .global template_func_replacement
24 .global template_func_replacement_end 34 .global template_func_replacement_end
25 .p2align 5 35 .p2align 5
26 template_func_replacement: 36 template_func_replacement:
27 #if defined(__i386__) 37 #if defined(__i386__)
28 movl $4321, %eax 38 movl $4321, %eax /* replaces constant */
29 popl %ecx 39 popl %ecx
30 nacljmp %ecx 40 and $0xffffffe0,%ecx
41 jmp *%ecx
42 call (template_func_replacement - 32) /* replaces a call target, the
43 * new target is bundle aligned
44 * and target address outside
45 * modified section */
31 #elif defined(__x86_64__) 46 #elif defined(__x86_64__)
32 movq $4321, %rax 47 /* tests all modifications that are
33 popq %r11 48 * currently allowed by service runtime */
34 nacljmp %r11d, %r15 49 new_disp = template_func_replacement_end - 4
50 xorl %r11d, %r11d
51 movq new_disp(%r15,%r11,1), %rax /* replaces displacement */
52 popq %r14
53 andl $0xffffffe0,%r14d
54 addq %r15,%r14
55 jmpq *%r14
56 call (template_func_replacement - 32) /* replaces a call target, the
57 * new target is bundle aligned
58 * and target address outside
59 * modified section */
60 test $0xffffffff,%r11d
61 movq $4321, %rax /* replaces constant */
35 #else 62 #else
36 # error "Unsupported architecture" 63 # error "Unsupported architecture"
37 #endif 64 #endif
38 template_func_replacement_end: 65 template_func_replacement_end:
39 66
67
40 .global template_func_nonreplacement 68 .global template_func_nonreplacement
41 .global template_func_nonreplacement_end 69 .global template_func_nonreplacement_end
70 .global template_func_misaligned_replacement
71 .global template_func_misaligned_replacement_end
42 .p2align 5 72 .p2align 5
43 template_func_nonreplacement: 73 template_func_nonreplacement:
74 template_func_misaligned_replacement:
44 #if defined(__i386__) 75 #if defined(__i386__)
45 movl $4132, %eax 76 nop /* nop creates misalignment in
46 popl %edx 77 * replacing section which makes
47 nacljmp %edx 78 * it illegal */
79 movl $1234, %eax
80 popl %ecx
81 and $0xffffffe0,%ecx
82 jmp *%ecx
83 call template_func_misaligned_replacement
48 #elif defined(__x86_64__) 84 #elif defined(__x86_64__)
49 movq $4132, %rax 85 nop /* nop creates misalignment in
50 popq %r12 86 * replacing section which makes
51 nacljmp %r12d, %r15 87 * it illegal */
88 xorl %r11d, %r11d
89 movq disp(%r15,%r11,1), %rax
90 popq %r14
91 andl $0xffffffe0,%r14d
92 addq %r15,%r14
93 jmpq *%r14
94 call template_func_misaligned_replacement
95 test $0xffffffff,%r11d
96 movq $1234, %rax
52 #else 97 #else
53 # error "Unsupported architecture" 98 # error "Unsupported architecture"
54 #endif 99 #endif
100 template_func_misaligned_replacement_end:
55 template_func_nonreplacement_end: 101 template_func_nonreplacement_end:
56 102
57 103
58
59 .global hlts 104 .global hlts
60 .global hlts_end 105 .global hlts_end
61 .p2align 5 106 .p2align 5
62 hlts: 107 hlts:
63 .fill 32, 1, 0xf4 108 .fill 32, 1, 0xf4
64 hlts_end: 109 hlts_end:
65 110
66 111
67 .global branch_forwards 112 .global branch_forwards
68 .global branch_forwards_end 113 .global branch_forwards_end
69 .global branch_backwards 114 .global branch_backwards
70 .global branch_backwards_end 115 .global branch_backwards_end
71 .p2align 5 116 .p2align 5
72 branch_forwards: 117 branch_forwards:
73 jmp branch_backwards 118 jmp branch_backwards
74 /* The assembler generates a bad jmp if I use ".p2align 5" 119 /* The assembler generates a bad jmp if I use ".p2align 5"
75 instead of padding manually. TODO(mseaborn): Investigate. */ 120 instead of padding manually. TODO(mseaborn): Investigate. */
76 .fill 32 - 5, 1, 0x90 121 .fill 32 - 5, 1, 0x90
77 branch_forwards_end: 122 branch_forwards_end:
78 branch_backwards: 123 branch_backwards:
79 jmp branch_forwards 124 jmp branch_forwards
80 /* The assembler generates a bad jmp if I use ".p2align 5" 125 /* The assembler generates a bad jmp if I use ".p2align 5"
81 instead of padding manually. */ 126 instead of padding manually. */
82 .fill 32 - 5, 1, 0x90 127 .fill 32 - 5, 1, 0x90
83 branch_backwards_end: 128 branch_backwards_end:
84 129
85 130
86 /* We include disallowed code below, so this must go into the 131 /* We include disallowed code below, so this must go into the
87 data segment. */ 132 data segment. */
88 .data 133 .data
89 134
90 135
91 .global invalid_code 136 .global invalid_code
92 .global invalid_code_end 137 .global invalid_code_end
93 .p2align 5 138 .p2align 5
94 invalid_code: 139 invalid_code:
95 int $0x80 140 int $0x80
96 ret 141 ret
97 invalid_code_end: 142 invalid_code_end:
143
144
145 .global template_func_illegal_register_replacement
146 .global template_func_illegal_register_replacement_end
147 .p2align 5
148 template_func_illegal_register_replacement:
149 #if defined(__i386__)
150 movl $1234, %eax
151 popl %ecx
152 and $0xffffffe0,%ecx
153 jmp *%edx /* replaces register here, jmp
154 * becomes illegal */
155 call template_func_illegal_register_replacement
156 #elif defined(__x86_64__)
157 xorl %r11d, %r11d
158 movq disp(%r15,%r11,1), %rax
159 popq %r14
160 andl $0xffffffe0,%r14d
161 addq %r15,%r14
162 jmpq *%r14
163 call template_func_illegal_register_replacement
164 test $0xffffffff,%r11d
165 movq $1234, %rbx /* replaces register
166 * which is not allowed */
167 #else
168 # error "Unsupported architecture"
169 #endif
170 template_func_illegal_register_replacement_end:
171
172
173 .global template_func_illegal_guard_replacement
174 .global template_func_illegal_guard_replacement_end
175 .p2align 5
176 template_func_illegal_guard_replacement:
177 #if defined(__i386__)
178 movl $1234, %eax
179 popl %ecx
180 and $0xffffffff,%ecx /* modifies mask */
181 jmp *%ecx
182 call template_func_illegal_guard_replacement
183 #elif defined(__x86_64__)
184 xorl %r14d, %r14d /* modifies memory guard */
185 movq disp(%r15,%r11,1), %rax
186 popq %r14
187 andl $0xffffffe0,%r14d
188 addq %r15,%r14
189 jmpq *%r14
190 call template_func_illegal_guard_replacement
191 test $0xffffffff,%r11d
192 movq $1234, %rax
193 #else
194 # error "Unsupported architecture"
195 #endif
196 template_func_illegal_guard_replacement_end:
197
198
199 .global template_func_illegal_call_target
200 .global template_func_illegal_call_target_end
201 .p2align 5
202 template_func_illegal_call_target:
203 #if defined(__i386__)
204 movl $1234, %eax
205 popl %ecx
206 and $0xffffffe0,%ecx
207 jmp *%ecx
208 call (template_func_illegal_call_target - 31) /* target of a call
209 * instruction is beyond
210 * replaced section, and it is
211 * not bundle_aligned */
212 #elif defined(__x86_64__)
213 xorl %r11d, %r11d
214 movq disp(%r15,%r11,1), %rax
215 popq %r14
216 andl $0xffffffe0,%r14d
217 addq %r15,%r14
218 jmpq *%r14
219 call (template_func_illegal_call_target - 31) /* target of a call
220 * instruction is beyond
221 * replaced section, and it is
222 * not bundle_aligned */
223 test $0xffffffff,%r11d
224 movq $1234, %rax
225 #else
226 # error "Unsupported architecture"
227 #endif
228 template_func_illegal_call_target_end:
229
230
231 .global template_func_illegal_constant_replacement
232 .global template_func_illegal_constant_replacement_end
233 .p2align 5
234 template_func_illegal_constant_replacement:
235 #if defined(__i386__)
236 hlt /* not applicable */
237 #elif defined(__x86_64__)
238 xorl %r11d, %r11d
239 movq disp(%r15,%r11,1), %rax
240 popq %r14
241 andl $0xffffffe0,%r14d
242 addq %r15,%r14
243 jmpq *%r14
244 call (template_func_illegal_constant_replacement)
245 test $0xf0f0f0f0,%r11d /* can't change constant in test */
246 movq $1234, %rax
247 #else
248 # error "Unsupported architecture"
249 #endif
250 template_func_illegal_constant_replacement_end:
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698