Commit Graph

952 Commits

Author SHA1 Message Date
njoly 9be71c742b Fix man page ERRORS section for (clock,pthread}_getcpuclockid to match
reality.
2017-03-05 18:42:51 +00:00
njoly 5e0724b3f9 Fix {clock,pthread}_getcpuclockid to return an error number on
failure, to match OpenGroup specifications.
2017-03-04 11:16:33 +00:00
kamil 0892a29a1a libpthread_dbg(3) deletion from the base distribution
libpthread_dbg(3) is a remnant library from the M:N thread model
(pre-NetBSD-5.0) API to introspect threads within a process and for use
of debuggers.

Currently in the 1:1 model it's not used in GDB neither in LLDB and it's
not either planned to be used. It's current function to read pthread_t
structures is realizable within a regular debugger capable to
instrospect objects within a tracee (GDB, LLDB...).

Remaining users of this API can still use this library from
pkgsrc/devel/libpthread_dbg.

Sponsored by <The NetBSD Foundation>
2017-02-08 03:44:40 +00:00
njoly cada2c18c7 Fix a typo : pthread_mutexaddr_init -> pthread_mutexattr_init. 2017-02-02 10:48:22 +00:00
wiz fe65e38bd3 Bump date for previous. 2016-11-24 12:19:28 +00:00
kamil 6c74bd40be Add reference in SEE ALSO to pthread_dbg(3)
Sponsored by <The NetBSD Foundation>
2016-11-22 00:32:09 +00:00
christos 6e03f6000c Don't spin if we already own the mutex, otherwise we will get stuck spinning
forever, fixes timemutex{1,2} tests.
2016-10-31 23:53:12 +00:00
kamil 06b9d77598 POSIX harder the pthread_mutex_timedlock(3) prototype
Add missing __restrict keyword to the first pointer parameter.

It was already used for the second argument, should not be a functional
change and generated code should be the same.

This new form is now aligned with POSIX.
2016-10-30 23:26:33 +00:00
christos 285a8995e1 unnamed unions need special treatment since they need braced initializers
for old style initializations.
2016-07-20 21:02:04 +00:00
christos 353946982c cplusplus does not like complex named initializers... 2016-07-20 20:06:04 +00:00
christos b826eda4de use named initializers 2016-07-20 19:26:52 +00:00
skrll 3b2c691c07 Use anonymous union for ptm_ceiling and old __pthread_spin_t field to
maintain backward compatibility and fix hppa build.  hppa has an non-
integer type __pthread_spin_t
2016-07-17 13:49:43 +00:00
skrll d946c609af KNF 2016-07-16 12:58:11 +00:00
wiz b9737c740d Fix some lint.
Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
2016-07-05 10:04:17 +00:00
christos 7cf7644fc7 GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
2016-07-03 14:24:58 +00:00
wiz a0a33836af Formatting, typos, whitespace fixes. 2016-04-24 09:01:45 +00:00
christos 3c50b65c77 commit the right file. 2016-04-24 00:05:28 +00:00
christos ed7dbad892 bump 2016-04-23 23:23:17 +00:00
christos d394d2a9b5 Add pthread_getcpuclockid(3) 2016-04-23 23:12:19 +00:00
dholland eb0c9743f2 _SC_PAGESIZE is not the page size; it's a symbolic code for retrieving
the page size.
2016-04-07 06:21:48 +00:00
pooka 01d7ebdd80 Fix PTHREAD_FOO_INITIALIZER for C++ by not using volatile in the relevant
pthread types in C++ builds, attempt 2.

The problem with attempt 1 was making assumptions of what the MD
__cpu_simple_lock_t (declared volatile) looks like.  To get a same type
except non-volatile, we change the MD type to __cpu_simple_lock_nv_t
and typedef __cpu_simple_lock_t as a volatile __cpu_simple_lock_nv_t.
IMO, __cpu_simple_lock_t should not be volatile at all, but changing it
now is too risky.

Fixes at least Rumprun w/ gcc 5.1/5.2.  Furthermore, the mpd application
(and possibly others) will no longer require NetBSD-specific patches.

Tested: build.sh for i386, Rumprun for x86_64 w/ gcc 5.2.

