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 /* | 7 /* |
8 * NaCl Service Runtime, C-level context switch code. | 8 * NaCl Service Runtime, C-level context switch code. |
9 */ | 9 */ |
10 | 10 |
11 #include "native_client/src/shared/platform/nacl_check.h" | 11 #include "native_client/src/shared/platform/nacl_check.h" |
12 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 12 #include "native_client/src/trusted/service_runtime/arch/mips/sel_rt.h" |
13 #include "native_client/src/trusted/service_runtime/arch/arm/sel_rt.h" | |
14 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 13 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
15 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 14 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
16 #include "native_client/src/trusted/service_runtime/nacl_switch_to_app.h" | 15 #include "native_client/src/trusted/service_runtime/nacl_switch_to_app.h" |
| 16 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
17 | 17 |
18 void NaClInitSwitchToApp(struct NaClApp *nap) { | 18 void NaClInitSwitchToApp(struct NaClApp *nap) { |
19 /* | 19 /* |
20 * We don't need anything here. We might need it in future if e.g. | 20 * We don't need anything here. |
21 * we start letting untrusted code use NEON extensions. | 21 */ |
22 */ | |
23 UNREFERENCED_PARAMETER(nap); | 22 UNREFERENCED_PARAMETER(nap); |
24 } | 23 } |
25 | 24 |
26 NORETURN void NaClStartThreadInApp(struct NaClAppThread *natp, | 25 NORETURN void NaClStartThreadInApp(struct NaClAppThread *natp, |
27 uint32_t new_prog_ctr) { | 26 uint32_t new_prog_ctr) { |
28 struct NaClApp *nap; | 27 struct NaClApp *nap; |
29 struct NaClThreadContext *context; | 28 struct NaClThreadContext *context; |
30 | 29 |
31 natp->user.trusted_stack_ptr = NaClGetStackPtr() & ~0xf; | 30 natp->user.trusted_stack_ptr = (NaClGetStackPtr() & ~0xf) + 4; |
32 | 31 |
33 nap = natp->nap; | 32 nap = natp->nap; |
34 context = &natp->user; | 33 context = &natp->user; |
35 context->new_prog_ctr = new_prog_ctr; | 34 context->new_prog_ctr = new_prog_ctr; |
36 | 35 |
37 /* | 36 /* |
38 * At startup this is not the return value, but the first argument. | 37 * At startup this is not the return value, but the first argument. |
39 * In the initial thread, it gets the pointer to the information | 38 * In the initial thread, it gets the pointer to the information |
40 * block on the stack. Additional threads do not expect anything in | 39 * block on the stack. Additional threads do not expect anything in |
41 * particular in the first argument register, so we don't bother to | 40 * particular in the first argument register, so we don't bother to |
42 * conditionalize this. | 41 * conditionalize this. |
43 */ | 42 */ |
44 context->sysret = context->stack_ptr; | 43 context->sysret = context->stack_ptr; |
45 | 44 |
| 45 /* |
| 46 * Define load/store and jump masks before switching to app |
| 47 */ |
| 48 context->t6 = NACL_CONTROL_FLOW_MASK; |
| 49 context->t7 = NACL_DATA_FLOW_MASK; |
| 50 |
| 51 /* |
| 52 * Just to be sure that app does not spoil gp |
| 53 */ |
| 54 context->global_ptr = NaClGetGlobalPtr(); |
| 55 |
| 56 /* |
| 57 * context stored in $a0 |
| 58 */ |
46 NaClSwitch(context); | 59 NaClSwitch(context); |
47 } | 60 } |
48 | 61 |
49 /* | 62 /* |
50 * syscall return | 63 * syscall return |
51 */ | 64 */ |
52 NORETURN void NaClSwitchToApp(struct NaClAppThread *natp) { | 65 NORETURN void NaClSwitchToApp(struct NaClAppThread *natp) { |
53 NaClSwitch(&natp->user); | 66 NaClSwitch(&natp->user); |
54 } | 67 } |
OLD | NEW |