Commit Graph

767 Commits

Author SHA1 Message Date
joerg e865ac2891 Move the pthread_once alias where it belongs. 2012-03-13 01:05:55 +00:00
joerg 77bfe129a9 Move pthread_once implementation into a separate file, it doesn't depend
on the mutex implementation in any way.
2012-03-12 21:35:10 +00:00
joerg d3660af7b6 Keep track of the size of the guard area, in case we want to make it
modifiable later. Only reuse the stack if it was allocated by libpthread
and if the expected thread size matches the current stack size.
2012-03-12 20:16:52 +00:00
joerg 1d34190ecc Further refine stack allocation. If the stack was provided by the user,
don't bother with setting up a guard page. Otherwise, round up the size
to page size. Point stack inside the guarded area, without the guard
page. Fix size when mprotect failed.
2012-03-12 16:37:15 +00:00
joerg fa060fc8c7 Fix error handling 2012-03-10 18:01:10 +00:00
joerg af435e468b Use correct size. 2012-03-10 18:01:09 +00:00
drochner 677d666c8d -fix initial stacksize rounding
-minor indentation fix
2012-03-09 12:06:44 +00:00
joerg 4acff4c01b Implement sem_timedwait. 2012-03-08 21:59:24 +00:00
joerg 344a231144 Actually use the stack thread attributes when creating a new thread. 2012-03-08 16:40:45 +00:00
joerg bfcb2008c8 Fix the stack base pointer for the initial thread on !HPPA.
AT_STACKBASE is pointing to the start of the stack, which is the
upper limit on platforms where the stack grows down.
2012-03-08 16:33:45 +00:00
joerg d1de8de689 Remove libpthread's semaphore implementation and always use the kernel
one. The implementation doesn't provide an async-safe sem_post and can't
without a lot of work on the pthread primitives.

Remove bogus time out requirement in test case, it should have been
a "known failure" if anything.
2012-03-07 23:31:44 +00:00
joerg d2be1428c2 Avoid getcontext() as it triggers clobbering warnings. Use inline
assembler to get the fields directly. Saves a system call as side
effect.
2012-03-02 23:19:47 +00:00
joerg 12529f382e Fix indentation. 2012-03-02 18:11:53 +00:00
joerg a56440951d Separate pthread_t from thread stack. Drop additional alignment
restrictions on the thread stack. Remove remaining parts of stackid.
2012-03-02 18:06:05 +00:00
joerg eab3272778 ld.elf_so is reentrant. 2012-02-03 21:11:17 +00:00
joerg 71d0bcc69f Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.
Require __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II as well as
__lwp_getprivate_fast / __lwp_gettcb_fast to exist for libpthread.
Define VAX as going to use TLS variant I, if it is ever implemented.
2012-01-17 20:34:57 +00:00
wiz 6533efb150 Do not xref to itself. 2011-12-05 10:27:40 +00:00
jym f3effc5ec2 Improvements in secmodel(9). Document secmodel_register(9), _deregister(9)
and _eval(9).

Add secmodel_extensions(9), and indicate the new sysctl(7) to let
ordinary users control the CPU affinity (user_set_cpu_affinity).
2011-12-04 21:08:37 +00:00
wiz 4a47c09250 Fix typo. 2011-11-10 16:44:47 +00:00
yamt 9c5d9163d1 document pthread_curcpu_np 2011-11-10 14:01:11 +00:00
christos 9924597a17 Include limits.h to get PTHREAD_KEYS_MAX, and move its definition there. 2011-10-06 16:03:48 +00:00
christos 0f48379f18 put back pthread__dbg variable; this is set to no zero by td_open() when
debugging to avoid multiple td_open() mess.
2011-10-02 18:18:56 +00:00
joerg 67f518f496 Use __dead 2011-09-16 16:05:58 +00:00
christos 5353040f23 document non-literal format strings 2011-08-16 10:35:03 +00:00
lukem eca6fe7e73 fix spello in comment 2011-08-05 03:55:31 +00:00
joerg 5c2887509e Don't kill the read(2) stub, just the magic around it. 2011-04-22 14:18:34 +00:00
joerg 77abb554dc Disable Fortification for pthread and rump stubs. 2011-04-21 13:38:14 +00:00
martin a128c5080b Backout previous, it causes lots of test failures (tests/fs/nfs for
example).
2011-04-21 08:17:00 +00:00
christos e6eca274ad Fix SSP builds (Vladimir Kirillov) 2011-04-12 19:49:48 +00:00
joerg 928f301be9 Rework TLS initialisation:
- Update TCB for the initial thread in pthread__initthread, not
  pthread__init to get it valid as soon as possible.
