Commit Graph

400 Commits

Author SHA1 Message Date
Rich Felker 1c76683cb4 add syscall wrappers for posix_fadvise, posix_fallocate 2011-04-20 15:20:22 -04:00
Rich Felker 145c05345d block cancellation in wordexp, handle more errors 2011-04-19 23:42:56 -04:00
Rich Felker f0fc95d439 avoid malloc of potentially-large string in wordexp 2011-04-19 23:37:57 -04:00
Rich Felker a6054e3c94 move some more code out of pthread_create.c
this also de-uglifies the dummy function aliasing a bit.
2011-04-19 23:09:14 -04:00
Rich Felker 4f24994920 fix uninitialized waiters field in semaphores 2011-04-19 13:16:59 -04:00
Rich Felker 43ee4df338 dns lookups: protect against cancellation and fix incorrect error codes 2011-04-18 21:35:14 -04:00
Rich Felker 75a0be1f65 avoid fd leak if opendir is cancelled when calloc has failed 2011-04-18 21:22:14 -04:00
Rich Felker df9e11bb06 protect ftw and nftw against cancellation 2011-04-18 21:17:03 -04:00
Rich Felker d2c604d5a4 protect syslog against cancellation
these functions are allowed to be cancellation points, but then we
would have to install cleanup handlers to avoid termination with locks
held.
2011-04-18 21:11:23 -04:00
Rich Felker be2e06d347 recheck cancellation disabled flag after syscall returns EINTR
we already checked before making the syscall, but it's possible that a
signal handler interrupted the blocking syscall and disabled
cancellation, and that this is the cause of EINTR. in this case, the
old behavior was testably wrong.
2011-04-18 20:50:37 -04:00
Rich Felker 61b56a8d21 remove bogus extra logic for close cancellability
like all other syscalls, close should return to the caller if and only
if it successfully performed its action. it is necessary that the
application be able to determine whether the close succeeded.
2011-04-18 18:42:34 -04:00
Rich Felker 1bc44a4734 fix typo in x86_64 cancellable syscall asm 2011-04-17 19:25:17 -04:00
Rich Felker e98bdca9df minimal realpath implementation using /proc
clean and simple, but fails when the caller does not have permissions
to open the file for reading or when /proc is not available. i may
replace this with a full implementation later, possibly leaving this
version as an optimization to use when it works.
2011-04-17 17:32:36 -04:00
Rich Felker 2afed79f15 pthread_exit is not supposed to affect cancellability
if the exit was caused by cancellation, __cancel has already set these
flags anyway.
2011-04-17 17:09:41 -04:00
Rich Felker 1ebde9c3a2 fix pthread_exit from cancellation handler
cancellation frames were not correctly popped, so this usage would not
only loop, but also reuse discarded and invalid parts of the stack.
2011-04-17 17:06:05 -04:00
Rich Felker 9080cc153c clean up handling of thread/nothread mode, locking 2011-04-17 16:53:54 -04:00
Rich Felker eb0e8fa0b1 debloat: use __syscall instead of syscall where possible
don't waste time (and significant code size due to function call
overhead!) setting errno when the result of a syscall does not matter
or when it can't fail.
2011-04-17 16:32:15 -04:00
Rich Felker 09dae2b7b6 fix bugs in cancellable syscall asm
x86_64 was just plain wrong in the cancel-flag-already-set path, and
crashing.

the more subtle error was not clearing the saved stack pointer before
returning to c code. this could result in the signal handler
misidentifying c code as the pre-syscall part of the asm, and acting
on cancellation at the wrong time, and thus resource leak race
conditions.

also, now __cancel (in the c code) is responsible for clearing the
saved sp in the already-cancelled branch. this means we have to use
call rather than jmp to ensure the stack pointer in the c will never
match what the asm saved.
2011-04-17 15:30:08 -04:00
Rich Felker ebf82447be optimize cancellation enable/disable code
the goal is to be able to use pthread_setcancelstate internally in
the implementation, whenever a function might want to use functions
which are cancellation points but avoid becoming a cancellation point
itself. i could have just used a separate internal function for
temporarily inhibiting cancellation, but the solution in this commit
is better because (1) it's one less implementation-specific detail in
functions that need to use it, and (2) application code can also get
the same benefit.

previously, pthread_setcancelstate dependend on pthread_self, which
would pull in unwanted thread setup overhead for non-threaded
programs. now, it temporarily stores the state in the global libc
struct if threads have not been initialized, and later moves it if
needed. this way we can instead use __pthread_self, which has no
dependencies and assumes that the thread register is already valid.
2011-04-17 13:21:13 -04:00
Rich Felker 02eff258c6 don't use pthread_once when there is no danger in race 2011-04-17 12:15:55 -04:00
Rich Felker e74664016b fix some minor issues in cancellation handling patch
signals were wrongly left masked, and cancellability state was not
switched to disabled, during the execution of cleanup handlers.
2011-04-17 12:09:47 -04:00
Rich Felker feee98903c overhaul pthread cancellation
this patch improves the correctness, simplicity, and size of
cancellation-related code. modulo any small errors, it should now be
completely conformant, safe, and resource-leak free.

the notion of entering and exiting cancellation-point context has been
completely eliminated and replaced with alternative syscall assembly
code for cancellable syscalls. the assembly is responsible for setting
up execution context information (stack pointer and address of the
syscall instruction) which the cancellation signal handler can use to
determine whether the interrupted code was in a cancellable state.

