plan9port/src/libthread
Russ Cox 8c573cab68 libthread: use mmap to allocate OpenBSD stacks
Should fix faults on OpenBSD.

Fixes #218.
Fixes #226.
2020-01-14 13:58:47 -05:00
..
test libthread: run first thread in proc on system stack 2020-01-12 15:08:28 -05:00
386-ucontext.h Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
BSD.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
channel.c libthread: fix nbrecvul, recvul to match man page, Plan 9 2020-01-13 17:00:58 -05:00
COPYING.SPARC64-CONTEXT sparc64 attempt 2006-02-10 05:32:42 +00:00
COPYRIGHT add wait 2006-02-12 16:48:50 +00:00
daemonize.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
Darwin-386-asm.s darwin 386 start 2006-04-21 03:34:44 +00:00
Darwin-386.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
Darwin-power-asm.s os x changes 2005-01-11 17:43:53 +00:00
Darwin-power.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
Darwin-x86_64-asm.s libthread: Lion context routines 2011-10-13 23:57:54 -04:00
Darwin-x86_64-swapcontext.c libthread: use mmap to allocate OpenBSD stacks 2020-01-14 13:58:47 -05:00
exec.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
FreeBSD-386-asm.s use macro for getcontext (setjmp) 2005-11-04 16:34:19 +00:00
FreeBSD.c new FreeBSD 2005-11-03 01:00:56 +00:00
ioproc.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
ioproc.h Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
iorw.c fix gcc 4.7 warnings (thanks Tuncer Ayaz) 2012-10-20 13:36:52 -04:00
Linux-386-asm.s better architecture splitting 2005-07-19 17:40:15 +00:00
Linux-arm-asm.s use macro for getcontext (setjmp) 2005-11-04 16:34:19 +00:00
Linux-arm-context.s libthread: context switching for arm, still not complete 2009-11-18 04:12:17 -05:00
Linux-arm-swapcontext.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
Linux-power-asm.s new 2005-08-22 16:56:28 +00:00
Linux-sparc64-asm.s set RFNOTEG when we can 2006-06-04 16:06:49 +00:00
Linux-sparc64-context.S more fix 2006-02-16 06:11:08 +00:00
Linux-sparc64-swapcontext.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
Linux.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
mkfile openbsd updates (thanks Pascal Stumpf) 2012-07-14 10:16:54 -04:00
NetBSD-386-asm.s better architecture splitting 2005-07-19 17:40:15 +00:00
NetBSD-power-asm.s Needed for NetBSD/macppc port. 2005-08-11 14:15:34 +00:00
NetBSD.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
OpenBSD-386-asm.s openbsd updates (thanks Pascal Stumpf) 2012-07-14 10:16:54 -04:00
OpenBSD-386.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
OpenBSD-power-asm.S openbsd updates (thanks Pascal Stumpf) 2012-07-14 10:16:54 -04:00
OpenBSD-power.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
OpenBSD-x86_64-asm.S openbsd updates (thanks Pascal Stumpf) 2012-07-14 10:16:54 -04:00
OpenBSD-x86_64.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
OpenBSD.c more strangeness (Tim Wiess) 2005-12-29 21:38:42 +00:00
power-ucontext.h Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
pthread.c stupid gcc 2005-02-03 15:41:39 +00:00
README.Linux explain nptl stuff 2005-01-18 18:14:14 +00:00
ref.c more new libthread 2004-12-25 21:57:50 +00:00
sparc-ucontext.h Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
stkmalloc.c libthread: use mmap to allocate OpenBSD stacks 2020-01-14 13:58:47 -05:00
stkmmap.c libthread: use mmap to allocate OpenBSD stacks 2020-01-14 13:58:47 -05:00
sysofiles.sh libthread: use mmap to allocate OpenBSD stacks 2020-01-14 13:58:47 -05:00
thread.c libthread: use mmap to allocate OpenBSD stacks 2020-01-14 13:58:47 -05:00
threadimpl.h libthread: use mmap to allocate OpenBSD stacks 2020-01-14 13:58:47 -05:00
wait.c Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
x86_64-ucontext.h Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00

Thread support on Linux is confused by the recent thread local storage (TLS)
support that has been put into the ELF tool chain.  The TLS libraries are 
installed in /lib/tls on most Linux systems.

We provide two different implementations of the os-dependent parts
of libthread for Linux.  The first is intended for use on Linux 2.4 and earlier
kernels, which do not support TLS.  It is in Linux.c and Linuxasm.c and
does not use the pthread interface.  The second is intended for Linux 2.6
and later kernels, which do support TLS.  It is in pthread.c and uses the
standard pthread interface.  It expects to be linked against the TLS-aware
thread library aka NPTL.

If you use Linux.c and Linuxasm.c with TLS libraries, they do not
set up the TLS properly so you will get incorrect programs.
For example, there will only be one errno among all the procs
in your program instead of one per proc.  The pthread NPTL
implementation is needed to use the TLS libraries properly.

If you use pthread.c without TLS libraries (i.e., with the old Linux
pthread library known as LinuxThreads), then you will also get
incorrect programs, although more obviously so.  The LinuxThreads
library assumes it can look at the stack pointer to distinguish between
threads, but libthread does its own stack management, breaking this
assumption.  If you run a pthread-compiled program with the 
LinuxThreads library, LinuxThreads itself will cause a segmentation
fault in __pthread_getspecific() the first time it is called from a
non-standard stack.

So, it is important that you compile binaries that match your
system's choice of TLS vs. not-TLS libraries.  The hard part is figuring
out which your system has chosen.  Plan9port looks at the kernel
version you are running and assumes that on kernels that support
TLS (2.6+) you will be using TLS.

Apparently Gentoo and maybe other distributions do not follow this rule.
They use non-TLS libraries even on kernels that can support TLS.
To accomodate them, you can add a line SYSVERSION=2.4 to $PLAN9/config
to force the build to think you are running an old kernel.
The INSTALL script sets up this file automatically on Linux systems.