Chromium Code Reviews| 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 uint8_t halts[] = { |
| 488 #if defined(__i386__) || defined(__x86_64__) | 489 #if defined(__i386__) || defined(__x86_64__) |
| 489 { 0xf4 }; /* HLT */ | 490 0xf4 /* HLT */ |
| 490 #elif defined(__arm__) | 491 #elif defined(__arm__) |
| 491 { 0x76, 0x66, 0x26, 0xe1 }; /* 0xe1266676 - BKPT 0x6666 */ | 492 (NACL_INSTR_HALT_FILL >> 0) & 0xFF, |
|
Mark Seaborn
2012/10/18 22:05:30
You can just do:
#if x86...
uint8_t halts = 0xf4;
| |
| 493 (NACL_INSTR_HALT_FILL >> 8) & 0xFF, | |
| 494 (NACL_INSTR_HALT_FILL >> 16) & 0xFF, | |
| 495 (NACL_INSTR_HALT_FILL >> 24) & 0xFF | |
| 492 #else | 496 #else |
| 493 # error "Unknown arch" | 497 # error "Unknown arch" |
| 494 #endif | 498 #endif |
| 499 }; | |
| 495 const char *ptr; | 500 const char *ptr; |
| 496 for (ptr = data; ptr < data + size; ptr += sizeof(halts)) { | 501 for (ptr = data; ptr < data + size; ptr += sizeof(halts)) { |
| 497 assert(memcmp(ptr, halts, sizeof(halts)) == 0); | 502 assert(memcmp(ptr, halts, sizeof(halts)) == 0); |
| 498 } | 503 } |
| 499 } | 504 } |
| 500 | 505 |
| 501 /* | 506 /* |
| 502 * Check that regions surrounding the region we load code into are | 507 * Check that regions surrounding the region we load code into are |
| 503 * correctly filled with halt instructions. Loading code causes the | 508 * correctly filled with halt instructions. Loading code causes the |
| 504 * pages to become allocated, and unused parts of these pages should | 509 * pages to become allocated, and unused parts of these pages should |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 | 602 |
| 598 /* Test again to make sure we didn't run out of space. */ | 603 /* Test again to make sure we didn't run out of space. */ |
| 599 RUN_TEST(test_loading_code); | 604 RUN_TEST(test_loading_code); |
| 600 | 605 |
| 601 return 0; | 606 return 0; |
| 602 } | 607 } |
| 603 | 608 |
| 604 int main() { | 609 int main() { |
| 605 return RunTests(TestMain); | 610 return RunTests(TestMain); |
| 606 } | 611 } |
| OLD | NEW |