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
4 * found in the LICENSE file.
7 #include "native_client/src/trusted/service_runtime/arch/arm/sel_ldr_arm.h"
8 #include "native_client/src/trusted/service_runtime/arch/arm/sel_rt.h"
9 #include "native_client/src/trusted/service_runtime/nacl_config.h"
15 * This trusted code is linked into the service runtime. It is executed when a
16 * nacl module performs a system call via a service runtime interface. The nacl
17 * module jumps to the trampoline corresponding to the syscall and then here.
18 * This code switches the execution contexts (registers and stack) from
19 * untrusted to trusted.
22 DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSyscallSeg):
23 /* Set r0 to the start of the NaClThreadContext struct. */
24 sub r0, r9, #NACL_THREAD_CONTEXT_OFFSET_TLS_VALUE1
27 * Check that r9 points into a valid NaClThreadContext by checking
28 * that the guard_token field matches nacl_guard_token.
30 ldr r2, [r0, #NACL_THREAD_CONTEXT_OFFSET_GUARD_TOKEN]
31 ldr r3, .L.offset.nacl_guard_token
35 bne NaClSyscallThreadCaptureFault
37 /* Save address of trampoline for determining which syscall was called. */
40 /* store thread state to the nacl_user entry */
41 stmia r0, NACL_CALLEE_SAVE_LIST
42 /* if r0 is NULL, we would have faulted here */
43 DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSyscallSegRegsSaved):
46 * Store the untrusted fpscr state and load the trusted fpscr into r2.
49 str ip, [r0, #NACL_THREAD_CONTEXT_OFFSET_FPSCR]
50 ldr r2, [r0, #NACL_THREAD_CONTEXT_OFFSET_SYS_FPSCR]
52 /* Restore the trusted stack */
53 ldr sp, [r0, #NACL_THREAD_CONTEXT_OFFSET_TRUSTED_STACK_PTR]
55 /* Restore the trusted fpscr. */
58 bl NaClSyscallCSegHook
61 * NaClSyscallCSegHook returned with the NaClThreadContext pointer
62 * back in r0, which is conveniently already where it's needed to
63 * be the argument to NaClSwitch.
67 DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSyscallSegEnd):
69 DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSyscallThreadCaptureFault):
72 .L.offset.nacl_guard_token:
73 .word nacl_guard_token - (.LPIC1 + 8)