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

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

Issue 3975001: Dynamic code modification support for x64 NaCl modules... (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 10 years, 1 month 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
« no previous file with comments | « tests/dynamic_code_loading/templates_arm.S ('k') | tests/inbrowser_test_runner/nacl.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
15 movq $1234, %rax 25 movq $1234, %rax
16 popq %r11
17 nacljmp %r11d, %r15
18 #else 26 #else
19 # error "Unsupported architecture" 27 # error "Unsupported architecture"
20 #endif 28 #endif
21 template_func_end: 29 template_func_end:
22 30
31
23 .global template_func_replacement 32 .global template_func_replacement
24 .global template_func_replacement_end 33 .global template_func_replacement_end
25 .p2align 5 34 .p2align 5
26 template_func_replacement: 35 template_func_replacement:
27 #if defined(__i386__) 36 #if defined(__i386__)
28 movl $4321, %eax 37 movl $4321, %eax /* replaces constant */
29 popl %ecx 38 popl %ecx
30 nacljmp %ecx 39 and $0xffffffe0,%ecx
40 jmp *%ecx
41 call (template_func_replacement - 32) /* replaces a call target, the
42 * new target is bundle aligned
43 * and target address outside
44 * modified section */
31 #elif defined(__x86_64__) 45 #elif defined(__x86_64__)
32 movq $4321, %rax 46 /* tests all modifications that are
33 popq %r11 47 * currently allowed by service runtime */
34 nacljmp %r11d, %r15 48 new_disp = template_func_replacement_end - 4
49 xorl %r11d, %r11d
50 movq new_disp(%r15,%r11,1), %rax /* replaces displacement */
51 popq %r14
52 andl $0xffffffe0,%r14d
53 addq %r15,%r14
54 jmpq *%r14
55 call (template_func_replacement - 32) /* replaces a call target, the
56 * new target is bundle aligned
57 * and target address outside
58 * modified section */
59 movq $4321, %rax /* replaces constant */
35 #else 60 #else
36 # error "Unsupported architecture" 61 # error "Unsupported architecture"
37 #endif 62 #endif
38 template_func_replacement_end: 63 template_func_replacement_end:
39 64
65
40 .global template_func_nonreplacement 66 .global template_func_nonreplacement
41 .global template_func_nonreplacement_end 67 .global template_func_nonreplacement_end
68 .global template_func_misaligned_replacement
69 .global template_func_misaligned_replacement_end
42 .p2align 5 70 .p2align 5
43 template_func_nonreplacement: 71 template_func_nonreplacement:
72 template_func_misaligned_replacement:
44 #if defined(__i386__) 73 #if defined(__i386__)
45 movl $4132, %eax 74 nop /* nop creates misalignment in
46 popl %edx 75 * replacing section which makes
47 nacljmp %edx 76 * it illegal */
77 movl $1234, %eax
78 popl %ecx
79 and $0xffffffe0,%ecx
80 jmp *%ecx
81 call template_func_misaligned_replacement
48 #elif defined(__x86_64__) 82 #elif defined(__x86_64__)
49 movq $4132, %rax 83 nop /* nop creates misalignment in
50 popq %r12 84 * replacing section which makes
51 nacljmp %r12d, %r15 85 * it illegal */
86 xorl %r11d, %r11d
87 movq disp(%r15,%r11,1), %rax
88 popq %r14
89 andl $0xffffffe0,%r14d
90 addq %r15,%r14
91 jmpq *%r14
92 call template_func_misaligned_replacement
93 movq $1234, %rax
52 #else 94 #else
53 # error "Unsupported architecture" 95 # error "Unsupported architecture"
54 #endif 96 #endif
97 template_func_misaligned_replacement_end:
55 template_func_nonreplacement_end: 98 template_func_nonreplacement_end:
56 99
57 100
58
59 .global hlts 101 .global hlts
60 .global hlts_end 102 .global hlts_end
61 .p2align 5 103 .p2align 5
62 hlts: 104 hlts:
63 .fill 32, 1, 0xf4 105 .fill 32, 1, 0xf4
64 hlts_end: 106 hlts_end:
65 107
66 108
67 .global branch_forwards 109 .global branch_forwards
68 .global branch_forwards_end 110 .global branch_forwards_end
69 .global branch_backwards 111 .global branch_backwards
70 .global branch_backwards_end 112 .global branch_backwards_end
71 .p2align 5 113 .p2align 5
72 branch_forwards: 114 branch_forwards:
73 jmp branch_backwards 115 jmp branch_backwards
74 /* The assembler generates a bad jmp if I use ".p2align 5" 116 /* The assembler generates a bad jmp if I use ".p2align 5"
75 instead of padding manually. TODO(mseaborn): Investigate. */ 117 instead of padding manually. TODO(mseaborn): Investigate. */
76 .fill 32 - 5, 1, 0x90 118 .fill 32 - 5, 1, 0x90
77 branch_forwards_end: 119 branch_forwards_end:
78 branch_backwards: 120 branch_backwards:
79 jmp branch_forwards 121 jmp branch_forwards
80 /* The assembler generates a bad jmp if I use ".p2align 5" 122 /* The assembler generates a bad jmp if I use ".p2align 5"
81 instead of padding manually. */ 123 instead of padding manually. */
82 .fill 32 - 5, 1, 0x90 124 .fill 32 - 5, 1, 0x90
83 branch_backwards_end: 125 branch_backwards_end:
84 126
85 127
86 /* We include disallowed code below, so this must go into the 128 /* We include disallowed code below, so this must go into the
87 data segment. */ 129 data segment. */
88 .data 130 .data
89 131
90 132
91 .global invalid_code 133 .global invalid_code
92 .global invalid_code_end 134 .global invalid_code_end
93 .p2align 5 135 .p2align 5
94 invalid_code: 136 invalid_code:
95 int $0x80 137 int $0x80
96 ret 138 ret
97 invalid_code_end: 139 invalid_code_end:
140
141
142 .global template_func_illegal_register_replacement
143 .global template_func_illegal_register_replacement_end
144 .p2align 5
145 template_func_illegal_register_replacement:
146 #if defined(__i386__)
147 movl $1234, %eax
148 popl %ecx
149 and $0xffffffe0,%ecx
150 jmp *%edx /* replaces register here, jmp
151 * becomes illegal */
152 call template_func_illegal_register_replacement
153 #elif defined(__x86_64__)
154 xorl %r11d, %r11d
155 movq disp(%r15,%r11,1), %rax
156 popq %r14
157 andl $0xffffffe0,%r14d
158 addq %r15,%r14
159 jmpq *%r14
160 call template_func_illegal_register_replacement
161 movq $1234, %rbx /* replaces register
162 * which is not allowed */
163 #else
164 # error "Unsupported architecture"
165 #endif
166 template_func_illegal_register_replacement_end:
167
168
169 .global template_func_illegal_guard_replacement
170 .global template_func_illegal_guard_replacement_end
171 .p2align 5
172 template_func_illegal_guard_replacement:
173 #if defined(__i386__)
174 movl $1234, %eax
175 popl %ecx
176 and $0xffffffff,%ecx /* modifies mask */
177 jmp *%ecx
178 call template_func_illegal_guard_replacement
179 #elif defined(__x86_64__)
180 xorl %r14d, %r14d /* modifies memory guard */
181 movq disp(%r15,%r11,1), %rax
182 popq %r14
183 andl $0xffffffe0,%r14d
184 addq %r15,%r14
185 jmpq *%r14
186 call template_func_illegal_guard_replacement
187 movq $1234, %rax
188 #else
189 # error "Unsupported architecture"
190 #endif
191 template_func_illegal_guard_replacement_end:
192
193
194 .global template_func_illegal_call_target
195 .global template_func_illegal_call_target_end
196 .p2align 5
197 template_func_illegal_call_target:
198 #if defined(__i386__)
199 movl $1234, %eax
200 popl %ecx
201 and $0xffffffe0,%ecx
202 jmp *%ecx
203 call (template_func_illegal_call_target - 31) /* target of a call
204 * instruction is beyond
205 * replaced section, and it is
206 * not bundle_aligned */
207 #elif defined(__x86_64__)
208 xorl %r11d, %r11d
209 movq disp(%r15,%r11,1), %rax
210 popq %r14
211 andl $0xffffffe0,%r14d
212 addq %r15,%r14
213 jmpq *%r14
214 call (template_func_illegal_call_target - 31) /* target of a call
215 * instruction is beyond
216 * replaced section, and it is
217 * not bundle_aligned */
218 movq $1234, %rax
219 #else
220 # error "Unsupported architecture"
221 #endif
222 template_func_illegal_call_target_end:
OLDNEW
« no previous file with comments | « tests/dynamic_code_loading/templates_arm.S ('k') | tests/inbrowser_test_runner/nacl.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698