Based on the patch from Christos in lib/49989.
2015-08-27 12:30:50 +00:00
pooka 2d85d43b0f Revert 1.14 now that the arduous task of fixing rumphijack to allow
mmap() in early init has been completed.
2015-08-25 13:46:23 +00:00
pooka a83d5ed5dd Rev 1.14 was nice except it didn't work with _INITIALIZER, which
sort of negates the whole point ... so revert everything while in
drawing board mode.
2015-06-26 11:25:22 +00:00
pooka 24bdf1ef99 Don't depend on __CPU_SIMPLE_LOCK_PAD to determine the type of
__cpu_simple_lock_t (because it doesn't).  Instead, use sizeof/alignof
with a struct { uchar[] }.

Fixes problem in previous commit, caught by Nick Hudson.
2015-06-26 10:05:17 +00:00
pooka 7cc7e65751 C++ (namely libc++) expects to be using PTHREAD_FOO_INITIALIZER as a
member initializer. This does not work for volatile types. Since C++
does not touch the guts of those types, redefine them as non-volatile.

Fixes libc++ compilation with g++ 5.1, as reported in PR lib/49989.
2015-06-26 01:33:08 +00:00
christos 8c0cb8e7ec Thanks rump for not letting us use even mmap during initialization. 2015-05-30 14:42:26 +00:00
wiz dbea196857 Bump date for previous.
New sentence, new line.
2015-05-29 18:00:51 +00:00
christos cb27e6553e Fix previous: Can't use calloc/malloc before we complete initialization
of the thread library, because malloc uses pthread_foo_specific, and it will
end up initializing itself incorrectly.
2015-05-29 16:05:13 +00:00
manu 841339f07f Make PTHREAD_KEYS_MAX dynamically adjustable
NetBSD's PTHREAD_KEYS_MAX is set to 256, which is low compared to
other systems like Linux (1024) or MacOS X (512). As a result some
setups tested on Linux will exhibit problems on NetBSD because of
pthread_keys usage beyond the limit. This happens for instance on
Apache with various module loaded, and in this case no particular
developper can be blamed for going beyond the limit, since several
modules from different sources contribute to the problem.

This patch makes the limit conigurable through the PTHREAD_KEYS_MAX
environement variable. If undefined, the default remains unchanged
(256). In any case, the value cannot be lowered below POSIX-mandated
_POSIX_THREAD_KEYS_MAX (128).

While there:
- use EXIT_FAILURE instead of 1 when calling err(3) in libpthread.
- Reset _POSIX_THREAD_KEYS_MAX to POSIX mandated 128, instead of 256.
2015-05-29 07:37:31 +00:00
martin f89f6560d4 Dummy ia64 support 2015-04-17 13:14:19 +00:00
matt b12144c585 We have _REG_SP so use it. 2015-03-31 01:36:27 +00:00
pooka aa91aeb3c8 include correct header for "last minute just-in-case defensive addition
that's too trivial to check"
2014-12-17 01:49:08 +00:00
pooka 082d249a16 Allow for arbitrary MI scheduler implementations.
A concrete result is enabling unpatched libpthread to run on the
rumprun stacks (e.g. Xen and bare metal) with a non-NetBSD scheduler.
Those schedulers hook into the existing _lwp_frobnitz() NetBSD syscall
interfaces (well, "syscall" interfaces in that scenario ;)

More specifically about the change itself:

1) instead of calling _lwp_makecontext() followed by _lwp_create()
   and passing the entry point in ucontext_t (MD) through the calls, roll
   the calls into pthread__makelwp() and allow alternate implementations
   for that MI interface.

2) allow compile-time overriding of __lwp_gettcb_fast() or
   __lwp_getprivate_fast, which are inline and leak MD scheduler/thread
   details into libpthread


Additionally, two small nits:

I)  define LIB=pthread before including mk.conf so that it's possible
    to test for LIB==pthread in mk.conf

II) make it possible to leave out pthread_cancelstub.c.  This is required
    by the current implementation of rumprun-posix (i.e. rumprun on
    POSIX hosts) due to symbol collisions.  It needs to be fixed properly
    some day, but for now allows an almost-correct libpthread to run.
    I am sure @justin will be happy to explain the details ;)


