| 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> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 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", (void *) ptr); |
| 42 exit(1); | 42 exit(1); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 int main(void) { | 47 int main(void) { |
| 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 |