OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 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 be |
4 * be found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 void unfixed_code(void); | 9 void unfixed_code(void); |
10 | 10 |
11 #if defined(__i386__) || defined(__x86_64__) | 11 #if defined(__i386__) || defined(__x86_64__) |
12 __asm__("unfixed_code: ret\n"); | 12 __asm__("unfixed_code: ret\n"); |
13 #elif defined(__mips__) | |
14 __asm__("unfixed_code: jr $ra\n" | |
15 "nop\n"); | |
13 #else | 16 #else |
14 # error "Unsupported architecture" | 17 # error "Unsupported architecture" |
15 #endif | 18 #endif |
16 | 19 |
17 /* Test a large number of validator errors. This is a regression test | 20 /* Test a large number of validator errors. This is a regression test |
18 for a bug in which the validator would only stub out the first 100 | 21 for a bug in which the validator would only stub out the first 100 |
19 bad instructions. | 22 bad instructions. |
20 See http://code.google.com/p/nativeclient/issues/detail?id=1194. | 23 See http://code.google.com/p/nativeclient/issues/detail?id=1194. |
21 The assembler does not provide an obvious repeat/loop construct, so | 24 The assembler does not provide an obvious repeat/loop construct, so |
22 we use ".fill" with a numeric value to generate an instruction many | 25 we use ".fill" with a numeric value to generate an instruction many |
23 times. */ | 26 times. */ |
24 #if defined(__i386__) | 27 #if defined(__i386__) |
25 __asm__(".p2align 5\n" | 28 __asm__(".p2align 5\n" |
26 /* "cd 80" disassembles to "int $0x80". */ | 29 /* "cd 80" disassembles to "int $0x80". */ |
27 ".fill 1000, 2, 0x80cd\n" | 30 ".fill 1000, 2, 0x80cd\n" |
28 ".p2align 5\n"); | 31 ".p2align 5\n"); |
29 #elif defined(__x86_64__) | 32 #elif defined(__x86_64__) |
30 __asm__(".p2align 5\n" | 33 __asm__(".p2align 5\n" |
31 /* "0f 05" disassembles to "syscall". */ | 34 /* "0f 05" disassembles to "syscall". */ |
32 ".fill 1000, 2, 0x050f\n" | 35 ".fill 1000, 2, 0x050f\n" |
33 ".p2align 5\n"); | 36 ".p2align 5\n"); |
37 #elif defined(__mips__) | |
38 __asm__(".p2align 4 \n" | |
Mark Seaborn
2013/02/13 22:14:09
Nit: For consistency, no space before \n
petarj
2013/03/05 17:50:04
Done.
| |
39 /* "0xc" disassembles to "syscall". */ | |
40 ".fill 1000, 4, 0x0000000c \n" | |
41 ".p2align 4 \n"); | |
34 #else | 42 #else |
35 # error "Unsupported architecture" | 43 # error "Unsupported architecture" |
36 #endif | 44 #endif |
37 | 45 |
38 int main(void) { | 46 int main(void) { |
39 printf("Before non-validating instruction\n"); | 47 printf("Before non-validating instruction\n"); |
40 fflush(stdout); | 48 fflush(stdout); |
41 unfixed_code(); | 49 unfixed_code(); |
42 printf("After non-validating instruction\n"); | 50 printf("After non-validating instruction\n"); |
43 return 0; | 51 return 0; |
44 } | 52 } |
OLD | NEW |