1/*
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.
5 */
6
7#include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h"
8#include "native_client/src/trusted/service_runtime/nacl_config.h"
9
10        .data
11timebuf:
12        .space 0x200 /* enough for a timeval */
13
14        .text
15        .globl SyscallReturnIsSandboxed
16SyscallReturnIsSandboxed:
17        movq $0, %rsi
18        movq $timebuf, %rdi
19        movl $1f, %ecx
20        addq %r15, %rcx
21        pushq %rcx
22
23        .p2align 5
24        movl $NACL_SYSCALL_ADDR(NACL_sys_gettimeofday), %ecx
25        andl $0xffffffe0, %ecx
26        addq %r15, %rcx
27        jmp *%rcx
28
29        .p2align 5
30        /*
31         * Here we have a whole bundle of halts, with the "return address"
32         * we pushed being in the middle of the bundle.  The syscall return
33         * should round up this misaligned address to the beginning of the
34         * next bundle.  If it fails to do that, we'll execute hlt and crash.
35         */
36        hlt
371:      .p2align 5,0xf4
38        /* Now we're at the next bundle, where the return is rounded to. */
39
40        /*
41         * Test the tls_get call as well, since it may have an alternate
42         * entry/return path in the trampoline implementation.
43         */
44        leaq 2f(%r15), %rcx
45        pushq %rcx
46
47        movl $NACL_SYSCALL_ADDR(NACL_sys_tls_get), %ecx
48        andl $0xffffffe0, %ecx
49        addq %r15, %rcx
50        jmp *%rcx
51
52        .p2align 5
53        hlt
542:      .p2align 5,0xf4
55        /* Now we're at the next bundle, where the return is rounded to. */
56
57        /*
58         * Test the second_tls_get call as well, since it may have an
59         * alternate entry/return path in the trampoline
60         * implementation.
61         */
62        leaq 3f(%r15), %rcx
63        pushq %rcx
64
65        movl $NACL_SYSCALL_ADDR(NACL_sys_second_tls_get), %ecx
66        andl $0xffffffe0, %ecx
67        addq %r15, %rcx
68        jmp *%rcx
69
70        .p2align 5
71        hlt
723:      .p2align 5,0xf4
73        /* Now we're at the next bundle, where the return is rounded to. */
74
75        movl $1, %eax
76        naclret
77        .p2align 5 /* -- pnacl toolchain leaves "..." without this */
78