no change to NetBSD
tested: anita+atf
2014-12-16 20:05:54 +00:00
matt 6cf6fe02a9 New files for Userland support of UCB RISC-V (both 32-bit and 64-bit) 2014-09-19 17:36:24 +00:00
matt 27620987b8 New files for OR1K support 2014-09-03 19:34:25 +00:00
matt 11614bb2b2 MKCOMPAT fixes for when compat MACHINE_CPU != normal MACHINE_CPU 2014-08-10 23:25:49 +00:00
matt beb9c6d1b5 Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.
2014-08-10 05:47:35 +00:00
riastradh 6cb10275d0 Merge riastradh-drm2 to HEAD. 2014-03-18 18:20:35 +00:00
dholland 1e9d60e3bf typo 2014-03-12 07:32:46 +00:00
matt 1de2b6f186 This is no different from the 32bit powerpc one.
Remove the redundancy.
2014-03-07 07:26:42 +00:00
rmind 2e17c78b61 pthread__mutex_lock_slow: fix the handling of a potential race with the
non-interlocked CAS in the fast unlock path -- it is unsafe to test for
the waiters-bit while the owner thread is running, we have to spin for
the owner or its state change to be sure about the presence of the bit.
Split off the logic into the pthread__mutex_setwaiters() routine.

This is a partial fix to the named lockup problem (also see PR/44756).
It seems there is another race which can be reproduced on faster CPUs.
2014-02-03 15:51:01 +00:00
christos cdce479a47 remove compatibility code for handling CLOCK_MONOTONIC and handle it in the
syscall directly.
2014-01-31 20:44:01 +00:00
christos de79b4937c PR/44756: Sad Clouds: Prevent leakage of errno = ESRCH from _lwp_park. This
has two parts:
	- in pthread_cond_timedwait() if the thread we are trying to unpark
	  exited, retry the the _lwp_park call without it.
	- pthread_mutex() was affecting errno since it is calling _lwp_park()
	  from pthread_mutex_lock_slow(). preserve the original errno.
Note that the example problem still causes an occassional deadlock on machines
with many CPUs and it is the same deadlock we observe with named.
2014-01-31 19:22:00 +00:00
matt fa741d8823 Use MACHINE_CPU for m68k. Use similar logic for both tests. 2013-10-09 22:33:41 +00:00
matt 06cb4b73b7 Add support for an optional ARCHSUBDIR/Makefile.inc 2013-08-15 22:38:24 +00:00
matt 77f07e0bd7 Use the thumb1 versions of sev/wfe for thumb && armv6+.
if using armv5t don't do anything for thumb.
2013-08-15 22:37:29 +00:00
joerg a6c6eb019c Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.
2013-08-12 17:15:46 +00:00
wiz a5684d07dd Use Mt for email addresses. 2013-07-20 21:39:55 +00:00
christos 53c7ca1dc2 s/inherited/inherit/ 2013-05-10 21:06:14 +00:00
christos bbae94036a bump for pthread_cond_setclock 2013-04-03 15:45:21 +00:00
christos 5ef4443346 for safety, declare mono on the outermost block it is used. 2013-04-01 13:28:21 +00:00
christos 1f8d3d6eb5 PR/47703: Yasushi Oshima: pthread_cond_timedwait() does not wait
after call pthread_condattr_setclock(CLOCK_MONOTONIC)

_lwp_park(2) expects a realtime clock, and it gets passed a monotonic
one.  Since monotonic < real, it never sleeps. This patch adjusts
the monotonic clock to be a real one before it passes is to
_lwp_park(2). This is the minimal hacky fix and it will be fixed
properly in _lwp_park(2) in the future.

XXX: pullup to 6.
2013-03-28 18:07:12 +00:00
christos 71d484f921 - Allow libpthread to be dlopened again, by providing libc stubs to libpthread.
- Fail if the dlopened libpthread does pthread_create(). From manu@
- Discussed at length in the mailing lists; approved by core@
- This was chosen as the least intrusive patch that will provide
  the necessary functionality.
