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/arch/mips/sel_rt.h" | 12 #include "native_client/src/trusted/service_runtime/arch/mips/sel_rt.h" |
13 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 13 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
14 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 14 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
15 #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" | 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. | 20 * We don't need anything here. |
21 */ | 21 */ |
22 UNREFERENCED_PARAMETER(nap); | 22 UNREFERENCED_PARAMETER(nap); |
23 } | 23 } |
24 | 24 |
25 NORETURN void NaClStartThreadInApp(struct NaClAppThread *natp, | 25 NORETURN void NaClStartThreadInApp(struct NaClAppThread *natp, |
26 uint32_t new_prog_ctr) { | 26 uint32_t new_prog_ctr) { |
27 struct NaClThreadContext *context; | 27 struct NaClThreadContext *context; |
28 | 28 |
29 natp->user.trusted_stack_ptr = (NaClGetStackPtr() & ~0xf) + 4; | 29 natp->user.trusted_stack_ptr = NaClGetStackPtr() & ~NACL_STACK_ALIGN_MASK; |
30 | 30 |
31 context = &natp->user; | 31 context = &natp->user; |
32 context->new_prog_ctr = new_prog_ctr; | 32 context->new_prog_ctr = new_prog_ctr; |
33 | 33 |
34 /* | 34 /* |
35 * At startup this is not the return value, but the first argument. | 35 * At startup this is not the return value, but the first argument. |
36 * In the initial thread, it gets the pointer to the information | 36 * In the initial thread, it gets the pointer to the information |
37 * block on the stack. Additional threads do not expect anything in | 37 * block on the stack. Additional threads do not expect anything in |
38 * particular in the first argument register, so we don't bother to | 38 * particular in the first argument register, so we don't bother to |
39 * conditionalize this. | 39 * conditionalize this. |
40 */ | 40 */ |
41 context->sysret = context->stack_ptr; | 41 context->sysret = context->stack_ptr; |
42 | 42 |
43 /* | 43 /* |
44 * Just to be sure that app does not spoil gp | |
45 */ | |
46 context->global_ptr = NaClGetGlobalPtr(); | |
47 | |
48 /* | |
49 * context stored in $a0 | 44 * context stored in $a0 |
50 */ | 45 */ |
51 NaClSwitch(context); | 46 NaClSwitch(context); |
52 } | 47 } |
53 | 48 |
54 /* | 49 /* |
55 * syscall return | 50 * syscall return |
56 */ | 51 */ |
57 NORETURN void NaClSwitchToApp(struct NaClAppThread *natp) { | 52 NORETURN void NaClSwitchToApp(struct NaClAppThread *natp) { |
58 NaClSwitch(&natp->user); | 53 NaClSwitch(&natp->user); |
59 } | 54 } |
OLD | NEW |