1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-04 23:35:36 -08:00

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@
This commit is contained in:
kettenis 2020-07-14 16:48:13 +00:00
parent c39afc64dd
commit 874055c7f0
3 changed files with 11 additions and 6 deletions

View File

@ -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
};

View File

@ -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)

View File

@ -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)