Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: newlib/libc/machine/x86_64/setjmp.S

Issue 923253002: Use PNaCl's implementation of setjmp/longjmp for x86-64 (Closed) Base URL: https://chromium.googlesource.com/native_client/nacl-newlib.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * ==================================================== 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Copyright (C) 2007 by Ellips BV. All rights reserved. 3 * Use of this source code is governed by a BSD-style license that can be
4 * 4 * found in the LICENSE file.
5 * Permission to use, copy, modify, and distribute this
6 * software is freely granted, provided that this notice
7 * is preserved.
8 * ====================================================
9 */ 5 */
10 6
11 /* 7 /* This file is copied from pnacl/support/setjmp_x86_64.S in the Native Client
12 ** jmp_buf: 8 * repository. It should be kept in sync.
Mark Seaborn 2015/02/13 23:02:34 add "with minor modifications" (since there are so
Derek Schuff 2015/02/13 23:31:31 Done.
13 ** rbx r12 r13 r14 rip ebp esp
14 ** 0 8 16 24 32 40 44
15 */ 9 */
16 10
17 #include "x86_64mach.h" 11 #define NACL_BLOCK_SHIFT 5
18 12
19 .global SYM (setjmp) 13 /*
20 .global SYM (longjmp) 14 * jump_buf is organized as follows
21 SOTYPE_FUNCTION(setjmp) 15 * rbx, rbp, rsp, r12, r13, r14, pc
22 SOTYPE_FUNCTION(longjmp) 16 * NOTE: r15 is neither saved nor restored
17 */
18 .text
19 .p2align NACL_BLOCK_SHIFT
20 .globl setjmp
21 .type setjmp, @function
23 22
24 SYM (setjmp): 23 /* int setjmp(jmp_buf env) */
25 movq rbx, %nacl: 0 (r15,rdi) 24 setjmp:
26 movq r12, %nacl: 8 (r15,rdi) 25 /* edi has env argument*/
27 movq r13, %nacl: 16 (r15,rdi) 26 pop %rdx /* return address */
28 movq r14, %nacl: 24 (r15,rdi)
29 movq (rsp), rax
30 movq rax, %nacl: 32 (r15,rdi)
31 leaq 8 (rsp), rax
32 movl ebp, %nacl: 40 (r15,rdi)
33 movl eax, %nacl: 44 (r15,rdi)
34 movq $0, rax
35 pop r11
36 nacljmp r11d, r15
37 27
38 SYM (longjmp): 28 /*
39 movq rsi, rax /* Return value */ 29 * We avoid revealing the top 32 bits of rbp and rsp here.
30 *
31 * Also note that we don't do:
32 * pop %r11
33 * ...
34 * movq %r11, %nacl:48(%r15,%rdi) / * save pc * /
35 * because the latter instruction might be reached via a direct or
36 * indirect jump when r11 contains the sandbox base address in its
37 * top 32 bits, and this would write the sandbox base address into
38 * memory. We treat r11 as a write-only register to avoid
39 * revealing the sandbox base address to user code.
40 */
41 movq %rbx, %nacl:0(%r15,%rdi) /* save rbx */
42 movl %ebp, %nacl:8(%r15,%rdi) /* save rbp/ebp */
43 movl %esp, %nacl:16(%r15,%rdi) /* save rsp/esp */
44 movq %r12, %nacl:24(%r15,%rdi) /* save r12 */
45 movq %r13, %nacl:32(%r15,%rdi) /* save r13 */
46 movq %r14, %nacl:40(%r15,%rdi) /* save r14 */
47 movq %rdx, %nacl:48(%r15,%rdi) /* save pc */
40 48
41 naclrestbp %nacl: 40 (r15,rdi), r15 49 xorq %rax, %rax
42 50
43 __CLI 51 movl %edx, %r11d
44 naclrestsp %nacl: 44 (r15,rdi), r15 52 nacljmp %r11d, %r15
45 pushq %nacl: 32 (r15,rdi)
46 movq %nacl: 0 (r15,rdi), rbx
47 movq %nacl: 8 (r15,rdi), r12
48 movq %nacl: 16 (r15,rdi), r13
49 movq %nacl: 24 (r15,rdi), r14
50 __STI
51 53
52 pop r11 54
53 nacljmp r11d, r15 55 .text
56 .p2align NACL_BLOCK_SHIFT
57 .globl longjmp
58 .type longjmp, @function
59
60 /* void longjmp(jmp_buf env, int val) */
61 longjmp:
62 /* edi has env argument */
63 /* esi has val argument */
64 movl %esi, %eax
65 /* if val is zero, we must return 1 -- otherwise return val */
66 testl %eax, %eax
67 jne .Lskip
Mark Seaborn 2015/02/13 23:02:34 PNaCl's version has ".skip". Can you avoid unnece
Derek Schuff 2015/02/13 23:31:31 I'll change PNaCl's version too. This version uses
68 movl $1, %eax
69 .Lskip:
70 movq %nacl:0(%r15,%rdi), %rbx /* restore rbx */
71 movq %nacl:8(%r15,%rdi), %rdx /* restore rbp */
72 naclrestbp %edx, %r15
73 movq %nacl:16(%r15,%rdi), %rdx /* restore rsp */
74 naclrestsp %edx, %r15
75 movq %nacl:24(%r15,%rdi), %r12 /* restore r12 */
76 movq %nacl:32(%r15,%rdi), %r13 /* restore r13 */
77 movq %nacl:40(%r15,%rdi), %r14 /* restore r14 */
78 movq %nacl:48(%r15,%rdi), %r11
79 nacljmp %r11d, %r15
80 .p2align NACL_BLOCK_SHIFT
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698