summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2020-12-06 15:31:30 +0000
committerbluhm <bluhm@openbsd.org>2020-12-06 15:31:30 +0000
commit3a26117014390486743ddc86d9fd1b9bca79fbd6 (patch)
tree3c8cec060d8891ca9758faba04df5650ad0ca137 /lib/libc
parentDo not hide error messages in tests, makes it easier to debug failures. (diff)
downloadwireguard-openbsd-3a26117014390486743ddc86d9fd1b9bca79fbd6.tar.xz
wireguard-openbsd-3a26117014390486743ddc86d9fd1b9bca79fbd6.zip
Introduce constants to access the setjmp(3) jmp_buf fields from
i386 libc. The assembler code is more readable than with magic numbers. This brings i386 in line with amd64. No change in object file. OK kettenis@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/i386/gen/_setjmp.S47
-rw-r--r--lib/libc/arch/i386/gen/setjmp.S51
-rw-r--r--lib/libc/arch/i386/gen/sigsetjmp.S57
3 files changed, 79 insertions, 76 deletions
diff --git a/lib/libc/arch/i386/gen/_setjmp.S b/lib/libc/arch/i386/gen/_setjmp.S
index 438689d6d22..8f77112e7db 100644
--- a/lib/libc/arch/i386/gen/_setjmp.S
+++ b/lib/libc/arch/i386/gen/_setjmp.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: _setjmp.S,v 1.6 2016/05/30 02:11:21 guenther Exp $ */
+/* $OpenBSD: _setjmp.S,v 1.7 2020/12/06 15:31:30 bluhm Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -32,6 +32,7 @@
*/
#include <machine/asm.h>
+#include <machine/setjmp.h>
.global __jmpxor
@@ -49,19 +50,19 @@ ENTRY(_setjmp)
call 1f
1: popl %ecx
addl $__jmpxor-1b,%ecx # load cookie address
- movl 4(%esp),%eax
- movl 0(%esp),%edx
+ movl 4(%esp),%eax # parameter, pointer to env
+ movl 0(%esp),%edx # caller address
xorl 0(%ecx),%edx # use eip cookie
- movl %edx, 0(%eax)
- movl %ebx, 4(%eax)
- movl %esp, %edx
+ movl %edx,(_JB_EIP * 4)(%eax)
+ movl %ebx,(_JB_EBX * 4)(%eax)
+ movl %esp,%edx
xorl 4(%ecx),%edx # use esp cookie
- movl %edx, 8(%eax)
+ movl %edx,(_JB_ESP * 4)(%eax)
movl 8(%ecx),%ecx # load ebp cookie over cookie address
- xorl %ebp, %ecx
- movl %ecx,12(%eax)
- movl %esi,16(%eax)
- movl %edi,20(%eax)
+ xorl %ebp,%ecx
+ movl %ecx,(_JB_EBP * 4)(%eax)
+ movl %esi,(_JB_ESI * 4)(%eax)
+ movl %edi,(_JB_EDI * 4)(%eax)
xorl %eax,%eax
ret
END(_setjmp)
@@ -70,18 +71,18 @@ ENTRY(_longjmp)
call 1f
1: popl %ecx
addl $__jmpxor-1b,%ecx # load cookie address
- movl 4(%esp),%edx
- movl 8(%esp),%eax
- movl 4(%edx),%ebx
- movl 8(%edx),%esi # load xor'ed esp into safe register
- xorl 4(%ecx),%esi # use esp cookie
- movl %esi, %esp # un-xor'ed esp is safe to use
- movl 12(%edx),%ebp
- xorl 8(%ecx),%ebp # use ebp cookie
- movl 16(%edx),%esi
- movl 20(%edx),%edi
- movl 0(%ecx),%ecx # load eip cookie over cookie address
- xorl 0(%edx),%ecx # overwrite eip cookie
+ movl 4(%esp),%edx # parameter, pointer to env
+ movl 8(%esp),%eax # parameter, val
+ movl (_JB_EBX * 4)(%edx),%ebx
+ movl (_JB_ESP * 4)(%edx),%esi
+ xorl 4(%ecx),%esi # use esp cookie
+ movl %esi,%esp # un-xor'ed esp is safe to use
+ movl (_JB_EBP * 4)(%edx),%ebp
+ xorl 8(%ecx),%ebp # use ebp cookie
+ movl (_JB_ESI * 4)(%edx),%esi
+ movl (_JB_EDI * 4)(%edx),%edi
+ movl 0(%ecx),%ecx # load eip cookie over cookie address
+ xorl (_JB_EIP * 4)(%edx),%ecx
testl %eax,%eax
jnz 1f
incl %eax
diff --git a/lib/libc/arch/i386/gen/setjmp.S b/lib/libc/arch/i386/gen/setjmp.S
index eaeb8737640..6e4cb37b0c3 100644
--- a/lib/libc/arch/i386/gen/setjmp.S
+++ b/lib/libc/arch/i386/gen/setjmp.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: setjmp.S,v 1.11 2016/05/30 02:11:21 guenther Exp $ */
+/* $OpenBSD: setjmp.S,v 1.12 2020/12/06 15:31:30 bluhm Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -32,6 +32,7 @@
*/
#include "SYS.h"
+#include <machine/setjmp.h>
.section .openbsd.randomdata,"aw",@progbits
.balign 4
@@ -63,27 +64,27 @@ ENTRY(setjmp)
addl $8,%esp
addl $__jmpxor-1b,%edx # load cookie address
- movl 4(%esp),%ecx
- movl %eax,24(%ecx)
- movl %ebx, 4(%ecx)
- movl %esp, %eax
+ movl 4(%esp),%ecx # parameter, pointer to env
+ movl %eax,(_JB_SIGMASK * 4)(%ecx)
+ movl %ebx,(_JB_EBX * 4)(%ecx)
+ movl %esp,%eax
xorl 0(%edx),%eax # use esp cookie
- movl %eax, 8(%ecx)
- movl %ebp, %eax
+ movl %eax,(_JB_ESP * 4)(%ecx)
+ movl %ebp,%eax
xorl 4(%edx),%eax # use ebp cookie
- movl %eax,12(%ecx)
- movl %esi,16(%ecx)
- movl %edi,20(%ecx)
+ movl %eax,(_JB_EBP * 4)(%ecx)
+ movl %esi,(_JB_ESI * 4)(%ecx)
+ movl %edi,(_JB_EDI * 4)(%ecx)
movl 8(%edx),%edx # load eip cookie over cookie address
- xorl 0(%esp),%edx
- movl %edx, 0(%ecx)
+ xorl 0(%esp),%edx # caller address
+ movl %edx,(_JB_EIP * 4)(%ecx)
xorl %eax,%eax
ret
END(setjmp)
ENTRY(longjmp)
- movl 4(%esp),%edx
- pushl 24(%edx) /* mask from sc_mask */
+ movl 4(%esp),%edx # parameter, pointer to env
+ pushl (_JB_SIGMASK * 4)(%edx) /* mask from sc_mask */
pushl $3 /* how = SIG_SETMASK */
call 1f /* get our eip */
1: movl $(SYS_sigprocmask),%eax
@@ -92,19 +93,19 @@ ENTRY(longjmp)
addl $8,%esp
addl $__jmpxor-1b,%ecx # load cookie address
- movl 4(%esp),%edx
- movl 8(%esp),%eax
- movl 4(%edx),%ebx
- movl 8(%edx),%esi # load xor'ed esp into safe register
- xorl 0(%ecx),%esi # use esp cookie
- movl %esi, %esp # un-xor'ed esp is safe to use
- movl 12(%edx),%ebp
- xorl 4(%ecx),%ebp # use ebp cookie
- movl 16(%edx),%esi
- movl 20(%edx),%edi
+ movl 4(%esp),%edx # parameter, pointer to env
+ movl 8(%esp),%eax # parameter, val
+ movl (_JB_EBX * 4)(%edx),%ebx
+ movl (_JB_ESP * 4)(%edx),%esi
+ xorl 0(%ecx),%esi # use esp cookie
+ movl %esi,%esp # un-xor'ed esp is safe to use
+ movl (_JB_EBP * 4)(%edx),%ebp
+ xorl 4(%ecx),%ebp # use ebp cookie
+ movl (_JB_ESI * 4)(%edx),%esi
+ movl (_JB_EDI * 4)(%edx),%edi
movl 8(%ecx),%ecx # load eip cookie over cookie address
- xorl 0(%edx),%ecx
+ xorl (_JB_EIP * 4)(%edx),%ecx
testl %eax,%eax
jnz 1f
incl %eax
diff --git a/lib/libc/arch/i386/gen/sigsetjmp.S b/lib/libc/arch/i386/gen/sigsetjmp.S
index e27b7accf9a..8ab77e636e9 100644
--- a/lib/libc/arch/i386/gen/sigsetjmp.S
+++ b/lib/libc/arch/i386/gen/sigsetjmp.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: sigsetjmp.S,v 1.10 2016/05/30 02:11:21 guenther Exp $ */
+/* $OpenBSD: sigsetjmp.S,v 1.11 2020/12/06 15:31:30 bluhm Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -32,13 +32,14 @@
*/
#include "SYS.h"
+#include <machine/setjmp.h>
.global __jmpxor
ENTRY(sigsetjmp)
- movl 4(%esp),%ecx
- movl 8(%esp),%eax
- movl %eax,28(%ecx)
+ movl 4(%esp),%ecx # parameter, pointer to env
+ movl 8(%esp),%eax # parameter, savemask
+ movl %eax,(_JB_SIGFLAG * 4)(%ecx)
testl %eax,%eax
jz 1f
@@ -48,34 +49,34 @@ ENTRY(sigsetjmp)
movl $(SYS_sigprocmask),%eax
int $0x80 /* leave oset in %eax */
addl $12,%esp
- movl %eax,24(%ecx)
+ movl %eax,(_JB_SIGMASK * 4)(%ecx)
1: call 2f
2: popl %edx
addl $__jmpxor-2b,%edx # load cookie address
- movl %ebx, 4(%ecx)
- movl %esp, %eax
+ movl %ebx,(_JB_EBX * 4)(%ecx)
+ movl %esp,%eax
xorl 8(%edx),%eax # use esp cookie
- movl %eax, 8(%ecx)
- movl %ebp, %eax
+ movl %eax,(_JB_ESP * 4)(%ecx)
+ movl %ebp,%eax
xorl 0(%edx),%eax # use ebp cookie
- movl %eax,12(%ecx)
- movl %esi,16(%ecx)
- movl %edi,20(%ecx)
+ movl %eax,(_JB_EBP * 4)(%ecx)
+ movl %esi,(_JB_ESI * 4)(%ecx)
+ movl %edi,(_JB_EDI * 4)(%ecx)
movl 4(%edx),%edx # load eip cookie over cookie address
xorl 0(%esp),%edx
- movl %edx, 0(%ecx)
+ movl %edx,(_JB_EIP * 4)(%ecx)
xorl %eax,%eax
ret
END(sigsetjmp)
ENTRY(siglongjmp)
- movl 4(%esp),%edx
- cmpl $0,28(%edx)
+ movl 4(%esp),%edx # parameter, pointer to env
+ cmpl $0,(_JB_SIGFLAG * 4)(%edx)
jz 1f
- pushl 24(%edx) /* mask from sc_mask */
+ pushl (_JB_SIGMASK * 4)(%edx) /* mask from sc_mask */
pushl $3 /* how = SIG_SETMASK */
subl $4,%esp
movl $(SYS_sigprocmask),%eax
@@ -86,19 +87,19 @@ ENTRY(siglongjmp)
2: popl %ecx
addl $__jmpxor-2b,%ecx # load cookie address
- movl 4(%esp),%edx # reload in case sigprocmask failed
- movl 8(%esp),%eax
- movl 4(%edx),%ebx
- movl 8(%edx),%esi # load xor'ed esp into safe register
- xorl 8(%ecx),%esi # use esp cookie
- movl %esi, %esp # un-xor'ed esp is safe to use
- movl 12(%edx),%ebp
- xorl 0(%ecx),%ebp # use ebp cookie
- movl 16(%edx),%esi
- movl 20(%edx),%edi
+ movl 4(%esp),%edx # reload in case sigprocmask failed
+ movl 8(%esp),%eax # parameter, val
+ movl (_JB_EBX * 4)(%edx),%ebx
+ movl (_JB_ESP * 4)(%edx),%esi
+ xorl 8(%ecx),%esi # use esp cookie
+ movl %esi,%esp # un-xor'ed esp is safe to use
+ movl (_JB_EBP * 4)(%edx),%ebp
+ xorl 0(%ecx),%ebp # use ebp cookie
+ movl (_JB_ESI * 4)(%edx),%esi
+ movl (_JB_EDI * 4)(%edx),%edi
- movl 4(%ecx),%ecx # load eip cookie over cookie address
- xorl 0(%edx),%ecx
+ movl 4(%ecx),%ecx # load eip cookie over cookie address
+ xorl (_JB_EIP * 4)(%edx),%ecx
testl %eax,%eax
jnz 2f
incl %eax