summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2020-07-14 16:48:13 +0000
committerkettenis <kettenis@openbsd.org>2020-07-14 16:48:13 +0000
commit874055c7f02823920709838a1b984071d59cc88d (patch)
tree39bd5d19eb3aac1ddd25063263eef8849443f77f
parentgetopt(3) returns an int so don't use a char to store its return value. (diff)
downloadwireguard-openbsd-874055c7f02823920709838a1b984071d59cc88d.tar.xz
wireguard-openbsd-874055c7f02823920709838a1b984071d59cc88d.zip
Fix TIB/TCB on powerpc64. Some bright sould decided that the TCB should
be 8 bytes in the 64-bit ABI just like in the 32-bit ABI. But that means there is no "spare" word in the TCB that we can use to store a pointer to our struct pthread. So we have to treat powerpc64 special. Also recognize that the thread pointer points 0x7000 bytes after the TCB. Since the TCB is 8 bytes this means that TCB_OFFSET should be 0x7008. Pointed out by guenther@; ok deraadt@
-rw-r--r--include/tib.h7
-rw-r--r--lib/libc/arch/powerpc64/SYS.h6
-rw-r--r--sys/arch/powerpc64/include/tcb.h4
3 files changed, 11 insertions, 6 deletions
diff --git a/include/tib.h b/include/tib.h
index 8d9216f19dc..d901b54aa23 100644
--- a/include/tib.h
+++ b/include/tib.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tib.h,v 1.7 2019/05/10 13:29:21 guenther Exp $ */
+/* $OpenBSD: tib.h,v 1.8 2020/07/14 16:48:13 kettenis Exp $ */
/*
* Copyright (c) 2011,2014 Philip Guenther <guenther@openbsd.org>
*
@@ -143,8 +143,13 @@ struct tib {
int tib_canceled;
int tib_errno;
void *tib_locale;
+#ifdef __powerpc64__
+ void *tib_thread;
+ void *tib_dtv; /* internal to the runtime linker */
+#else
void *tib_dtv; /* internal to the runtime linker */
void *tib_thread;
+#endif
};
diff --git a/lib/libc/arch/powerpc64/SYS.h b/lib/libc/arch/powerpc64/SYS.h
index 60a41e370c5..b239fffc8ea 100644
--- a/lib/libc/arch/powerpc64/SYS.h
+++ b/lib/libc/arch/powerpc64/SYS.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: SYS.h,v 1.2 2020/06/26 17:58:45 kettenis Exp $ */
+/* $OpenBSD: SYS.h,v 1.3 2020/07/14 16:48:13 kettenis Exp $ */
/*-
* Copyright (c) 1994
* Andrew Cagney. All rights reserved.
@@ -47,9 +47,9 @@
/* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
-#define TCB_OFFSET_ERRNO (-12)
+#define TCB_OFFSET_ERRNO (-20)
/* from <powerpc64/tcb.h>: TCB address == %r13 - TCB_OFFSET */
-#define TCB_OFFSET 0x7000
+#define TCB_OFFSET 0x7008
/* offset of errno from %r13 */
#define R13_OFFSET_ERRNO (-TCB_OFFSET + TCB_OFFSET_ERRNO)
diff --git a/sys/arch/powerpc64/include/tcb.h b/sys/arch/powerpc64/include/tcb.h
index 72b25142a08..a57539d53a9 100644
--- a/sys/arch/powerpc64/include/tcb.h
+++ b/sys/arch/powerpc64/include/tcb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcb.h,v 1.3 2020/06/26 08:58:31 kettenis Exp $ */
+/* $OpenBSD: tcb.h,v 1.4 2020/07/14 16:48:13 kettenis Exp $ */
/*
* Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
@@ -32,7 +32,7 @@
#define TLS_VARIANT 1
/* powerpc offsets the TCB pointer 0x7000 bytes after the data */
-#define TCB_OFFSET 0x7000
+#define TCB_OFFSET 0x7008
register void *__tcb __asm__ ("r13");
#define TCB_GET() (__tcb)