OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2010 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 "bx lr" */ |
| 13 #define INST_BX_LR 0xE12FFF1E |
| 14 |
| 15 int NaClCheckDEP() { |
| 16 /* |
| 17 * We require DEP, so forward this call to the OS-specific check routine. |
| 18 */ |
| 19 /* TODO(cbiffle) or (jvoung): enable this when ARM HW test bots have |
| 20 * an upgraded kernel that does not have "the" signal handler bug. |
| 21 * http://code.google.com/p/nativeclient/issues/detail?id=969 |
| 22 * |
| 23 return NaClAttemptToExecuteData(); |
| 24 */ |
| 25 return 1; |
| 26 } |
| 27 |
| 28 nacl_void_thunk NaClGenerateThunk(char *buf, size_t size_in_bytes) { |
| 29 /* |
| 30 * Place a "bx lr" at the next aligned address after buf. Instructions |
| 31 * are always little-endian, regardless of data setting. |
| 32 */ |
| 33 char *aligned_buf = (char *) (((uintptr_t) buf + 3) & ~3); |
| 34 |
| 35 if (aligned_buf + 4 > buf + size_in_bytes) return 0; |
| 36 |
| 37 aligned_buf[0] = (char) (INST_BX_LR >> 0); |
| 38 aligned_buf[1] = (char) (INST_BX_LR >> 8); |
| 39 aligned_buf[2] = (char) (INST_BX_LR >> 16); |
| 40 aligned_buf[3] = (char) (INST_BX_LR >> 24); |
| 41 |
| 42 /* |
| 43 * ISO C prevents a direct data->function cast, because the pointers aren't |
| 44 * guaranteed to be the same size. For our platforms this is fine, but we |
| 45 * verify at compile time anyway before tricking the compiler: |
| 46 */ |
| 47 NACL_ASSERT_SAME_SIZE(char *, nacl_void_thunk); |
| 48 return (nacl_void_thunk) (uintptr_t) aligned_buf; |
| 49 } |
OLD | NEW |