OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 #include <nacl/nacl_dyncode.h> | 11 #include <nacl/nacl_dyncode.h> |
12 | 12 |
13 #include "native_client/src/include/arm_sandbox.h" | |
13 #include "native_client/tests/dynamic_code_loading/dynamic_segment.h" | 14 #include "native_client/tests/dynamic_code_loading/dynamic_segment.h" |
14 | 15 |
15 | 16 |
16 uint8_t halts[] = | |
17 #if defined(__i386__) || defined(__x86_64__) | 17 #if defined(__i386__) || defined(__x86_64__) |
18 { 0xf4 }; /* HLT */ | 18 uint8_t halts = 0xf4; /* HLT */ |
Mark Seaborn
2012/10/19 18:08:43
Remove the indentation here
| |
19 #elif defined(__arm__) | 19 #elif defined(__arm__) |
20 { 0x76, 0x66, 0x26, 0xe1 }; /* 0xe1266676 - BKPT 0x6666 */ | 20 uint32_t halts = NACL_INSTR_HALT_FILL; |
21 #else | 21 #else |
22 # error "Unknown arch" | 22 # error "Unknown arch" |
23 #endif | 23 #endif |
24 | 24 |
25 | 25 |
26 void load_into_page(uint8_t *dest) { | 26 void load_into_page(uint8_t *dest) { |
27 uint8_t buf[32]; | 27 uint8_t buf[32]; |
28 int rc; | 28 int rc; |
29 uint8_t *ptr; | 29 uint8_t *ptr; |
30 | 30 |
31 /* Touch the page by loading some halt instructions into it. */ | 31 /* Touch the page by loading some halt instructions into it. */ |
32 for (ptr = buf; ptr < buf + sizeof(buf); ptr += sizeof(halts)) { | 32 for (ptr = buf; ptr < buf + sizeof(buf); ptr += sizeof(halts)) { |
33 memcpy(ptr, halts, sizeof(halts)); | 33 memcpy(ptr, &halts, sizeof(halts)); |
34 } | 34 } |
35 rc = nacl_dyncode_create(dest, buf, sizeof(buf)); | 35 rc = nacl_dyncode_create(dest, buf, sizeof(buf)); |
36 assert(rc == 0); | 36 assert(rc == 0); |
37 | 37 |
38 /* Check that the whole page is correctly filled with halts. */ | 38 /* Check that the whole page is correctly filled with halts. */ |
39 for (ptr = dest; ptr < dest + DYNAMIC_CODE_PAGE_SIZE; ptr += sizeof(halts)) { | 39 for (ptr = dest; ptr < dest + DYNAMIC_CODE_PAGE_SIZE; ptr += sizeof(halts)) { |
40 if (memcmp(ptr, halts, sizeof(halts)) != 0) { | 40 if (memcmp(ptr, &halts, sizeof(halts)) != 0) { |
41 fprintf(stderr, "Mismatch at %p\n", ptr); | 41 fprintf(stderr, "Mismatch at %p\n", ptr); |
42 exit(1); | 42 exit(1); |
43 } | 43 } |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 int main() { | 47 int main() { |
48 uint8_t *dyncode = (uint8_t *) DYNAMIC_CODE_SEGMENT_START; | 48 uint8_t *dyncode = (uint8_t *) DYNAMIC_CODE_SEGMENT_START; |
49 int value; | 49 int value; |
50 | 50 |
51 /* | 51 /* |
52 * Sanity check: First check that two code pages can be written and | 52 * Sanity check: First check that two code pages can be written and |
53 * read, before we check that the page inbetween is unreadable. | 53 * read, before we check that the page inbetween is unreadable. |
54 */ | 54 */ |
55 load_into_page(dyncode); | 55 load_into_page(dyncode); |
56 load_into_page(dyncode + DYNAMIC_CODE_PAGE_SIZE * 2); | 56 load_into_page(dyncode + DYNAMIC_CODE_PAGE_SIZE * 2); |
57 | 57 |
58 printf("Attempting to read from unallocated dyncode page. " | 58 printf("Attempting to read from unallocated dyncode page. " |
59 "This should fault...\n"); | 59 "This should fault...\n"); |
60 fprintf(stderr, "** intended_exit_status=untrusted_segfault\n"); | 60 fprintf(stderr, "** intended_exit_status=untrusted_segfault\n"); |
61 value = dyncode[DYNAMIC_CODE_PAGE_SIZE]; | 61 value = dyncode[DYNAMIC_CODE_PAGE_SIZE]; |
62 printf("Failed: Dynamic code page was readable and contained the " | 62 printf("Failed: Dynamic code page was readable and contained the " |
63 "byte 0x%x.\n", value); | 63 "byte 0x%x.\n", value); |
64 return 1; | 64 return 1; |
65 } | 65 } |
OLD | NEW |