these changes eliminate race conditions in the previous generation of
cancellation handling code (whereby a cancellation request received
just prior to the syscall would not be processed, leaving the syscall
to block, potentially indefinitely), and remedy an issue where
non-cancellable syscalls made from signal handlers became cancellable
if the signal handler interrupted a cancellation point.

x86_64 asm is untested and may need a second try to get it right.
2011-04-17 11:43:03 -04:00
Rich Felker 90f09a0dde remove stupid debug code in wordexp 2011-04-15 12:07:26 -04:00
Rich Felker d251c2645c implement wordexp. first try, may be buggy. intended to be safe. 2011-04-15 12:06:34 -04:00
Rich Felker 69cf09c821 avoid setting errno when checking for tty
setting errno here is completely valid, but some programs, notably
busybox printf, assume that errno will not be set during output and
treat this as an error condition. in any case, skipping it slightly
reduces code size and saves time.
2011-04-15 12:04:13 -04:00
Rich Felker 088ae5995a document some changes in the upcoming release 2011-04-14 23:33:46 -04:00
Rich Felker a3aa89d826 fix O_SYNC definition, cleanup fcntl.h 2011-04-14 22:06:30 -04:00
Rich Felker 0a84e72c42 fix FAPPEND typo on x86_64 (previously only fixed on i386) 2011-04-14 21:50:07 -04:00
Rich Felker c2b18f3531 fcntl.h: move macros that do not vary between archs out of bits 2011-04-14 21:49:22 -04:00
Rich Felker ace973637f fix broken fcntl locks on x86_64 2011-04-14 21:45:26 -04:00
Rich Felker b172dc8b58 make tmpfile slightly more efficient (use unlink syscall instead of remove) 2011-04-14 21:43:49 -04:00
Rich Felker 9b96220e5a fix typo in legacy FAPPEND definition 2011-04-14 19:14:42 -04:00
Rich Felker 33a3f202d1 add useless type fd_mask. it's in the reserved namespace. 2011-04-14 16:23:31 -04:00
Rich Felker e983aea0ae change sem_trywait algorithm so it never has to call __wake 2011-04-14 15:10:50 -04:00
Rich Felker ec2e50d0d7 cheap trick to further optimize locking normal mutexes 2011-04-14 14:39:57 -04:00
Rich Felker 016a5dc192 use a separate signal from SIGCANCEL for SIGEV_THREAD timers
otherwise we cannot support an application's desire to use
asynchronous cancellation within the callback function. this change
also slightly debloats pthread_create.c.
2011-04-14 12:51:00 -04:00
Rich Felker 9beb6330c0 simplify cancellation point handling
we take advantage of the fact that unless self->cancelpt is 1,
cancellation cannot happen. so just increment it by 2 to temporarily
block cancellation. this drops pthread_create.o well under 1k.
2011-04-13 20:47:01 -04:00
Rich Felker 19c1830eaa simplify syslog, add vsyslog interface (nonstandard)
with datagram sockets, depending on fprintf not to flush the output
early was very fragile; the new version simply uses a small fixed-size
buffer. it could be updated to dynamic-allocate large buffers if
needed, but i can't envision any admin being happy about finding
64kb-long lines in their syslog...
2011-04-13 18:32:33 -04:00
Rich Felker a77411a50d remove useless SIGPIPE protection from syslog
per the standard, SIGPIPE is not generated for SOCK_DGRAM.
2011-04-13 17:51:45 -04:00
Rich Felker a444ee3410 fix syslog (corrected SIGPIPE blocking, and using dgram instead of stream)
it actually appears the hacks to block SIGPIPE are probably not
necessary, and potentially harmful. if i can confirm this, i'll remove
them.
2011-04-13 17:24:25 -04:00
Rich Felker 07e865cc5a numerous fixes to sysv ipc
some of these definitions were just plain wrong, others based on
outdated ancient "non-64" versions of the kernel interface.

as much as possible has now been moved out of bits/*

these changes break abi (the old abi for these functions was wrong),
but since they were not working anyway it can hardly matter.
2011-04-13 16:45:43 -04:00
Rich Felker b5b43b6d62 add syslog.h cruft for syslogd to use... 2011-04-13 16:13:49 -04:00
Rich Felker b778a2ba69 add profile for getmntent_r 2011-04-13 15:24:26 -04:00
Rich Felker 55b123b5ed add syscall wrapper for flock
it should be noted that flock does not mix well with standard fcntl
locking, but nonetheless some applications will attempt to use flock
instead of fcntl if both exist. options to configure or small patches
may be needed. debian maintainers have plenty of experience with this
unfortunate situation...
2011-04-13 14:55:26 -04:00
Rich Felker 6f0259a4fc fix bug whereby getopt_long allowed mismatch in last char of option name 2011-04-13 14:52:23 -04:00
Rich Felker 45a3219944 fix typos on RLIM_NLIMITS, remove _GNU_SOURCE test for it
RLIM_* is in the reserved namespace for this header
2011-04-13 13:22:19 -04:00
Rich Felker cac7d837cc fix and cleanup suseconds_t/timeval stuff (broken on 64-bit)
trash in the upper 32 bits was making the kernel sleep forever in
select on 64-bit systems.
2011-04-13 13:16:49 -04:00
Rich Felker 91e836fda7 implement getgrouplist (for initgroups), formerly dummied-out 2011-04-13 09:39:47 -04:00
Rich Felker 3f44f298e4 fix prototypes/signature for setgroups, etc. 2011-04-13 09:03:22 -04:00
Rich Felker 0f5b43550c fix incorrect GNU sighandler_t typedef 2011-04-13 08:45:28 -04:00