566
562
#ifdef CONFIG_MM_OWNER
568
* Task p is exiting and it owned mm, lets find a new owner for it
564
* A task is exiting. If it owned this mm, find a new owner for the mm.
571
mm_need_new_owner(struct mm_struct *mm, struct task_struct *p)
574
* If there are other users of the mm and the owner (us) is exiting
575
* we need to find a new owner to take on the responsibility.
577
if (atomic_read(&mm->mm_users) <= 1)
584
566
void mm_update_next_owner(struct mm_struct *mm)
586
568
struct task_struct *c, *g, *p = current;
589
if (!mm_need_new_owner(mm, p))
572
* If the exiting or execing task is not the owner, it's
573
* someone else's problem.
578
* The current owner is exiting/execing and there are no other
579
* candidates. Do not leave the mm pointing to a possibly
580
* freed task structure.
582
if (atomic_read(&mm->mm_users) <= 1) {
592
587
read_lock(&tasklist_lock);
1384
* Handle sys_wait4 work for one task in state TASK_STOPPED. We hold
1385
* read_lock(&tasklist_lock) on entry. If we return zero, we still hold
1386
* the lock and this task is uninteresting. If we return nonzero, we have
1387
* released the lock and the system call should return.
1380
* wait_task_stopped - Wait for %TASK_STOPPED or %TASK_TRACED
1382
* @ptrace: is the wait for ptrace
1383
* @p: task to wait for
1385
* Handle sys_wait4() work for %p in state %TASK_STOPPED or %TASK_TRACED.
1388
* read_lock(&tasklist_lock), which is released if return value is
1389
* non-zero. Also, grabs and releases @p->sighand->siglock.
1392
* 0 if wait condition didn't exist and search for other wait conditions
1393
* should continue. Non-zero return, -errno on failure and @p's pid on
1394
* success, implies that tasklist_lock is released and wait condition
1395
* search should terminate.
1389
1397
static int wait_task_stopped(struct wait_opts *wo,
1390
1398
int ptrace, struct task_struct *p)
1544
if (likely(!ptrace) && unlikely(task_ptrace(p))) {
1546
* This child is hidden by ptrace.
1547
* We aren't allowed to see it now, but eventually we will.
1555
/* dead body doesn't have much to contribute */
1556
if (p->exit_state == EXIT_DEAD)
1560
if (p->exit_state == EXIT_ZOMBIE) {
1562
* A zombie ptracee is only visible to its ptracer.
1563
* Notification and reaping will be cascaded to the real
1564
* parent when the ptracer detaches.
1566
if (likely(!ptrace) && unlikely(task_ptrace(p))) {
1567
/* it will become visible, clear notask_error */
1568
wo->notask_error = 0;
1572
/* we don't reap group leaders with subthreads */
1573
if (!delay_group_leader(p))
1574
return wait_task_zombie(wo, p);
1577
* Allow access to stopped/continued state via zombie by
1578
* falling through. Clearing of notask_error is complex.
1582
* If WEXITED is set, notask_error should naturally be
1583
* cleared. If not, subset of WSTOPPED|WCONTINUED is set,
1584
* so, if there are live subthreads, there are events to
1585
* wait for. If all subthreads are dead, it's still safe
1586
* to clear - this function will be called again in finite
1587
* amount time once all the subthreads are released and
1588
* will then return without clearing.
1592
* Stopped state is per-task and thus can't change once the
1593
* target task dies. Only continued and exited can happen.
1594
* Clear notask_error if WCONTINUED | WEXITED.
1596
if (likely(!ptrace) || (wo->wo_flags & (WCONTINUED | WEXITED)))
1597
wo->notask_error = 0;
1600
* If @p is ptraced by a task in its real parent's group,
1601
* hide group stop/continued state when looking at @p as
1602
* the real parent; otherwise, a single stop can be
1603
* reported twice as group and ptrace stops.
1605
* If a ptracer wants to distinguish the two events for its
1606
* own children, it should create a separate process which
1607
* takes the role of real parent.
1609
if (likely(!ptrace) && task_ptrace(p) &&
1610
same_thread_group(p->parent, p->real_parent))
1614
* @p is alive and it's gonna stop, continue or exit, so
1615
* there always is something to wait for.
1549
1617
wo->notask_error = 0;
1553
if (p->exit_state == EXIT_DEAD)
1557
* We don't reap group leaders with subthreads.
1559
if (p->exit_state == EXIT_ZOMBIE && !delay_group_leader(p))
1560
return wait_task_zombie(wo, p);
1563
* It's stopped or running now, so it might
1564
* later continue, exit, or stop again.
1566
wo->notask_error = 0;
1568
if (task_stopped_code(p, ptrace))
1569
return wait_task_stopped(wo, ptrace, p);
1621
* Wait for stopped. Depending on @ptrace, different stopped state
1622
* is used and the two don't interact with each other.
1624
ret = wait_task_stopped(wo, ptrace, p);
1629
* Wait for continued. There's only one continued state and the
1630
* ptracer can consume it which can confuse the real parent. Don't
1631
* use WCONTINUED from ptracer. You don't need or want it.
1571
1633
return wait_task_continued(wo, p);