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.
10 #include "native_client/src/include/portability_string.h"
11 #include "native_client/src/shared/platform/nacl_global_secure_random.h"
12 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
13 #include "native_client/src/trusted/service_runtime/nacl_signal.h"
14 #include "native_client/src/trusted/service_runtime/nacl_tls.h"
15 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
16 #include "native_client/src/trusted/service_runtime/sel_rt.h"
17 #include "native_client/src/trusted/service_runtime/arch/arm/sel_ldr_arm.h"
18 #include "native_client/src/trusted/service_runtime/arch/arm/tramp_arm.h"
21 uint32_t nacl_guard_token;
24 void NaClInitGlobals(void) {
25 NaClLog(2, "NaClInitGlobals\n");
26 nacl_guard_token = NaClGlobalSecureRngUint32();
30 int NaClAppThreadInitArchSpecific(struct NaClAppThread *natp,
32 nacl_reg_t stack_ptr) {
33 struct NaClThreadContext *ntcp = &natp->user;
36 * We call this function so that it does not appear to be dead code,
37 * although it only contains compile-time assertions.
39 NaClThreadContextOffsetCheck();
41 memset((void *)ntcp, 0, sizeof(*ntcp));
42 ntcp->stack_ptr = stack_ptr;
43 ntcp->prog_ctr = prog_ctr;
44 ntcp->tls_idx = NaClTlsAllocate(natp);
45 if (ntcp->tls_idx == NACL_TLS_INDEX_INVALID)
47 ntcp->r9 = (uintptr_t) &ntcp->tls_value1;
48 ntcp->syscall_routine = (uintptr_t) NaClSyscallSeg;
49 ntcp->guard_token = nacl_guard_token;
52 * Save the system's state of the FPSCR so we can restore
53 * the same state when returning to trusted code.
55 __asm__ __volatile__("fmrx %0, fpscr" : "=r" (ntcp->sys_fpscr));
57 NaClLog(4, "user.tls_idx: 0x%08"NACL_PRIxNACL_REG"\n", ntcp->tls_idx);
58 NaClLog(4, "user.stack_ptr: 0x%08"NACL_PRIxNACL_REG"\n", ntcp->stack_ptr);
59 NaClLog(4, "user.prog_ctr: 0x%08"NACL_PRIxNACL_REG"\n", ntcp->prog_ctr);
65 void NaClThreadContextToSignalContext(const struct NaClThreadContext *th_ctx,
66 struct NaClSignalContext *sig_ctx) {
71 sig_ctx->r4 = th_ctx->r4;
72 sig_ctx->r5 = th_ctx->r5;
73 sig_ctx->r6 = th_ctx->r6;
74 sig_ctx->r7 = th_ctx->r7;
75 sig_ctx->r8 = th_ctx->r8;
76 sig_ctx->r9 = th_ctx->r9;
77 sig_ctx->r10 = th_ctx->r10;
78 sig_ctx->r11 = th_ctx->fp;
80 sig_ctx->stack_ptr = th_ctx->stack_ptr;
82 sig_ctx->prog_ctr = th_ctx->new_prog_ctr;
87 void NaClSignalContextUnsetClobberedRegisters(
88 struct NaClSignalContext *sig_ctx) {