XXX: pullup to 6
2013-03-21 16:49:11 +00:00
yamt a74bc62145 add comments
whitespace
2013-03-06 11:31:34 +00:00
yamt 93af5b695c add assertions 2013-03-06 11:30:56 +00:00
apb 6cee3c7cf5 Explain what PTHREAD__COMPAT is for. This comment in
src/libpthread/Makefile is adated from a comment in
src/doc/CHANGES.prev.
2013-02-25 17:04:46 +00:00
riastradh d86328195e Add pthread_condattr_setclock(3) man page link. 2013-01-31 20:57:58 +00:00
dsl 2bf5f9db37 Don't rely on sys/lwp.h includeing sys/resource.h for us. 2013-01-01 18:42:39 +00:00
christos fe230c9d39 Don't call the destructor in pthread_key_delete() following the standard. 2012-11-22 08:32:36 +00:00
christos 55f47ec332 Replace the simple implementation of pthread_key_{create,destroy}
and pthread_{g,s}etspecific functions, to one that invalidates
values of keys in other threads when pthread_key_delete() is called.
This fixes chromium, which expects pthread_key_delete() to do
cleanup in all threads.
2012-11-21 19:19:24 +00:00
christos cb292d56ab add argsused 2012-11-14 23:25:05 +00:00
uwe ed34834025 Mark up (unsupported) PTHREAD_PROCESS_SHARED with .Dv macro. 2012-11-12 23:34:50 +00:00
uwe 7fe27706ff Refer to init_routine in the DESCRIPTION section with .Fa instead of .Fn 2012-11-12 23:28:11 +00:00
uwe b5c99d4306 Use
.Vt type var No = Dv INITIALIZER;

to provide examples of static initialization in SYNOPSIS section.
.Va macro does the wrong thing (check groff PostScript output) and the
need for .Pp kludge (now dropped) should have been an indication too.

While here move static initialization example to be right after the
declaration of *_init().
2012-11-12 23:11:05 +00:00
uwe b89e4203ae Each get function "has" a set counterpart, it doesn't "contain" it. 2012-11-10 23:12:36 +00:00
apb 9d94c0263d Remove duplicate "const" modifier found by clang -Wduplicate-decl-specifier 2012-11-06 09:03:03 +00:00
rmind d79b47c370 libpthread: replace the use of obsolete sys/tree.h interface with rbtree(9). 2012-11-03 23:42:27 +00:00
wiz 2268525138 Fix pasto. 2012-11-03 09:20:36 +00:00
christos 2a29ccd3da add pthread_condattr_setclock(3) 2012-11-03 03:10:50 +00:00
christos 284dc1a8fd cast return of sysconf 2012-11-03 03:10:35 +00:00
matt 8837651bdf Use .inst instead of wfe/sev to shut up gas. 2012-09-19 07:57:14 +00:00
matt 426a76190c Only copy the ucontext_t in pthread_setcontext if _UC_TLSBASE is set.
Conditionalize the test on _UC_TLSBASE being defined.
2012-09-12 14:55:48 +00:00
manu bba80928a8 setcontext() used to be incompatible with -lpthread since it affected
the TLS pointer, therefore wrecking the pthread environement.

Some ports had _UC_TLSBASE flag or equivalent (_UC_UNIQUE on alpha)
that controlled whether setcontext() would change the TLS pointer.
This change let libpthread override setcontext() with its own version
that unsets _UC_TLSBASE, enabling safe usage of setcontext() with
-lpthread.

We also have the following required changes here:
- rename alpha's _UC_UNIQUE into _UC_TLSBASE
- add _UC_TLSBASE definition in header file for all ports
  (powerpc, sh3, sparc and sparc64 lack the implementation for now)
- introduce a libc stub that can be overriden for setcontext()
- modify MD libcs swapcontext() implementations so that they use the
  setcontext() libc stub instead of doing a plain system call.

While we are there:
- document various MD _UC_* flags in header file
- add libc and libpthread tests for swapcontext() behavior
  (hopefully helpful to spot MD problems introduced with this change)

Future work:
- Deciding whether kernel support or _UC_TLSBASE should be added for
  powerpc, sh3, sparc and sparc64 is left to portmasters
  sparc64

