Commit Graph

423 Commits

Author SHA1 Message Date
Rich Felker
32e2c468ba typo in prototype for mempcpy 2011-04-26 08:42:55 -04:00
Rich Felker
d179807f6b prototype for mempcpy 2011-04-26 08:41:54 -04:00
Rich Felker
3486365e95 fix bug in ipv6 parsing that prevented parsing a lone "::" 2011-04-25 17:49:21 -04:00
Rich Felker
34d81974d3 ipv6 parsing code (formerly dummied-out) 2011-04-25 17:04:40 -04:00
Rich Felker
5efc6af4eb fix 2 eof-related bugs in scanf
1. failed match of literal chars from the format string would always
return matching failure rather than input failure at eof, leading to
infinite loops in some programs.

2. unread of eof would wrongly adjust the character counts reported by
%n, yielding an off-by-one error.
2011-04-25 10:40:25 -04:00
Rich Felker
db9915ee97 update release notes to new format, add more 2011-04-22 20:14:04 -04:00
Rich Felker
e6cc1d6c0e fix initial stack alignment in new threads on x86_64 2011-04-22 18:48:57 -04:00
Rich Felker
cbb65af6ae update release notes in prep for 0.7.9 release 2011-04-21 23:33:39 -04:00
Rich Felker
d878dcecca omit errno update path for syscalls that cannot fail 2011-04-21 21:52:41 -04:00
Rich Felker
31f014e0a7 fix bogus return values for inet_pton 2011-04-21 16:57:00 -04:00
Rich Felker
4b5f054098 move wait.h macros out of bits. they do not vary. 2011-04-21 14:27:28 -04:00
Rich Felker
f492c95401 include signal.h to avoid thorny __sigcontext/sigcontext issues
this is explicitly allowed by POSIX
2011-04-21 14:21:57 -04:00
Rich Felker
870cc67977 fix minor bugs due to incorrect threaded-predicate semantics
some functions that should have been testing whether pthread_self()
had been called and initialized the thread pointer were instead
testing whether pthread_create() had been called and actually made the
program "threaded". while it's unlikely any mismatch would occur in
real-world problems, this could have introduced subtle bugs. now, we
store the address of the main thread's thread descriptor in the libc
structure and use its presence as a flag that the thread register is
initialized. note that after fork, the calling thread (not necessarily
the original main thread) is the new main thread.
2011-04-20 21:41:45 -04:00
Rich Felker
f9a6372a98 workaround bug in linux dup2
the linux documentation for dup2 says it can fail with EBUSY due to a
race condition with open and dup in the kernel. shield applications
(and the rest of libc) from this nonsense by looping until it succeeds
2011-04-20 21:05:10 -04:00
Rich Felker
10d7561db5 properly create new session/controlling terminal in forkpty 2011-04-20 21:01:42 -04:00
Rich Felker
4921ce0867 implement (nonstandard) forkpty 2011-04-20 20:55:13 -04:00
Rich Felker
f1ac8a28d8 disallow blank strings as service or host name 2011-04-20 20:02:35 -04:00
Rich Felker
d4b5d6e981 fix bugs in ipv4 parsing 2011-04-20 20:00:59 -04:00
Rich Felker
29a15ad077 fix initgroups (uninitialized count passed to getgrouplist) 2011-04-20 19:15:27 -04:00
Rich Felker
18bca57510 shadow password fixes: empty fields should read as -1 not 0 2011-04-20 19:05:59 -04:00
Rich Felker
b052f13cd1 namespace fixes for sys/mman.h 2011-04-20 15:55:58 -04:00
Rich Felker
53ab4e793b fix missing include in posix_madvise.c (compile error) 2011-04-20 15:36:15 -04:00
Rich Felker
2357350924 support posix_madvise (previous a stub)
the check against MADV_DONTNEED to because linux MADV_DONTNEED
semantics conflict dangerously with the POSIX semantics
2011-04-20 15:25:28 -04:00
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