aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/exit.c')
-rw-r--r--kernel/exit.c115
1 files changed, 91 insertions, 24 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index f9a45ebcc7b1..20a406471525 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -841,7 +841,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
841 /* Let father know we died 841 /* Let father know we died
842 * 842 *
843 * Thread signals are configurable, but you aren't going to use 843 * Thread signals are configurable, but you aren't going to use
844 * that to send signals to arbitary processes. 844 * that to send signals to arbitrary processes.
845 * That stops right now. 845 * That stops right now.
846 * 846 *
847 * If the parent exec id doesn't match the exec id we saved 847 * If the parent exec id doesn't match the exec id we saved
@@ -908,6 +908,7 @@ NORET_TYPE void do_exit(long code)
908 profile_task_exit(tsk); 908 profile_task_exit(tsk);
909 909
910 WARN_ON(atomic_read(&tsk->fs_excl)); 910 WARN_ON(atomic_read(&tsk->fs_excl));
911 WARN_ON(blk_needs_flush_plug(tsk));
911 912
912 if (unlikely(in_interrupt())) 913 if (unlikely(in_interrupt()))
913 panic("Aiee, killing interrupt handler!"); 914 panic("Aiee, killing interrupt handler!");
@@ -1015,7 +1016,7 @@ NORET_TYPE void do_exit(long code)
1015 /* 1016 /*
1016 * FIXME: do that only when needed, using sched_exit tracepoint 1017 * FIXME: do that only when needed, using sched_exit tracepoint
1017 */ 1018 */
1018 flush_ptrace_hw_breakpoint(tsk); 1019 ptrace_put_breakpoints(tsk);
1019 1020
1020 exit_notify(tsk, group_dead); 1021 exit_notify(tsk, group_dead);
1021#ifdef CONFIG_NUMA 1022#ifdef CONFIG_NUMA
@@ -1376,11 +1377,23 @@ static int *task_stopped_code(struct task_struct *p, bool ptrace)
1376 return NULL; 1377 return NULL;
1377} 1378}
1378 1379
1379/* 1380/**
1380 * Handle sys_wait4 work for one task in state TASK_STOPPED. We hold 1381 * wait_task_stopped - Wait for %TASK_STOPPED or %TASK_TRACED
1381 * read_lock(&tasklist_lock) on entry. If we return zero, we still hold 1382 * @wo: wait options
1382 * the lock and this task is uninteresting. If we return nonzero, we have 1383 * @ptrace: is the wait for ptrace
1383 * released the lock and the system call should return. 1384 * @p: task to wait for
1385 *
1386 * Handle sys_wait4() work for %p in state %TASK_STOPPED or %TASK_TRACED.
1387 *
1388 * CONTEXT:
1389 * read_lock(&tasklist_lock), which is released if return value is
1390 * non-zero. Also, grabs and releases @p->sighand->siglock.
1391 *
1392 * RETURNS:
1393 * 0 if wait condition didn't exist and search for other wait conditions
1394 * should continue. Non-zero return, -errno on failure and @p's pid on
1395 * success, implies that tasklist_lock is released and wait condition
1396 * search should terminate.
1384 */ 1397 */
1385static int wait_task_stopped(struct wait_opts *wo, 1398static int wait_task_stopped(struct wait_opts *wo,
1386 int ptrace, struct task_struct *p) 1399 int ptrace, struct task_struct *p)
@@ -1396,6 +1409,9 @@ static int wait_task_stopped(struct wait_opts *wo,
1396 if (!ptrace && !(wo->wo_flags & WUNTRACED)) 1409 if (!ptrace && !(wo->wo_flags & WUNTRACED))
1397 return 0; 1410 return 0;
1398 1411
1412 if (!task_stopped_code(p, ptrace))
1413 return 0;
1414
1399 exit_code = 0; 1415 exit_code = 0;
1400 spin_lock_irq(&p->sighand->siglock); 1416 spin_lock_irq(&p->sighand->siglock);
1401 1417
@@ -1537,33 +1553,84 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
1537 return 0; 1553 return 0;
1538 } 1554 }
1539 1555
1540 if (likely(!ptrace) && unlikely(task_ptrace(p))) { 1556 /* dead body doesn't have much to contribute */
1557 if (p->exit_state == EXIT_DEAD)
1558 return 0;
1559
1560 /* slay zombie? */
1561 if (p->exit_state == EXIT_ZOMBIE) {
1562 /*
1563 * A zombie ptracee is only visible to its ptracer.
1564 * Notification and reaping will be cascaded to the real
1565 * parent when the ptracer detaches.
1566 */
1567 if (likely(!ptrace) && unlikely(task_ptrace(p))) {
1568 /* it will become visible, clear notask_error */
1569 wo->notask_error = 0;
1570 return 0;
1571 }
1572
1573 /* we don't reap group leaders with subthreads */
1574 if (!delay_group_leader(p))
1575 return wait_task_zombie(wo, p);
1576
1541 /* 1577 /*
1542 * This child is hidden by ptrace. 1578 * Allow access to stopped/continued state via zombie by
1543 * We aren't allowed to see it now, but eventually we will. 1579 * falling through. Clearing of notask_error is complex.
1580 *
1581 * When !@ptrace:
1582 *
1583 * If WEXITED is set, notask_error should naturally be
1584 * cleared. If not, subset of WSTOPPED|WCONTINUED is set,
1585 * so, if there are live subthreads, there are events to
1586 * wait for. If all subthreads are dead, it's still safe
1587 * to clear - this function will be called again in finite
1588 * amount time once all the subthreads are released and
1589 * will then return without clearing.
1590 *
1591 * When @ptrace:
1592 *
1593 * Stopped state is per-task and thus can't change once the
1594 * target task dies. Only continued and exited can happen.
1595 * Clear notask_error if WCONTINUED | WEXITED.
1596 */
1597 if (likely(!ptrace) || (wo->wo_flags & (WCONTINUED | WEXITED)))
1598 wo->notask_error = 0;
1599 } else {
1600 /*
1601 * If @p is ptraced by a task in its real parent's group,
1602 * hide group stop/continued state when looking at @p as
1603 * the real parent; otherwise, a single stop can be
1604 * reported twice as group and ptrace stops.
1605 *
1606 * If a ptracer wants to distinguish the two events for its
1607 * own children, it should create a separate process which
1608 * takes the role of real parent.
1609 */
1610 if (likely(!ptrace) && task_ptrace(p) &&
1611 same_thread_group(p->parent, p->real_parent))
1612 return 0;
1613
1614 /*
1615 * @p is alive and it's gonna stop, continue or exit, so
1616 * there always is something to wait for.
1544 */ 1617 */
1545 wo->notask_error = 0; 1618 wo->notask_error = 0;
1546 return 0;
1547 } 1619 }
1548 1620
1549 if (p->exit_state == EXIT_DEAD)
1550 return 0;
1551
1552 /* 1621 /*
1553 * We don't reap group leaders with subthreads. 1622 * Wait for stopped. Depending on @ptrace, different stopped state
1623 * is used and the two don't interact with each other.
1554 */ 1624 */
1555 if (p->exit_state == EXIT_ZOMBIE && !delay_group_leader(p)) 1625 ret = wait_task_stopped(wo, ptrace, p);
1556 return wait_task_zombie(wo, p); 1626 if (ret)
1627 return ret;
1557 1628
1558 /* 1629 /*
1559 * It's stopped or running now, so it might 1630 * Wait for continued. There's only one continued state and the
1560 * later continue, exit, or stop again. 1631 * ptracer can consume it which can confuse the real parent. Don't
1632 * use WCONTINUED from ptracer. You don't need or want it.
1561 */ 1633 */
1562 wo->notask_error = 0;
1563
1564 if (task_stopped_code(p, ptrace))
1565 return wait_task_stopped(wo, ptrace, p);
1566
1567 return wait_task_continued(wo, p); 1634 return wait_task_continued(wo, p);
1568} 1635}
1569 1636