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 "native_client/tests/dynamic_code_loading/dynamic_load_test.h" | 7 #include "native_client/tests/dynamic_code_loading/dynamic_load_test.h" |
8 | 8 |
9 #include <assert.h> | 9 #include <assert.h> |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <string.h> | 12 #include <string.h> |
13 #include <sys/mman.h> | 13 #include <sys/mman.h> |
14 | 14 |
15 #include <nacl/nacl_dyncode.h> | 15 #include <nacl/nacl_dyncode.h> |
16 | 16 |
| 17 #include "native_client/src/include/arm_sandbox.h" |
17 #include "native_client/tests/dynamic_code_loading/dynamic_segment.h" | 18 #include "native_client/tests/dynamic_code_loading/dynamic_segment.h" |
18 #include "native_client/tests/dynamic_code_loading/templates.h" | 19 #include "native_client/tests/dynamic_code_loading/templates.h" |
19 #include "native_client/tests/inbrowser_test_runner/test_runner.h" | 20 #include "native_client/tests/inbrowser_test_runner/test_runner.h" |
20 | 21 |
21 #if defined(__x86_64__) | 22 #if defined(__x86_64__) |
22 /* On x86-64, template functions do not fit in 32-byte buffers */ | 23 /* On x86-64, template functions do not fit in 32-byte buffers */ |
23 #define BUF_SIZE 64 | 24 #define BUF_SIZE 64 |
24 #elif defined(__i386__) || defined(__arm__) | 25 #elif defined(__i386__) || defined(__arm__) |
25 #define BUF_SIZE 32 | 26 #define BUF_SIZE 32 |
26 #else | 27 #else |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 fill_int32(data, size, 0xe1a00000); /* NOP (MOV r0, r0) */ | 75 fill_int32(data, size, 0xe1a00000); /* NOP (MOV r0, r0) */ |
75 #else | 76 #else |
76 # error "Unknown arch" | 77 # error "Unknown arch" |
77 #endif | 78 #endif |
78 } | 79 } |
79 | 80 |
80 void fill_hlts(uint8_t *data, size_t size) { | 81 void fill_hlts(uint8_t *data, size_t size) { |
81 #if defined(__i386__) || defined(__x86_64__) | 82 #if defined(__i386__) || defined(__x86_64__) |
82 memset(data, 0xf4, size); /* HLTs */ | 83 memset(data, 0xf4, size); /* HLTs */ |
83 #elif defined(__arm__) | 84 #elif defined(__arm__) |
84 fill_int32(data, size, 0xe1266676); /* BKPT 0x6666 */ | 85 fill_int32(data, size, NACL_INSTR_HALT_FILL); |
85 #else | 86 #else |
86 # error "Unknown arch" | 87 # error "Unknown arch" |
87 #endif | 88 #endif |
88 } | 89 } |
89 | 90 |
90 /* | 91 /* |
91 * Getting the assembler to pad our code fragments in templates.S is | 92 * Getting the assembler to pad our code fragments in templates.S is |
92 * awkward because we have to output them in data mode, in which the | 93 * awkward because we have to output them in data mode, in which the |
93 * assembler wants to output zeroes instead of NOPs for padding. | 94 * assembler wants to output zeroes instead of NOPs for padding. |
94 */ | 95 */ |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 rc = nacl_dyncode_delete(load_addr + NACL_BUNDLE_SIZE, | 478 rc = nacl_dyncode_delete(load_addr + NACL_BUNDLE_SIZE, |
478 sizeof(buf) - NACL_BUNDLE_SIZE); | 479 sizeof(buf) - NACL_BUNDLE_SIZE); |
479 assert(rc == -1); | 480 assert(rc == -1); |
480 assert(errno == EFAULT); | 481 assert(errno == EFAULT); |
481 /* The correct range should work, though. */ | 482 /* The correct range should work, though. */ |
482 rc = nacl_dyncode_delete(load_addr, sizeof(buf)); | 483 rc = nacl_dyncode_delete(load_addr, sizeof(buf)); |
483 assert(rc == 0); | 484 assert(rc == 0); |
484 } | 485 } |
485 | 486 |
486 void check_region_is_filled_with_hlts(const char *data, size_t size) { | 487 void check_region_is_filled_with_hlts(const char *data, size_t size) { |
487 uint8_t halts[] = | |
488 #if defined(__i386__) || defined(__x86_64__) | 488 #if defined(__i386__) || defined(__x86_64__) |
489 { 0xf4 }; /* HLT */ | 489 uint8_t halts = 0xf4; /* HLT */ |
490 #elif defined(__arm__) | 490 #elif defined(__arm__) |
491 { 0x76, 0x66, 0x26, 0xe1 }; /* 0xe1266676 - BKPT 0x6666 */ | 491 uint32_t halts = NACL_INSTR_HALT_FILL; |
492 #else | 492 #else |
493 # error "Unknown arch" | 493 # error "Unknown arch" |
494 #endif | 494 #endif |
495 const char *ptr; | 495 const char *ptr; |
496 for (ptr = data; ptr < data + size; ptr += sizeof(halts)) { | 496 for (ptr = data; ptr < data + size; ptr += sizeof(halts)) { |
497 assert(memcmp(ptr, halts, sizeof(halts)) == 0); | 497 assert(memcmp(ptr, &halts, sizeof(halts)) == 0); |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 /* | 501 /* |
502 * Check that regions surrounding the region we load code into are | 502 * Check that regions surrounding the region we load code into are |
503 * correctly filled with halt instructions. Loading code causes the | 503 * correctly filled with halt instructions. Loading code causes the |
504 * pages to become allocated, and unused parts of these pages should | 504 * pages to become allocated, and unused parts of these pages should |
505 * be filled with halts. | 505 * be filled with halts. |
506 */ | 506 */ |
507 void test_demand_alloc_surrounding_hlt_filling() { | 507 void test_demand_alloc_surrounding_hlt_filling() { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 | 597 |
598 /* Test again to make sure we didn't run out of space. */ | 598 /* Test again to make sure we didn't run out of space. */ |
599 RUN_TEST(test_loading_code); | 599 RUN_TEST(test_loading_code); |
600 | 600 |
601 return 0; | 601 return 0; |
602 } | 602 } |
603 | 603 |
604 int main() { | 604 int main() { |
605 return RunTests(TestMain); | 605 return RunTests(TestMain); |
606 } | 606 } |
OLD | NEW |