Approved by core@
2012-09-12 02:00:51 +00:00
matt 2f1e74f8c5 Add a pthread__smt_wake and add support for it on arm along with
pthread__smt_pause.  These are implemented using the ARM instructions
SEV (wake) and WFE (pause).  These are treated as NOPs on ARM CPUs that
don't support them.
2012-08-16 04:49:47 +00:00
drochner b0ce37c2b0 return errno if pthread_create hits the system limit, not just -1
(this is not entirely correct because it can return ENOMEM which is
not mentioned in the spec, but there are other places in pthread_create
whete ENOMEM is returned -- it at all, this should be fixed everywhere)
2012-08-15 13:28:32 +00:00
matt 234b053454 -Wfoo goes into CWARNFLAGS 2012-08-04 15:13:09 +00:00
joerg 0645d95b42 Prefer sysconf to obtain number of CPUs. 2012-08-02 12:43:41 +00:00
joerg 74a7f3e6f2 Do not mark pthread_cond_timedwait explicitly as inlineable, since it
calls pthread__self, which is static.
2012-06-15 19:20:44 +00:00
joerg 8050d45d71 Simplify check for TLS definition to not hide code. Drop it in another
place as it is redundant.
2012-05-04 12:26:33 +00:00
enami 3cdda33922 Store allocated lwpctl state in the thread actually forked,
which is the only thread lives in the child process.

The problem originally reported here:
  https://bugs.ruby-lang.org/issues/6341
2012-04-26 00:21:44 +00:00
christos 5662c2716e trailing whitespace police. 2012-04-04 17:47:03 +00:00
joerg b757af438b Disable new -Wstring-plus-int warning where needed for now.
Adjust various places that add GCC-only options to check for the active
compiler first.
2012-04-04 10:59:44 +00:00
agc 76f4f39125 Add a pthread cancel stub for sigwait, following Onno van der Linden's
analysis in PR 45131.  Kindly tested by Hisashi T Fujinaka (using csup
as the test case) with a successful outcome.

OK martin@
2012-04-04 06:29:16 +00:00
drochner e917deee9c don't reuse a dynamically allocated stack if a fixed one is requested 2012-03-22 20:01:18 +00:00
matt fa835e8c8b These directories default to WARNS?=5 2012-03-21 05:37:42 +00:00
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
christos f6cf46930e make kevent(2) a cancelation point, and document properly all the cancelation
points we currently support.
2010-08-06 05:25:46 +00:00
christos 32d8a48951 Add pthread_getattr_np() 2010-08-06 05:25:02 +00:00
wiz 4d7c45167f Sort sections. 2010-07-09 20:58:38 +00:00
wiz bb4a6891d0 Fix typo. 2010-07-09 20:56:01 +00:00
jruoho b46f888960 Add a compatibility note. Also some minor improvements. 2010-07-09 18:16:31 +00:00
jruoho be670be457 Update ERRORS, tidy SEE ALSO. 2010-07-09 18:07:20 +00:00
jruoho 267d79598f Rearrange, reword, clarify. Remove duplicate paragraphs and recurring
sentences. Update the ERRORS to reflect reality in NetBSD.
2010-07-09 18:01:53 +00:00
jruoho bc665d2683 Re-add EINVAL for pthread_condattr_destroy(3) (misread the pthread__error()). 2010-07-09 17:54:08 +00:00
jruoho e328c0292c Note also alignment via mmap(2), as done in NetBSD. 2010-07-09 17:15:59 +00:00
jruoho c42287d313 As per (now closed) PR lib/43581, add a note about unsupported modifications
to the red zone size.
2010-07-09 17:03:04 +00:00
jruoho dd981aaaa6 Remove error conditions. Add CAVEATS to note the questionable value of the
functions in NetBSD, which does not support additional condition attributes.
Note that these do not conform to SUSv4, where two additional attributes are
mandated.
2010-07-09 16:54:30 +00:00
jruoho 4ec5f0283b Use .Ss for non-standard subtitle. 2010-07-09 12:00:38 +00:00
jruoho 10bc8c491b Rewrite this for clarity. Also remove AUTHORS; someone was proud enough to
put himself as the author, even though the page was directly cut-and-pasted
from the Open Group's specification.
2010-07-09 11:03:26 +00:00
jruoho 70d17355ab Add missing prototypes. Noted by wiz@ -- thanks. 2010-07-09 10:55:57 +00:00
wiz 83d2a68694 Mark up NULL. 2010-07-09 10:55:11 +00:00