summaryrefslogtreecommitdiff
path: root/src/process
AgeCommit message (Collapse)AuthorLines
2012-10-19fix usage of locks with vforkRich Felker-2/+3
__release_ptc() is only valid in the parent; if it's performed in the child, the lock will be unlocked early then double-unlocked later, corrupting the lock state.
2012-10-18fix parent-memory-clobber in posix_spawn (environ)Rich Felker-9/+17
2012-10-18overhaul system() and popen() to use vfork; fix various related bugsRich Felker-29/+49
since we target systems without overcommit, special care should be taken that system() and popen(), like posix_spawn(), do not fail in processes whose commit charges are too high to allow ordinary forking. this in turn requires special precautions to ensure that the parent process's signal handlers do not end up running in the shared-memory child, where they could corrupt the state of the parent process. popen has also been updated to use pipe2, so it does not have a fd-leak race in multi-threaded programs. since pipe2 is missing on older kernels, (non-atomic) emulation has been added. some silly bugs in the old code should be gone too.
2012-10-15block uid/gid changes during posix_spawnRich Felker-0/+10
usage of vfork creates a situation where a process of lower privilege may momentarily have write access to the memory of a process of higher privilege. consider the case of a multi-threaded suid program which is calling posix_spawn in one thread while another thread drops the elevated privileges then runs untrusted (relative to the elevated privilege) code as the original invoking user. this untrusted code can then potentially modify the data the child process will use before calling exec, for example changing the pathname or arguments that will be passed to exec. note that if vfork is implemented as fork, the lock will not be held until the child execs, but since memory is not shared it does not matter.
2012-09-14use vfork if possible in posix_spawnRich Felker-1/+3
vfork is implemented as the fork syscall (with no atfork handlers run) on archs where it is not available, so this change does not introduce any change in behavior or regression for such archs.
2012-09-06use restrict everywhere it's required by c99 and/or posix 2008Rich Felker-18/+18
to deal with the fact that the public headers may be used with pre-c99 compilers, __restrict is used in place of restrict, and defined appropriately for any supported compiler. we also avoid the form [restrict] since older versions of gcc rejected it due to a bug in the original c99 standard, and instead use the form *restrict.
2012-02-06x86_64 vfork implementationRich Felker-0/+12
untested; should work.
2011-10-14support vfork on i386Rich Felker-0/+14
2011-10-14make available a namespace-safe vfork, if supportedRich Felker-1/+4
this may be useful to posix_spawn..?
2011-09-29fix various bugs in path and error handling in execvp/fexecveRich Felker-18/+29
2011-09-13fix various errors in function signatures/prototypes found by nszRich Felker-5/+8
2011-09-13add missing posix_spawnattr_init/destroy functionsRich Felker-0/+13
2011-08-06use weak aliases rather than function pointers to simplify some codeRich Felker-2/+8
2011-07-16ensure in fork that child gets its own new robust mutex listRich Felker-0/+1
2011-05-29fix backwards posix_spawn file action orderRich Felker-6/+10
2011-05-28add accidentally-omitted file needed for posix_spawn file actionsRich Felker-0/+10
2011-05-28add file actions support to posix_spawnRich Felker-2/+85
2011-05-28posix_spawn: honor POSIX_SPAWN_SETSIGDEF flagRich Felker-1/+3
2011-05-28initial implementation of posix_spawnRich Felker-0/+151
file actions are not yet implemented, but everything else should be mostly complete and roughly correct.
2011-04-27correct variadic prototypes for execl* familyRich Felker-15/+18
the old versions worked, but conflicted with programs which declared their own prototypes and generated warnings with some versions of gcc.
2011-04-20fix minor bugs due to incorrect threaded-predicate semanticsRich Felker-1/+2
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-17clean up handling of thread/nothread mode, lockingRich Felker-1/+1
2011-04-17overhaul pthread cancellationRich Felker-12/+2
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-12speed up threaded forkRich Felker-2/+1
after fork, we have a new process and the pid is equal to the tid of the new main thread. there is no need to make two separate syscalls to obtain the same number.
2011-03-24overhaul cancellation to fix resource leaks and dangerous behavior with signalsRich Felker-2/+14
this commit addresses two issues: 1. a race condition, whereby a cancellation request occurring after a syscall returned from kernelspace but before the subsequent CANCELPT_END would cause cancellable resource-allocating syscalls (like open) to leak resources. 2. signal handlers invoked while the thread was blocked at a cancellation point behaved as if asynchronous cancellation mode wer in effect, resulting in potentially dangerous state corruption if a cancellation request occurs. the glibc/nptl implementation of threads shares both of these issues. with this commit, both are fixed. however, cancellation points encountered in a signal handler will not be acted upon if the signal was received while the thread was already at a cancellation point. they will of course be acted upon after the signal handler returns, so in real-world usage where signal handlers quickly return, it should not be a problem. it's possible to solve this problem too by having sigaction() wrap all signal handlers with a function that uses a pthread_cleanup handler to catch cancellation, patch up the saved context, and return into the cancellable function that will catch and act upon the cancellation. however that would be a lot of complexity for minimal if any benefit...
2011-03-20global cleanup to use the new syscall interfaceRich Felker-7/+7
2011-03-09make fork properly initialize the main thread in the child processRich Felker-0/+7
2011-02-27implement fexecveRich Felker-0/+10
2011-02-18add pthread_atfork interfaceRich Felker-3/+6
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.
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker-0/+194