Rich Felker [Thu, 10 Mar 2011 23:31:37 +0000 (18:31 -0500)]
optimize pthread termination in the non-detached case
we can avoid blocking signals by simply using a flag to mark that the
thread has exited and prevent it from getting counted in the rsyscall
signal-pingpong. this restores the original pthread create/join
throughput from before the sigprocmask call was added.
Rich Felker [Thu, 10 Mar 2011 23:26:29 +0000 (18:26 -0500)]
fix errors in sigqueue (potential information leak, wrong behavior)
1. any padding in the siginfo struct was not necessarily zero-filled,
so it might have contained private data off the caller's stack.
2. the uid and pid must be filled in from userspace. the previous
rsyscall fix broke rsyscalls because the values were always incorrect.
Rich Felker [Thu, 10 Mar 2011 16:59:39 +0000 (11:59 -0500)]
security fix: check that cancel/rsyscall signal was sent by the process itself
Rich Felker [Thu, 10 Mar 2011 16:06:50 +0000 (11:06 -0500)]
more cancellation points: tcdrain, clock_nanosleep
Rich Felker [Thu, 10 Mar 2011 16:02:29 +0000 (11:02 -0500)]
remove useless return value checks for functions that cannot fail
Rich Felker [Thu, 10 Mar 2011 16:01:11 +0000 (11:01 -0500)]
make sigsuspend a cancellation point
Rich Felker [Thu, 10 Mar 2011 15:59:50 +0000 (10:59 -0500)]
make sigtimedwait a cancellation point
Rich Felker [Thu, 10 Mar 2011 15:43:09 +0000 (10:43 -0500)]
don't fail with EINTR in sigtimedwait
POSIX allows either behavior, but sigwait is not allowed to fail with
EINTR, so the retry loop would have to be in one or the other anyway.
Rich Felker [Thu, 10 Mar 2011 15:26:16 +0000 (10:26 -0500)]
fix sigsuspend syscall
Rich Felker [Thu, 10 Mar 2011 15:17:29 +0000 (10:17 -0500)]
make sigaltstack work (missing macros in signal.h, error conditions)
Rich Felker [Thu, 10 Mar 2011 14:54:23 +0000 (09:54 -0500)]
fix errno behavior in clock_* functions
these functions are specified inconsistent in whether they're
specified to return an error value, or return -1 and set errno.
hopefully now they all match what POSIX requires.
Rich Felker [Thu, 10 Mar 2011 01:31:06 +0000 (20:31 -0500)]
fix error handling for pthread_sigmask
it must return errno, not -1, and should reject invalud values for how.
Rich Felker [Thu, 10 Mar 2011 01:23:44 +0000 (20:23 -0500)]
make fork properly initialize the main thread in the child process
Rich Felker [Thu, 10 Mar 2011 01:21:23 +0000 (20:21 -0500)]
optimize pthread initialization
the set_tid_address returns the tid (which is also the pid when called
from the initial thread) so there is no need to make a separate
syscall to get pid/tid.
Rich Felker [Thu, 10 Mar 2011 01:07:24 +0000 (20:07 -0500)]
fix race condition in raise - just mask signals
a signal handler could fork after the pid/tid were read, causing the
wrong process to be signalled. i'm not sure if this is supposed to
have UB or not, but raise is async-signal-safe, so it probably is
allowed. the current solution is slightly expensive so this
implementation is likely to be changed in the future.
Rich Felker [Thu, 10 Mar 2011 00:42:06 +0000 (19:42 -0500)]
fix raise semantics with threads.
Rich Felker [Tue, 8 Mar 2011 22:34:26 +0000 (17:34 -0500)]
fix typos in dirent.h
Rich Felker [Tue, 8 Mar 2011 17:35:35 +0000 (12:35 -0500)]
fcntl.h should make availabel the mode constants from sys/stat.h
also remove some legacy nonsense that crept in.
Rich Felker [Tue, 8 Mar 2011 17:20:10 +0000 (12:20 -0500)]
simplify and optimize pthread_mutex_trylock
Rich Felker [Tue, 8 Mar 2011 17:19:30 +0000 (12:19 -0500)]
rwlock trylock functions were wrongly returning EAGAIN instead of EBUSY
Rich Felker [Tue, 8 Mar 2011 17:08:40 +0000 (12:08 -0500)]
fix major breakage in pthread_once (it was always deadlocking)
the issue was a break statement that was breaking only from the
switch, not the enclosing for loop, and a failure to set the final
success state.
Rich Felker [Tue, 8 Mar 2011 08:41:05 +0000 (03:41 -0500)]
fix and optimize non-default-type mutex behavior
problem 1: mutex type from the attribute was being ignored by
pthread_mutex_init, so recursive/errorchecking mutexes were never
being used at all.
problem 2: ownership of recursive mutexes was not being enforced at
unlock time.
Rich Felker [Tue, 8 Mar 2011 07:33:37 +0000 (02:33 -0500)]
implement pthread_mutexattr_[gs]etpshared functions
Rich Felker [Tue, 8 Mar 2011 07:32:42 +0000 (02:32 -0500)]
disallow cpu time clocks as condattr clock values
Rich Felker [Mon, 7 Mar 2011 23:32:36 +0000 (18:32 -0500)]
add macros for use with d_type extension field in dirent
Rich Felker [Mon, 7 Mar 2011 23:09:24 +0000 (18:09 -0500)]
fix off-by-one error in sem_(timed)wait (using old sem value instead of new)
Rich Felker [Mon, 7 Mar 2011 22:39:13 +0000 (17:39 -0500)]
use the selected clock from the condattr for pthread_cond_timedwait
Rich Felker [Mon, 7 Mar 2011 21:45:48 +0000 (16:45 -0500)]
add prototypes for pthread_condattr_* and pthread_rwlockattr_*
Rich Felker [Mon, 7 Mar 2011 21:43:25 +0000 (16:43 -0500)]
implement pthread_rwlockattr_* (essentially no-ops)
Rich Felker [Mon, 7 Mar 2011 21:20:12 +0000 (16:20 -0500)]
implement pthread_condattr_* interfaces
note that, while the attributes are stored, they are not used in
pthread_cond_init yet.
Rich Felker [Mon, 7 Mar 2011 20:46:37 +0000 (15:46 -0500)]
reject invalid attribute settings
note that this is a pedantic conformance issue and waste of code. it
only affects broken code or code that is probing for conformance.
Rich Felker [Mon, 7 Mar 2011 20:42:52 +0000 (15:42 -0500)]
implement barrier attribute functions (essentially no-ops)
Rich Felker [Fri, 4 Mar 2011 05:59:14 +0000 (00:59 -0500)]
enforce stack size min in pthread_attr_setstacksize
Rich Felker [Fri, 4 Mar 2011 05:45:59 +0000 (00:45 -0500)]
implement POSIX semaphores
Rich Felker [Thu, 3 Mar 2011 23:32:26 +0000 (18:32 -0500)]
preliminaries to adding POSIX semaphores
Rich Felker [Thu, 3 Mar 2011 23:30:44 +0000 (18:30 -0500)]
optimize POSIX TSD for fast pthread_getspecific
Rich Felker [Thu, 3 Mar 2011 05:32:15 +0000 (00:32 -0500)]
namespace cleanup in sys/mman.h
Rich Felker [Thu, 3 Mar 2011 05:30:31 +0000 (00:30 -0500)]
implement POSIX shared memory
Rich Felker [Tue, 1 Mar 2011 17:04:36 +0000 (12:04 -0500)]
use -L/...../ -lgcc instead of /...../libgcc.a in musl-gcc wrapper
this should avoid warnings about unused libs when not linking, and
might fix some other obscure issues too. i might replace this approach
with a completely different one soon though.
Rich Felker [Tue, 1 Mar 2011 16:57:19 +0000 (11:57 -0500)]
depends on settimeofday which needs _GNU_SOURCE feature test
Rich Felker [Sun, 27 Feb 2011 08:48:57 +0000 (03:48 -0500)]
implement futimens and utimensat
Rich Felker [Sun, 27 Feb 2011 08:48:19 +0000 (03:48 -0500)]
cleanup namespace in sys/time.h
Rich Felker [Sun, 27 Feb 2011 07:59:23 +0000 (02:59 -0500)]
implement fexecve
Rich Felker [Sun, 27 Feb 2011 05:28:59 +0000 (00:28 -0500)]
cleanup utf-8 multibyte code, use visibility if possible
this code was written independently of musl, with support for a the
backwards, nonstandard "31-bit unicode" some libraries/apps might
want. unfortunately the extra code (inside #ifdef) makes the source
harder to read and makes code that should be simple look complex, so
i'm removing it. anyone who wants to use the old code can find it in
the history or from elsewhere.
also, change the visibility of the __fsmu8 state machine table to
hidden, if supported. this should improve performance slightly in
shared-library builds.
Rich Felker [Sun, 27 Feb 2011 04:50:26 +0000 (23:50 -0500)]
fix missing prototype for strsignal
Rich Felker [Thu, 24 Feb 2011 21:37:21 +0000 (16:37 -0500)]
various changes in preparation for dynamic linking support
prefer using visibility=hidden for __libc internal data, rather than
an accessor function, if the compiler has visibility.
optimize with -O3 for PIC targets (shared library). without heavy
inlining, reloading the GOT register in small functions kills
performance. 20-30% size increase for a single libc.so is not a big
deal, compared to comparaible size increase in every static binaries.
use -Bsymbolic-functions, not -Bsymbolic. global variables are subject
to COPY relocations, and thus binding their addresses in the library
at link time will cause library functions to read the wrong (original)
copies instead of the copies made in the main program's bss section.
add entry point, _start, for dynamic linker.
Rich Felker [Thu, 24 Feb 2011 17:36:04 +0000 (12:36 -0500)]
apply feature test protection to memccpy
Rich Felker [Thu, 24 Feb 2011 17:35:42 +0000 (12:35 -0500)]
add implementation of memccpy function
Rich Felker [Thu, 24 Feb 2011 17:34:31 +0000 (12:34 -0500)]
fix backwards conditional in stpncpy
this only made the function unnecessarily slow on systems with
unaligned access, but would of course crash on systems that can't do
unaligned accesses (none of which have ports yet).
Rich Felker [Tue, 22 Feb 2011 22:11:35 +0000 (17:11 -0500)]
rewind must clear the error indicator in addition to seeking
Rich Felker [Tue, 22 Feb 2011 04:00:52 +0000 (23:00 -0500)]
change errno to static linkage (improves PIC code generation)
Rich Felker [Tue, 22 Feb 2011 03:27:35 +0000 (22:27 -0500)]
cleanup comment cruft in startup code
Rich Felker [Tue, 22 Feb 2011 03:26:31 +0000 (22:26 -0500)]
make startup code PIE-compatible
Rich Felker [Mon, 21 Feb 2011 20:43:26 +0000 (15:43 -0500)]
remove sample utf-8 code that's not part of the standard library
Rich Felker [Mon, 21 Feb 2011 03:30:06 +0000 (22:30 -0500)]
use an accessor function for __libc data pointer when compiled as PIC
prior to this change, a large portion of libc was unusable prior to
relocation by the dynamic linker, due to dependence on the global data
in the __libc structure and the need to obtain its address through the
GOT. with this patch, the accessor function __libc_loc is now able to
obtain the address of __libc via PC-relative addressing without using
the GOT. this means the majority of libc functionality is now
accessible right away.
naturally, the above statements all depend on having an architecture
where PC-relative addressing and jumps/calls are feasible, and a
compiler that generates the appropriate code.
Rich Felker [Mon, 21 Feb 2011 03:24:28 +0000 (22:24 -0500)]
avoid referencing address of extern function from vdprintf
this change is in preparation for upcoming PIC/shared library support.
the intent is to avoid going through the GOT, mainly so that dprintf
is operable immediately, prior to processing of relocations. having
dprintf accessible from the dynamic linker will make writing and
debugging the dynamic linker much easier.
Rich Felker [Mon, 21 Feb 2011 00:07:19 +0000 (19:07 -0500)]
shave off 2 bytes from crt1.o _start
Rich Felker [Sun, 20 Feb 2011 22:19:37 +0000 (17:19 -0500)]
cleanup asprintf stuff
Rich Felker [Sun, 20 Feb 2011 22:17:09 +0000 (17:17 -0500)]
prototypes for GNU asprintf/vasprintf
Rich Felker [Sun, 20 Feb 2011 22:10:40 +0000 (17:10 -0500)]
fix %n specifier, again. this time it was storing the wrong value.
Rich Felker [Sun, 20 Feb 2011 21:34:10 +0000 (16:34 -0500)]
include sys/sysmacros.h from sys/types.h when _GNU_SOURCE is defined
Rich Felker [Sun, 20 Feb 2011 21:21:39 +0000 (16:21 -0500)]
fix typo in inotify structure
Rich Felker [Sun, 20 Feb 2011 21:16:33 +0000 (16:16 -0500)]
make malloc(0) return unique pointers rather than NULL
this change is made with some reluctance, but i think it's for the
best. correct programs must handle either behavior, so there is little
advantage to having malloc(0) return NULL. and i managed to actually
make the malloc code slightly smaller with this change.
Rich Felker [Sun, 20 Feb 2011 21:12:09 +0000 (16:12 -0500)]
fix simple_malloc malloc(0) behavior not to return non-unique pointers
Rich Felker [Sun, 20 Feb 2011 21:10:38 +0000 (16:10 -0500)]
fix simple_malloc size restrictions
do not allow allocations that overflow ptrdiff_t; fix some overflow
checks that were not quite right but didn't matter due to address
layout implementation.
Rich Felker [Sun, 20 Feb 2011 20:16:04 +0000 (15:16 -0500)]
fix null pointer dereference introduced in last sigprocmask commit
Rich Felker [Sun, 20 Feb 2011 20:06:26 +0000 (15:06 -0500)]
make real symbols for the legacy (nonstandardized) utmp functions
this is needed in the long term for ABI compatibility anyway, and in
the immediate, it helps with building broken programs like GNU screen
that try to prototype the functions themselves rather than using the
header.
Rich Felker [Sun, 20 Feb 2011 07:44:52 +0000 (02:44 -0500)]
resolve some header namespace non-issues
after re-reading 2.2.2 of POSIX 2008, all of these are in the correct
reserved namespaces and do not need protection.
Rich Felker [Sun, 20 Feb 2011 06:48:51 +0000 (01:48 -0500)]
move the GNU siginfo renaming so it doesn't lead to mismatching names
Rich Felker [Sun, 20 Feb 2011 06:26:25 +0000 (01:26 -0500)]
fill in some missing siginfo stuff in signal.h
Rich Felker [Sun, 20 Feb 2011 05:28:10 +0000 (00:28 -0500)]
make sys/param.h not depend on PATH_MAX and NAME_MAX
this is a nonstandard header used only by backwards programs, but for
some reason it's extremely popular. the recent namespace cleanup fixes
broke it, because PATH_MAX and NAME_MAX will not be defined unless an
approriate feature test macro has been defined. moreover, it's too
late to just #define _GNU_SOURCE in param.h, since limits.h may have
already been included.
let's just hard-code standard values and be done with it.
Rich Felker [Sat, 19 Feb 2011 22:56:57 +0000 (17:56 -0500)]
workaround gcc bug 46926 by providing a dumb sincos implementation
note that this library itself is built with -ffreestanding so sincos.c
should not be miscompiled even if the gcc used to compile musl has
this bug.
Rich Felker [Sat, 19 Feb 2011 20:21:05 +0000 (15:21 -0500)]
use rt_sigprocmask, not legacy sigprocmask, syscall in pthread exit code
Rich Felker [Sat, 19 Feb 2011 17:44:36 +0000 (12:44 -0500)]
fix typo in wordexp.h (note that the function is still unimplemented)
Rich Felker [Sat, 19 Feb 2011 17:43:56 +0000 (12:43 -0500)]
implement the remaining clock_* interfaces
Rich Felker [Sat, 19 Feb 2011 16:04:36 +0000 (11:04 -0500)]
race condition fix: block all signals before decrementing thread count
the existence of a (kernelspace) thread must never have observable
effects after the thread count is decremented. if signals are not
blocked, it could end up handling the signal for rsyscall and
contributing towards the count of threads which have changed ids,
causing a thread to be missed. this could lead to one thread retaining
unwanted privilege level.
this change may also address other subtle race conditions in
application code that uses signals.
Rich Felker [Sat, 19 Feb 2011 15:51:13 +0000 (10:51 -0500)]
prevent sigprocmask/pthread_sigmask from blocking implementation signals
this code was wrongly disabled because the old version was trying to
be too clever and didn't work. replaced it with a simple version for
now.
Rich Felker [Sat, 19 Feb 2011 15:38:57 +0000 (10:38 -0500)]
make pthread_exit run dtors for last thread, wait to decrement thread count
Rich Felker [Sat, 19 Feb 2011 14:40:07 +0000 (09:40 -0500)]
make mktemp match the historic behavior, and update functions that use it
the historic mktemp is supposed to blank the template string on
failure, rather than returning 0. just zero the first character so
that mkstemp and mkdtemp can still retry with O(1) space requirement.
Rich Felker [Sat, 19 Feb 2011 14:34:28 +0000 (09:34 -0500)]
fix major bug created from copying mkdtemp logic
Rich Felker [Sat, 19 Feb 2011 07:52:29 +0000 (02:52 -0500)]
add syscall wrappers for inotify
Rich Felker [Sat, 19 Feb 2011 07:28:42 +0000 (02:28 -0500)]
cleanup cruft left from when kernel and user time_t disagreed
Rich Felker [Sat, 19 Feb 2011 07:26:11 +0000 (02:26 -0500)]
prototype wait3 and wait4
Rich Felker [Sat, 19 Feb 2011 07:23:29 +0000 (02:23 -0500)]
add missing WIFCONTINUED macro and improve WIFSIGNALED
Rich Felker [Sat, 19 Feb 2011 06:02:46 +0000 (01:02 -0500)]
prototypes for brk and sbrk
Rich Felker [Sat, 19 Feb 2011 03:03:03 +0000 (22:03 -0500)]
support the ugly and deprecated ucontext and sigcontext header stuff...
only the structures, not the functions from ucontext.h, are supported
at this point. the main goal of this commit is to make modern gcc with
dwarf2 unwinding build without errors.
honestly, it probably doesn't matter how we define these as long as
they have members with the right names to prevent errors while
compiling libgcc. the only time they will be used is for propagating
exceptions across signal-handler boundaries, which invokes undefined
behavior anyway. but as-is, they're probably correct and may be useful
to various low-level applications dealing with virtualization, jit
code generation, and so on...
Rich Felker [Sat, 19 Feb 2011 00:52:42 +0000 (19:52 -0500)]
add pthread_atfork interface
note that this presently does not handle consistency of the libc's own
global state during forking. as per POSIX 2008, if the parent process
was threaded, the child process may only call async-signal-safe
functions until one of the exec-family functions is called, so the
current behavior is believed to be conformant even if non-ideal. it
may be improved at some later time.
Rich Felker [Fri, 18 Feb 2011 22:04:56 +0000 (17:04 -0500)]
major improvements to temp file name generator
use current time in nanoseconds and some potentially-random (if aslr
is enabled) pointer values for the initial tempfile name generation,
and step via a cheap linear prng on collisions. limit the number of
retry attempts to prevent denial of service attacks even if an
attacker can guess the filenames.
Rich Felker [Fri, 18 Feb 2011 21:32:33 +0000 (16:32 -0500)]
reformat mkstemp like mkdtemp
this is cleaner and makes it easy to impose a limit on the number of
retries later if it seems desirable to do so.
Rich Felker [Fri, 18 Feb 2011 04:13:46 +0000 (23:13 -0500)]
add portable lchown (trivial to support and a few ancient things want it..)
Rich Felker [Fri, 18 Feb 2011 00:15:08 +0000 (19:15 -0500)]
prepare WHATSNEW for release
Rich Felker [Thu, 17 Feb 2011 23:30:41 +0000 (18:30 -0500)]
document in config.mak sample that x86_64 is supported
Rich Felker [Thu, 17 Feb 2011 22:57:50 +0000 (17:57 -0500)]
update WHATSNEW in preparation for release
Rich Felker [Thu, 17 Feb 2011 22:57:26 +0000 (17:57 -0500)]
avoid deleting the lib/empty file
Rich Felker [Thu, 17 Feb 2011 22:16:20 +0000 (17:16 -0500)]
reorganize pthread data structures and move the definitions to alltypes.h
this allows sys/types.h to provide the pthread types, as required by
POSIX. this design also facilitates forcing ABI-compatible sizes in
the arch-specific alltypes.h, while eliminating the need for
developers changing the internals of the pthread types to poke around
with arch-specific headers they may not be able to test.
Rich Felker [Thu, 17 Feb 2011 22:12:52 +0000 (17:12 -0500)]
new solution for empty lib dir (old one had some problems)
Rich Felker [Thu, 17 Feb 2011 20:15:03 +0000 (15:15 -0500)]
improve Makefile handling of git checkouts with missing lib/ and config.mak
Rich Felker [Thu, 17 Feb 2011 15:30:00 +0000 (10:30 -0500)]
make daemon try the operations that might fail before fork rather than after
Rich Felker [Thu, 17 Feb 2011 15:28:56 +0000 (10:28 -0500)]
daemon should check for failures and return -1
Rich Felker [Thu, 17 Feb 2011 05:03:24 +0000 (00:03 -0500)]
don't compare elements with themselves during qsort.
this is actually a workaround for a bug in gcc, whereby it asserts
inequality of the keys being compared...