OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2012 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can | |
4 * be found in the LICENSE file. | |
5 */ | |
6 | |
7 #include <stddef.h> | |
8 #include <stdint.h> | |
9 #include "native_client/src/trusted/platform_qualify/nacl_dep_qualify.h" | |
10 #include "native_client/src/include/nacl_macros.h" | |
11 | |
12 /* Assembled equivalent of "jr ra" */ | |
13 #define INST_JR_RA 0x3E00008 | |
14 #define INST_NOP 0x0000000 | |
15 | |
16 int NaClCheckDEP(void) { | |
17 /* | |
18 * We require DEP, so forward this call to the OS-specific check routine. | |
19 */ | |
20 return NaClAttemptToExecuteData(); | |
21 } | |
22 | |
23 nacl_void_thunk NaClGenerateThunk(char *buf, size_t size_in_bytes) { | |
24 /* | |
25 * Place a "jr ra" at the next aligned address after buf. Instructions | |
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. | |
28 */ | |
29 uint32_t *aligned_buf = (uint32_t *) (((uintptr_t) buf + 3) & ~3); | |
30 | |
31 if ((char*) aligned_buf + 8 > buf + size_in_bytes) return 0; | |
32 | |
33 aligned_buf[0] = (uint32_t) INST_JR_RA; | |
34 aligned_buf[1] = (uint32_t) INST_NOP; | |
35 | |
36 /* | |
37 * 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 | |
39 * verify at compile time anyway before tricking the compiler: | |
40 */ | |
41 NACL_ASSERT_SAME_SIZE(char *, nacl_void_thunk); | |
42 return (nacl_void_thunk) (uintptr_t) aligned_buf; | |
43 } | |
OLD | NEW |