Chromium Code Reviews| Index: newlib/libc/machine/x86_64/setjmp.S |
| diff --git a/newlib/libc/machine/x86_64/setjmp.S b/newlib/libc/machine/x86_64/setjmp.S |
| index b1d26adba38b905d3b269ded44f305b06de6b240..a2a838a6e7280390d547552a3071eec4ef1e5b5d 100644 |
| --- a/newlib/libc/machine/x86_64/setjmp.S |
| +++ b/newlib/libc/machine/x86_64/setjmp.S |
| @@ -1,53 +1,80 @@ |
| /* |
| - * ==================================================== |
| - * Copyright (C) 2007 by Ellips BV. All rights reserved. |
| - * |
| - * Permission to use, copy, modify, and distribute this |
| - * software is freely granted, provided that this notice |
| - * is preserved. |
| - * ==================================================== |
| + * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| */ |
| - /* |
| - ** jmp_buf: |
| - ** rbx r12 r13 r14 rip ebp esp |
| - ** 0 8 16 24 32 40 44 |
| +/* This file is copied from pnacl/support/setjmp_x86_64.S in the Native Client |
| + * 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.
|
| */ |
| - #include "x86_64mach.h" |
| - |
| - .global SYM (setjmp) |
| - .global SYM (longjmp) |
| - SOTYPE_FUNCTION(setjmp) |
| - SOTYPE_FUNCTION(longjmp) |
| - |
| -SYM (setjmp): |
| - movq rbx, %nacl: 0 (r15,rdi) |
| - movq r12, %nacl: 8 (r15,rdi) |
| - movq r13, %nacl: 16 (r15,rdi) |
| - movq r14, %nacl: 24 (r15,rdi) |
| - movq (rsp), rax |
| - movq rax, %nacl: 32 (r15,rdi) |
| - leaq 8 (rsp), rax |
| - movl ebp, %nacl: 40 (r15,rdi) |
| - movl eax, %nacl: 44 (r15,rdi) |
| - movq $0, rax |
| - pop r11 |
| - nacljmp r11d, r15 |
| - |
| -SYM (longjmp): |
| - movq rsi, rax /* Return value */ |
| - |
| - naclrestbp %nacl: 40 (r15,rdi), r15 |
| - |
| - __CLI |
| - naclrestsp %nacl: 44 (r15,rdi), r15 |
| - pushq %nacl: 32 (r15,rdi) |
| - movq %nacl: 0 (r15,rdi), rbx |
| - movq %nacl: 8 (r15,rdi), r12 |
| - movq %nacl: 16 (r15,rdi), r13 |
| - movq %nacl: 24 (r15,rdi), r14 |
| - __STI |
| - |
| - pop r11 |
| - nacljmp r11d, r15 |
| +#define NACL_BLOCK_SHIFT 5 |
| + |
| +/* |
| + * jump_buf is organized as follows |
| + * rbx, rbp, rsp, r12, r13, r14, pc |
| + * NOTE: r15 is neither saved nor restored |
| + */ |
| + .text |
| + .p2align NACL_BLOCK_SHIFT |
| + .globl setjmp |
| + .type setjmp, @function |
| + |
| +/* int setjmp(jmp_buf env) */ |
| +setjmp: |
| + /* edi has env argument*/ |
| + pop %rdx /* return address */ |
| + |
| + /* |
| + * We avoid revealing the top 32 bits of rbp and rsp here. |
| + * |
| + * Also note that we don't do: |
| + * pop %r11 |
| + * ... |
| + * movq %r11, %nacl:48(%r15,%rdi) / * save pc * / |
| + * because the latter instruction might be reached via a direct or |
| + * indirect jump when r11 contains the sandbox base address in its |
| + * top 32 bits, and this would write the sandbox base address into |
| + * memory. We treat r11 as a write-only register to avoid |
| + * revealing the sandbox base address to user code. |
| + */ |
| + movq %rbx, %nacl:0(%r15,%rdi) /* save rbx */ |
| + movl %ebp, %nacl:8(%r15,%rdi) /* save rbp/ebp */ |
| + movl %esp, %nacl:16(%r15,%rdi) /* save rsp/esp */ |
| + movq %r12, %nacl:24(%r15,%rdi) /* save r12 */ |
| + movq %r13, %nacl:32(%r15,%rdi) /* save r13 */ |
| + movq %r14, %nacl:40(%r15,%rdi) /* save r14 */ |
| + movq %rdx, %nacl:48(%r15,%rdi) /* save pc */ |
| + |
| + xorq %rax, %rax |
| + |
| + movl %edx, %r11d |
| + nacljmp %r11d, %r15 |
| + |
| + |
| + .text |
| + .p2align NACL_BLOCK_SHIFT |
| + .globl longjmp |
| + .type longjmp, @function |
| + |
| +/* void longjmp(jmp_buf env, int val) */ |
| +longjmp: |
| + /* edi has env argument */ |
| + /* esi has val argument */ |
| + movl %esi, %eax |
| + /* if val is zero, we must return 1 -- otherwise return val */ |
| + testl %eax, %eax |
| + 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
|
| + movl $1, %eax |
| +.Lskip: |
| + movq %nacl:0(%r15,%rdi), %rbx /* restore rbx */ |
| + movq %nacl:8(%r15,%rdi), %rdx /* restore rbp */ |
| + naclrestbp %edx, %r15 |
| + movq %nacl:16(%r15,%rdi), %rdx /* restore rsp */ |
| + naclrestsp %edx, %r15 |
| + movq %nacl:24(%r15,%rdi), %r12 /* restore r12 */ |
| + movq %nacl:32(%r15,%rdi), %r13 /* restore r13 */ |
| + movq %nacl:40(%r15,%rdi), %r14 /* restore r14 */ |
| + movq %nacl:48(%r15,%rdi), %r11 |
| + nacljmp %r11d, %r15 |
| + .p2align NACL_BLOCK_SHIFT |