OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2012 The Native Client Authors. All rights reserved. |
Mark Seaborn
2012/09/08 02:43:14
BTW, we don't update the copyright year any more.
petarj
2012/09/11 16:58:13
As I understand from there, when a new file is cre
| |
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 |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include "native_client/src/trusted/platform_qualify/nacl_dep_qualify.h" | 9 #include "native_client/src/trusted/platform_qualify/nacl_dep_qualify.h" |
10 #include "native_client/src/include/nacl_macros.h" | 10 #include "native_client/src/include/nacl_macros.h" |
11 | 11 |
12 /* Assembled equivalent of "bx lr" */ | 12 /* Assembled equivalent of "jr ra" */ |
13 #define INST_BX_LR 0xE12FFF1E | 13 #define INST_JR_RA 0x3E00008 |
14 #define INST_NOP 0x0000000 | |
14 | 15 |
15 int NaClCheckDEP() { | 16 int NaClCheckDEP() { |
16 /* | 17 /* |
17 * We require DEP, so forward this call to the OS-specific check routine. | 18 * We require DEP, so forward this call to the OS-specific check routine. |
18 */ | 19 */ |
19 return NaClAttemptToExecuteData(); | 20 return NaClAttemptToExecuteData(); |
Mark Seaborn
2012/09/08 02:43:14
Nit: the changed indentation here is wrong
petarj
2012/09/11 16:58:13
Done.
| |
20 } | 21 } |
21 | 22 |
22 nacl_void_thunk NaClGenerateThunk(char *buf, size_t size_in_bytes) { | 23 nacl_void_thunk NaClGenerateThunk(char *buf, size_t size_in_bytes) { |
23 /* | 24 /* |
24 * Place a "bx lr" at the next aligned address after buf. Instructions | 25 * Place a "jr ra" at the next aligned address after buf. Instructions |
25 * are always little-endian, regardless of data setting. | 26 * are always little-endian, regardless of data setting. We also place opcode |
27 * for "nop" (which is zero) because of delay slot in Mips. | |
26 */ | 28 */ |
27 char *aligned_buf = (char *) (((uintptr_t) buf + 3) & ~3); | 29 char *aligned_buf = (char *) (((uintptr_t) buf + 3) & ~3); |
28 | 30 |
29 if (aligned_buf + 4 > buf + size_in_bytes) return 0; | 31 if (aligned_buf + 8 > buf + size_in_bytes) return 0; |
30 | 32 |
31 aligned_buf[0] = (char) (INST_BX_LR >> 0); | 33 aligned_buf[0] = (char) (INST_JR_RA >> 0); |
Mark Seaborn
2012/09/08 02:43:14
Why not just write:
uint32_t *aligned_buf = ...;
petarj
2012/09/11 16:58:13
Done.
| |
32 aligned_buf[1] = (char) (INST_BX_LR >> 8); | 34 aligned_buf[1] = (char) (INST_JR_RA >> 8); |
33 aligned_buf[2] = (char) (INST_BX_LR >> 16); | 35 aligned_buf[2] = (char) (INST_JR_RA >> 16); |
34 aligned_buf[3] = (char) (INST_BX_LR >> 24); | 36 aligned_buf[3] = (char) (INST_JR_RA >> 24); |
37 aligned_buf[4] = (char) (INST_NOP >> 0); | |
38 aligned_buf[5] = (char) (INST_NOP >> 8); | |
39 aligned_buf[6] = (char) (INST_NOP >> 16); | |
40 aligned_buf[7] = (char) (INST_NOP >> 24); | |
35 | 41 |
36 /* | 42 /* |
37 * ISO C prevents a direct data->function cast, because the pointers aren't | 43 * ISO C prevents a direct data->function cast, because the pointers aren't |
38 * guaranteed to be the same size. For our platforms this is fine, but we | 44 * guaranteed to be the same size. For our platforms this is fine, but we |
39 * verify at compile time anyway before tricking the compiler: | 45 * verify at compile time anyway before tricking the compiler: |
40 */ | 46 */ |
41 NACL_ASSERT_SAME_SIZE(char *, nacl_void_thunk); | 47 NACL_ASSERT_SAME_SIZE(char *, nacl_void_thunk); |
42 return (nacl_void_thunk) (uintptr_t) aligned_buf; | 48 return (nacl_void_thunk) (uintptr_t) aligned_buf; |
43 } | 49 } |
OLD | NEW |