~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to kernel/exit.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
514
514
        return files;
515
515
}
516
516
 
517
 
EXPORT_SYMBOL(get_files_struct);
518
 
 
519
517
void put_files_struct(struct files_struct *files)
520
518
{
521
519
        struct fdtable *fdt;
537
535
        }
538
536
}
539
537
 
540
 
EXPORT_SYMBOL(put_files_struct);
541
 
 
542
538
void reset_files_struct(struct files_struct *files)
543
539
{
544
540
        struct task_struct *tsk = current;
565
561
 
566
562
#ifdef CONFIG_MM_OWNER
567
563
/*
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.
569
565
 */
570
 
static inline int
571
 
mm_need_new_owner(struct mm_struct *mm, struct task_struct *p)
572
 
{
573
 
        /*
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.
576
 
         */
577
 
        if (atomic_read(&mm->mm_users) <= 1)
578
 
                return 0;
579
 
        if (mm->owner != p)
580
 
                return 0;
581
 
        return 1;
582
 
}
583
 
 
584
566
void mm_update_next_owner(struct mm_struct *mm)
585
567
{
586
568
        struct task_struct *c, *g, *p = current;
587
569
 
588
570
retry:
589
 
        if (!mm_need_new_owner(mm, p))
590
 
                return;
 
571
        /*
 
572
         * If the exiting or execing task is not the owner, it's
 
573
         * someone else's problem.
 
574
         */
 
575
        if (mm->owner != p)
 
576
                return;
 
577
        /*
 
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.
 
581
         */
 
582
        if (atomic_read(&mm->mm_users) <= 1) {
 
583
                mm->owner = NULL;
 
584
                return;
 
585
        }
591
586
 
592
587
        read_lock(&tasklist_lock);
593
588
        /*
845
840
        /* Let father know we died
846
841
         *
847
842
         * Thread signals are configurable, but you aren't going to use
848
 
         * that to send signals to arbitary processes.
 
843
         * that to send signals to arbitrary processes.
849
844
         * That stops right now.
850
845
         *
851
846
         * If the parent exec id doesn't match the exec id we saved
912
907
        profile_task_exit(tsk);
913
908
 
914
909
        WARN_ON(atomic_read(&tsk->fs_excl));
 
910
        WARN_ON(blk_needs_flush_plug(tsk));
915
911
 
916
912
        if (unlikely(in_interrupt()))
917
913
                panic("Aiee, killing interrupt handler!");
1019
1015
        /*
1020
1016
         * FIXME: do that only when needed, using sched_exit tracepoint
1021
1017
         */
1022
 
        flush_ptrace_hw_breakpoint(tsk);
 
1018
        ptrace_put_breakpoints(tsk);
1023
1019
 
1024
1020
        exit_notify(tsk, group_dead);
1025
1021
#ifdef CONFIG_NUMA
1380
1376
        return NULL;
1381
1377
}
1382
1378
 
1383
 
/*
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.
 
1379
/**
 
1380
 * wait_task_stopped - Wait for %TASK_STOPPED or %TASK_TRACED
 
1381
 * @wo: wait options
 
1382
 * @ptrace: is the wait for ptrace
 
1383
 * @p: task to wait for
 
1384
 *
 
1385
 * Handle sys_wait4() work for %p in state %TASK_STOPPED or %TASK_TRACED.
 
1386
 *
 
1387
 * CONTEXT:
 
1388
 * read_lock(&tasklist_lock), which is released if return value is
 
1389
 * non-zero.  Also, grabs and releases @p->sighand->siglock.
 
1390
 *
 
1391
 * RETURNS:
 
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.
1388
1396
 */
1389
1397
static int wait_task_stopped(struct wait_opts *wo,
1390
1398
                                int ptrace, struct task_struct *p)
1400
1408
        if (!ptrace && !(wo->wo_flags & WUNTRACED))
1401
1409
                return 0;
1402
1410
 
 
1411
        if (!task_stopped_code(p, ptrace))
 
1412
                return 0;
 
1413
 
1403
1414
        exit_code = 0;
1404
1415
        spin_lock_irq(&p->sighand->siglock);
1405
1416
 
1541
1552
                return 0;
1542
1553
        }
1543
1554
 
1544
 
        if (likely(!ptrace) && unlikely(task_ptrace(p))) {
1545
 
                /*
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)
 
1557
                return 0;
 
1558
 
 
1559
        /* slay zombie? */
 
1560
        if (p->exit_state == EXIT_ZOMBIE) {
 
1561
                /*
 
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.
 
1565
                 */
 
1566
                if (likely(!ptrace) && unlikely(task_ptrace(p))) {
 
1567
                        /* it will become visible, clear notask_error */
 
1568
                        wo->notask_error = 0;
 
1569
                        return 0;
 
1570
                }
 
1571
 
 
1572
                /* we don't reap group leaders with subthreads */
 
1573
                if (!delay_group_leader(p))
 
1574
                        return wait_task_zombie(wo, p);
 
1575
 
 
1576
                /*
 
1577
                 * Allow access to stopped/continued state via zombie by
 
1578
                 * falling through.  Clearing of notask_error is complex.
 
1579
                 *
 
1580
                 * When !@ptrace:
 
1581
                 *
 
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.
 
1589
                 *
 
1590
                 * When @ptrace:
 
1591
                 *
 
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.
 
1595
                 */
 
1596
                if (likely(!ptrace) || (wo->wo_flags & (WCONTINUED | WEXITED)))
 
1597
                        wo->notask_error = 0;
 
1598
        } else {
 
1599
                /*
 
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.
 
1604
                 *
 
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.
 
1608
                 */
 
1609
                if (likely(!ptrace) && task_ptrace(p) &&
 
1610
                    same_thread_group(p->parent, p->real_parent))
 
1611
                        return 0;
 
1612
 
 
1613
                /*
 
1614
                 * @p is alive and it's gonna stop, continue or exit, so
 
1615
                 * there always is something to wait for.
1548
1616
                 */
1549
1617
                wo->notask_error = 0;
1550
 
                return 0;
1551
1618
        }
1552
1619
 
1553
 
        if (p->exit_state == EXIT_DEAD)
1554
 
                return 0;
1555
 
 
1556
 
        /*
1557
 
         * We don't reap group leaders with subthreads.
1558
 
         */
1559
 
        if (p->exit_state == EXIT_ZOMBIE && !delay_group_leader(p))
1560
 
                return wait_task_zombie(wo, p);
1561
 
 
1562
 
        /*
1563
 
         * It's stopped or running now, so it might
1564
 
         * later continue, exit, or stop again.
1565
 
         */
1566
 
        wo->notask_error = 0;
1567
 
 
1568
 
        if (task_stopped_code(p, ptrace))
1569
 
                return wait_task_stopped(wo, ptrace, p);
1570
 
 
 
1620
        /*
 
1621
         * Wait for stopped.  Depending on @ptrace, different stopped state
 
1622
         * is used and the two don't interact with each other.
 
1623
         */
 
1624
        ret = wait_task_stopped(wo, ptrace, p);
 
1625
        if (ret)
 
1626
                return ret;
 
1627
 
 
1628
        /*
 
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.
 
1632
         */
1571
1633
        return wait_task_continued(wo, p);
1572
1634
}
1573
1635