summaryrefslogtreecommitdiff
path: root/sys/kern/kern_fork.c
AgeCommit message (Collapse)Author
2014-02-12Eliminate the exit sig handling, which was only invokable via thePhilip Guenther
Linux-compat clone() syscall when *not* using CLONE_THREAD. pirofti@ confirms Opera runs in compat without this, so out it goes; one less hair to choke on in kern_exit.c ok tedu@ pirofti@
2014-02-10arc4random_uniform() returns a value strictly less than its argument; fixPhilip Guenther
arithmetic so that PID_MAX can be reached. ok otto@ zhuk@ miod@
2014-01-20Threads can't be zombies, only processes, so change zombproc to zombprocess,Philip Guenther
make it a list of processes, and change P_NOZOMBIE and P_STOPPED from thread flags to process flags. Add allprocess list for the code that just wants to see processes. ok tedu@
2014-01-20Move p_textvp from struct proc to struct process so that the exit codePhilip Guenther
can be further simplified. ok kettenis@
2013-10-08Fix delivery of SIGPROF and SIGVTALRM to threaded processes by havingPhilip Guenther
hardclock() set a flag on the running thread and force AST processing, and then have the thread signal itself from userret(). idea and flag names from FreeBSD ok jsing@
2013-08-14The last user of the old __tfork() was updated to the current one,Philip Guenther
so COMPAT_O51 can go. The complete ABI role means COMPAT_O53 can be removed as well. ok jsing@ tedu@
2013-06-11convert some easy bcopy to memcpy and clean up fdexpand a bit.Ted Unangst
ok kettenis
2013-06-06Prevent idle thread from being stolen on startup.Christiano F. Haesbaert
There is a race condition which might trigger a case where two cpus try to run the same idle thread. The problem arises when one cpu steals the idle proc of another cpu and this other cpu ends up running the idle thread via spc->spc_idleproc, resulting in two cpus trying to cpu_switchto(idleX). On startup, idle procs are scaterred around different runqueues, the decision for scheduling is: 1 look at my runqueue. 2 if empty, look at other dudes runqueue. 3 if empty, select idle proc via spc->spc_idleproc. The problem is that cpu0's idle0 might be running on cpu1 due to step 1 or 2 and cpu0 hits step 3. So cpu0 will select idle0, while cpu1 is in fact running it already. The solution is to never place idle on a runqueue, therefore being only selectable through spc->spc_idleproc. This race can be more easily triggered on a HT cpu on virtualized environments, where the guest more often than not doesn't have the cpu for itself, so timing gets shuffled. ok tedu@ guenther@ go ahead after t2k13 deraadt@
2013-06-05factor out pid allocation to functions. add a small cache of recentlyTed Unangst
exited pids that won't get recycled. ok deraadt
2013-06-03When creating a thread, don't add it to the process's thread listPhilip Guenther
until it's fully built, so that it can't get a signal from realitexpire(), as seen by sthen@ and espie@ in ports builds. Exact bits moved down worked out with tedu@, ok deraadt@
2013-06-03Convert some internal APIs to use timespecs instead of timevalsPhilip Guenther
ok matthew@ deraadt@
2013-06-01As found by kurt, there's a twisty race between exit1 and fork1Ted Unangst
with threaded processes. Fix this by checking for an attempt to go single threaded in fork1 and account for the new thread as well. ok espie guenther kurt
2013-04-06rthreads are always enabled. remove the sysctl.Ted Unangst
ok deraadt guenther kettenis matthew
2013-03-14the 5.1 era tfork syscall claws its way out of the grave. we failed toTed Unangst
fully deprecate it (notably the go port was still using it as of 5.3) so to give users a little more time to update, __tfork51 lives again. okish deraadt guenther
2013-03-02No longer need the 5.1 version of the __tfork syscallPhilip Guenther
ok deraadt@
2012-11-19If uvm_km_kmemalloc_pla() fails when just creating a thread (and not aPhilip Guenthe
process), then don't decrement the total and per-user counts of processes. ok deraadt@ miod@
2012-08-02Apply profiling to all threads instead of just the thread that calledPhilip Guenthe
profil() by moving P_PROFIL from proc->p_flag to process->ps_flags with matching adjustment in fork1() and exit1() ok matthew@
2012-06-21__tfork() needs to set the stack address of the new thread in the kernel,Philip Guenthe
so that it can't get a signal while still running on the parent thread's stack. Also, pass in sizeof(struct __tfork) to provide forward compat when more members are added. This is an ABI change, so switch syscall numbers and bump lib majors this time. ok deraadt@ matthew@
2012-05-10Only set a process's start time when starting the main thread. There'sPhilip Guenthe
also no need to protect that and the setting of the AFORK accounting flag with the scheduler lock. ok mikeb@
2012-04-13First stab at making ptrace(2) usable for debugging multi-threaded programs.Mark Kettenis
It implements a full-stop model where all threads are stopped before handing over control to the debugger. Events are reported as before through wait(2); you will have to call ptrace(PT_GET_PROCESS_STATE, ...) to find out which thread hit the event. Since this changes the size of struct ptrace_state, you will have to recompile gdb. ok guenther@
2012-04-12remove rfork(); ok guenther miodTheo de Raadt
2012-04-12move accounting flags to struct process; idea and ok guentherMike Belopuhov
2012-04-10Make the KERN_NPROCS and KERN_MAXPROC sysctl()s and the RLIMIT_NPROC rlimitPhilip Guenthe
count processes instead of threads. New sysctl()s KERN_NTHREADS and KERN_MAXTHREAD count and limit threads. The nprocs and maxproc kernel variables are replaced by nprocess, maxprocess, nthreads, and maxthread. ok tedu@ mikeb@
2012-03-23Make rusage totals, itimers, and profile settings per-process insteadPhilip Guenthe
of per-rthread. Handling of per-thread tick and runtime counters inspired by how FreeBSD does it. ok kettenis@
2012-02-20First steps for making ptrace work with rthreads:Philip Guenthe
- move the P_TRACED and P_INEXEC flags, and p_oppid, p_ptmask, and p_ptstat member from struct proc to struct process - sort the PT_* requests into those that take a PID vs those that can also take a TID - stub in PT_GET_THREAD_FIRST and PT_GET_THREAD_NEXT ok kettenis@
2011-12-14Handle rthreads consistently in ktrace by moving the flags and vnode intoPhilip Guenthe
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials used to open the file in sys_ktrace() and use them for all writes to the vnode. much feedback and ok jsing@
2011-11-22Move struct proc's sigaltstack struct from the zeroed area into theJoshua Elsasser
copied area, and initialize it properly in the FORK_THREAD case. This restores the behavior of a forked process inheriting its parent's signal stack. ok guenther@
2011-11-09Change fork1() and kthread_create() to match the rest of the treePhilip Guenthe
and use curp vs p instead of p1 vs p2. Add curpr and pr variables for the respective struct processes. Make sigactsshare() return the shared sigacts intead of taking the struct proc to update. ok deraadt@
2011-11-05I had moved earlier the adding of processes to the pgrp and children listsPhilip Guenthe
during the big rework at c2k10, but it's too early as signals can be posted before the process is fully built. Move those list adds back down to the late stage they were before. Problem seen on sebastia@'s sparc. ok deraadt@ miod@
2011-10-15"TLS-lite": add kernel support for a per-thread userspace pointer,Philip Guenthe
for pointing to the thread-control-block. Support for mapping this to the correct hardware register can be added as it's finished; start with support for amd64, sparc, and sparc64. Includes syscalls for getting and setting it (for a portable __errno implementation) as well as creating a new thread with an initial value for it. discussed with miod@, kettenis@, deraadt@; committing to get the syscalls in with the impending libc bump and do further refinements in tree
2011-07-07Functions used in files other than where they are defined should bePhilip Guenthe
declared in .h files, not in each .c. Apply that rule to endtsleep(), scheduler_start(), updatepri(), and realitexpire() ok deraadt@ tedu@
2011-07-06Clean up after P_BIGLOCK removal.Artur Grabowski
KERNEL_PROC_LOCK -> KERNEL_LOCK KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK oga@ ok
2011-06-06push kernel malloc(9) and kernel stacks into non-dma memory, since thatTheo de Raadt
appears to be safe now. If not, we'll know soon where the bugs lie, so that we can fix them. This diff has been in snapshots for many months. ok oga miod
2011-04-03Move PPWAIT flag from struct proc to process, so that rthreads inPhilip Guenthe
a vforked child behave correctly. Have the parent in a vfork() wait on a (different) flag in *its* process instead of the child to prevent a possible use-after-free. When ktracing the child return from a fork, call it rfork if an rthread was created. ok blambert@
2011-04-02Move P_SUGID and P_SUGIDEXEC from struct proc to struct process, soPhilip Guenthe
that you can't evade the checks by doing the dirty work in an rthread ok blambert@, deraadt@
2010-10-31The return of rfork(RFTHREAD) must be consistent with getthrid().Philip Guenthe
Fixes rthread breakage observed by Vladimir Kirillov.
2010-07-26Correct the links between threads, processes, pgrps, and sessions,Philip Guenthe
so that the process-level stuff is to/from struct process and not struct proc. This fixes a bunch of problem cases in rthreads. Based on earlier work by blambert and myself, but mostly written at c2k10. Tested by many: deraadt, sthen, krw, ray, and in snapshots
2010-07-23Make sure the u area of new processes is zero-filled; this got lost inMiod Vallat
1.119.
2010-07-19Rollback the allproclk and fileheadlk addition. When grabbing anPhilip Guenthe
rwlock, the thread will release biglock if it sleeps, means that atomicity from before the rw_enter() to after it is not guaranteed. The change didn't address those, so pulling it until it does. "go for it" tedu@
2010-07-02add an align argument to uvm_km_kmemalloc_pla.Artur Grabowski
Use uvm_km_kmemalloc_pla with the dma constraint to allocate kernel stacks. Yes, that means DMA is possible to kernel stacks, but only until we've fixed all the scary drivers. deraadt@ ok
2010-06-30style nitThordur I. Bjornsson
2010-06-30Move the plimit and pcred bits in fork1() into process_new() and makePhilip Guenthe
process_new() handle the new struct process like fork1() does struct proc, with a range of members zeroed and a range copied from the parent process. ok tedu@
2010-06-29We always copy struct pcred when creating a new process, so the referencePhilip Guenthe
count was always one. That's pointless, so remove the member and the code. ok tedu@
2010-06-29Eliminate struct plimit's PL_SHAREMOD flag: it was for COMPAT_IRIXPhilip Guenthe
sproc() support, but we don't have COMPAT_IRIX. ok krw@ tedu@
2010-06-29some late breaking style comments from guentherTed Unangst
2010-06-29Eliminate RTHREADS kernel option in favor of a sysctl. The actual statusTed Unangst
(not done) hasn't changed, but now it's less work to test things. ok art deraadt
2010-06-27A process on the zombie list can have a NULL p_pgrp if it sleeps whenPhilip Guenthe
grabbing allproclk in proc_zap(); don't dereference the process's p_pgrp if that happens. ok art@ thib@
2010-05-29As noted by art, two processes with the same pid would be bad. GrabPhilip Guenthe
the allproclk before searching for a free pid so that we don't sleep between picking one and adding it to the list that is searched. Also, keep holding the lock until after the PIDHASH update. ok art@, tedu@
2010-05-18move knote list to struct process. ok guentherTed Unangst
2010-03-24Add a rwlock around the filehead and allproc lists, mainly to protectTed Unangst
list walkers in sysctl that can block. As a reward, no more vslock. With some feedback from art, guenther, phessler. ok guenther.