- Don't overwrite the pt_tls field in pthread__initthread.
- Don't deallocate pt_tls in pthread__scrubthread. This worked more by
  chance than by design.
- Handle freeing the TLS area in pthread_create after removing the
  thread instance from the dead queue.
2011-03-30 00:03:26 +00:00
matt def13dad30 Add __HAVE___LWP_GETTCB_FAST support (for mips and powerpc). 2011-03-17 00:43:48 +00:00
joerg 01eef02a1b If TLS support is present, use it for pthread__self(). The
initialisation order is correct in this case as _lwp_setprivate has been
called already by ld.elf_so for dynamic programs or _libc_init for
statically linked ones.
2011-03-16 12:39:44 +00:00
matt 71fdb89287 Use __lwp_gettcb_fast if present. 2011-03-12 07:46:29 +00:00
joerg aad599979d Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
2011-03-09 23:10:05 +00:00
joerg b7b592d544 Back out using the thread register (if present) for now.
libgcc_s's __register_frame_info gets called from libc's CSU code before
the libc constructors are run. __register_frame_info in turn calls
pthread_mutex_lock. libpthread is not initialised at this point and
therefore pthread__self() traps when deferencing the thread register.
This worked before because the garbage from pthread__self() is
effectively ignored.
2011-02-25 14:32:38 +00:00
joerg 1631a78097 Allow storing and receiving the LWP private pointer via ucontext_t
on all platforms except VAX and IA64. Add fast access via register for
AMD64, i386 and SH3 ports. Use this fast access in libpthread to replace
the stack based pthread_self(). Implement skeleton support for Alpha,
HPPA, PowerPC, SPARC and SPARC64, but leave it disabled.

Ports that support this feature provide __HAVE____LWP_GETPRIVATE_FAST in
machine/types.h and a corresponding __lwp_getprivate_fast in
machine/mcontext.h.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
2011-02-24 04:28:41 +00:00
christos 4ffe9a1805 make the code more re-usable 2011-01-26 18:48:57 +00:00
christos 74a83d351e Moving the ssp check inside the source code does not work properly because
the compiler loses information about the size of the object. So instead of
the hacky #define mess we did before, add a way to inject our function between
the user call and the system call.
2011-01-26 18:11:35 +00:00
christos 13fe5bd280 Fix SSP build.
XXX: This is gross.
2011-01-25 19:13:26 +00:00
christos c5d359be42 make pthread__sp unsigned long. 2011-01-25 19:12:04 +00:00
skrll f1d73a2c94 Add support for DF_1_BIND_NOW, DF_1_NODELETE and DF_1_NOOPEN marked
objects, and the RTLD_NODELETE and RTLD_NOLOAD flags to dlopen(3).

Mark libpthread as DF_1_NOOPEN and use it to test the functionality.

Somewhat taken from FreeBSD.

Fixes PR 42029.

OK from christos and joerg.
2010-12-24 12:41:42 +00:00
christos 736ce759b3 use pthread__stacksize since size has not been initialized yet. 2010-12-22 22:41:45 +00:00
christos 5cea6e6df8 only mprotect base if we moved it. 2010-12-22 22:19:46 +00:00
christos 66f16a1fa6 I've had this patch in my tree for a while and since it only improves
the situation, I decided to commit it. There is an inherent problem
with ASLR and the way the pthread library is using the thread stack.

Our pthread library chooses that stack for each thread strategically
so that it can locate the location of the pthread struct for each
thread by masking the stack pointer and looking just below the red
zone it creates. Unfortunately with ASLR you get many random values
for the initial stack, and there are situations where the masked
stack base ends up below the base of the stack. (this happens on
x86 when the stack base happens to be 0x???02000 for example and
your mask is stackmask is 0xffe00000). To fix this, we detect the
pathological cases (this happens only in the main thread), allocate
more stack, and mprotect it appropriately. Then we stash the main
base and the main struct, so that when we look for the pthread
struct in pthread__id, we can special case the main thread.

Another way to work around the problem is unlimiting stacksize,
but the proper way is to use TLS to find the thread structure and
not to play games with the thread stacks.
2010-12-18 15:54:27 +00:00
tron 103af04b49 Don't use internal libc function __findenv(). 2010-11-14 22:25:23 +00:00
skrll 162991256a Spell immediately correctly. 2010-11-02 20:49:47 +00:00
christos 5861d73fd7 move namespace protection before inclusion. 2010-08-06 15:21:50 +00:00
christos e8deba048f Add a weak alias for pthread_attr_get_np. Noted my Matthias Drochner. 2010-08-06 14:23:06 +00:00
wiz 6abd2b9ccc Fix typo. 2010-08-06 06:29:38 +00:00
christos ea1f852ab8 document pthread_getattr_np 2010-08-06 05:35:42 +00:00