kern_exit.c (135763) | kern_exit.c (136152) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_exit.c 8.7 (Berkeley) 2/12/94 35 */ 36 37#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_exit.c 8.7 (Berkeley) 2/12/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/kern/kern_exit.c 135763 2004-09-24 20:27:04Z jhb $"); | 38__FBSDID("$FreeBSD: head/sys/kern/kern_exit.c 136152 2004-10-05 18:51:11Z jhb $"); |
39 40#include "opt_compat.h" 41#include "opt_ktrace.h" 42#include "opt_mac.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/sysproto.h> --- 358 unchanged lines hidden (view full) --- 405 if (q->p_flag & P_TRACED) { 406 q->p_flag &= ~P_TRACED; 407 psignal(q, SIGKILL); 408 } 409 PROC_UNLOCK(q); 410 } 411 412 /* | 39 40#include "opt_compat.h" 41#include "opt_ktrace.h" 42#include "opt_mac.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/sysproto.h> --- 358 unchanged lines hidden (view full) --- 405 if (q->p_flag & P_TRACED) { 406 q->p_flag &= ~P_TRACED; 407 psignal(q, SIGKILL); 408 } 409 PROC_UNLOCK(q); 410 } 411 412 /* |
413 * Save exit status and final rusage info, adding in child rusage 414 * info and self times. | 413 * Save exit status and finalize rusage info except for times, 414 * adding in child rusage info. |
415 */ | 415 */ |
416 mtx_lock(&Giant); | |
417 PROC_LOCK(p); 418 p->p_xstat = rv; 419 p->p_xthread = td; | 416 PROC_LOCK(p); 417 p->p_xstat = rv; 418 p->p_xthread = td; |
419 p->p_stats->p_ru.ru_nvcsw++; |
|
420 *p->p_ru = p->p_stats->p_ru; | 420 *p->p_ru = p->p_stats->p_ru; |
421 mtx_lock_spin(&sched_lock); 422 calcru(p, &p->p_ru->ru_utime, &p->p_ru->ru_stime, NULL); 423 mtx_unlock_spin(&sched_lock); 424 ruadd(p->p_ru, &p->p_stats->p_cru); | 421 ruadd(p->p_ru, &p->p_rux, &p->p_stats->p_cru, &p->p_crux); |
425 | 422 |
426 mtx_unlock(&Giant); | |
427 /* 428 * Notify interested parties of our demise. 429 */ 430 KNOTE_LOCKED(&p->p_klist, NOTE_EXIT); 431 432 /* 433 * Just delete all entries in the p_klist. At this point we won't 434 * report any more events, and there are nasty race conditions that --- 47 unchanged lines hidden (view full) --- 482 * vm_waitproc(). 483 */ 484 cpu_exit(td); 485 486 PROC_LOCK(p); 487 PROC_LOCK(p->p_pptr); 488 sx_xunlock(&proctree_lock); 489 | 423 /* 424 * Notify interested parties of our demise. 425 */ 426 KNOTE_LOCKED(&p->p_klist, NOTE_EXIT); 427 428 /* 429 * Just delete all entries in the p_klist. At this point we won't 430 * report any more events, and there are nasty race conditions that --- 47 unchanged lines hidden (view full) --- 478 * vm_waitproc(). 479 */ 480 cpu_exit(td); 481 482 PROC_LOCK(p); 483 PROC_LOCK(p->p_pptr); 484 sx_xunlock(&proctree_lock); 485 |
490 while (mtx_owned(&Giant)) 491 mtx_unlock(&Giant); 492 | |
493 /* 494 * We have to wait until after acquiring all locks before 495 * changing p_state. We need to avoid all possible context 496 * switches (including ones from blocking on a mutex) while 497 * marked as a zombie. 498 */ 499 mtx_lock_spin(&sched_lock); 500 p->p_state = PRS_ZOMBIE; 501 502 critical_enter(); 503 mtx_unlock_spin(&sched_lock); 504 wakeup(p->p_pptr); 505 PROC_UNLOCK(p->p_pptr); 506 mtx_lock_spin(&sched_lock); 507 critical_exit(); 508 509 /* Do the same timestamp bookkeeping that mi_switch() would do. */ 510 binuptime(&new_switchtime); | 486 /* 487 * We have to wait until after acquiring all locks before 488 * changing p_state. We need to avoid all possible context 489 * switches (including ones from blocking on a mutex) while 490 * marked as a zombie. 491 */ 492 mtx_lock_spin(&sched_lock); 493 p->p_state = PRS_ZOMBIE; 494 495 critical_enter(); 496 mtx_unlock_spin(&sched_lock); 497 wakeup(p->p_pptr); 498 PROC_UNLOCK(p->p_pptr); 499 mtx_lock_spin(&sched_lock); 500 critical_exit(); 501 502 /* Do the same timestamp bookkeeping that mi_switch() would do. */ 503 binuptime(&new_switchtime); |
511 bintime_add(&p->p_runtime, &new_switchtime); 512 bintime_sub(&p->p_runtime, PCPU_PTR(switchtime)); | 504 bintime_add(&p->p_rux.rux_runtime, &new_switchtime); 505 bintime_sub(&p->p_rux.rux_runtime, PCPU_PTR(switchtime)); |
513 PCPU_SET(switchtime, new_switchtime); 514 PCPU_SET(switchticks, ticks); 515 cnt.v_swtch++; 516 517 sched_exit(p->p_pptr, td); 518 519 /* 520 * Hopefully no one will try to deliver a signal to the process this --- 30 unchanged lines hidden (view full) --- 551/* 552 * The dirty work is handled by kern_wait(). 553 * 554 * MPSAFE. 555 */ 556int 557wait4(struct thread *td, struct wait_args *uap) 558{ | 506 PCPU_SET(switchtime, new_switchtime); 507 PCPU_SET(switchticks, ticks); 508 cnt.v_swtch++; 509 510 sched_exit(p->p_pptr, td); 511 512 /* 513 * Hopefully no one will try to deliver a signal to the process this --- 30 unchanged lines hidden (view full) --- 544/* 545 * The dirty work is handled by kern_wait(). 546 * 547 * MPSAFE. 548 */ 549int 550wait4(struct thread *td, struct wait_args *uap) 551{ |
559 struct rusage ru; | 552 struct rusage ru, *rup; |
560 int error, status; 561 | 553 int error, status; 554 |
562 error = kern_wait(td, uap->pid, &status, uap->options, &ru); | 555 if (uap->rusage != NULL) 556 rup = &ru; 557 else 558 rup = NULL; 559 error = kern_wait(td, uap->pid, &status, uap->options, rup); |
563 if (uap->status != NULL && error == 0) 564 error = copyout(&status, uap->status, sizeof(status)); 565 if (uap->rusage != NULL && error == 0) 566 error = copyout(&ru, uap->rusage, sizeof(struct rusage)); 567 return (error); 568} 569 570int --- 36 unchanged lines hidden (view full) --- 607 continue; 608 } 609 610 nfound++; 611 if (p->p_state == PRS_ZOMBIE) { 612 td->td_retval[0] = p->p_pid; 613 if (status) 614 *status = p->p_xstat; /* convert to int */ | 560 if (uap->status != NULL && error == 0) 561 error = copyout(&status, uap->status, sizeof(status)); 562 if (uap->rusage != NULL && error == 0) 563 error = copyout(&ru, uap->rusage, sizeof(struct rusage)); 564 return (error); 565} 566 567int --- 36 unchanged lines hidden (view full) --- 604 continue; 605 } 606 607 nfound++; 608 if (p->p_state == PRS_ZOMBIE) { 609 td->td_retval[0] = p->p_pid; 610 if (status) 611 *status = p->p_xstat; /* convert to int */ |
615 if (rusage) | 612 if (rusage) { |
616 bcopy(p->p_ru, rusage, sizeof(struct rusage)); | 613 bcopy(p->p_ru, rusage, sizeof(struct rusage)); |
614 calcru(p, &rusage->ru_utime, &rusage->ru_stime); 615 } |
|
617 618 /* 619 * If we got the child via a ptrace 'attach', 620 * we need to give it back to the old parent. 621 */ 622 PROC_UNLOCK(p); 623 if (p->p_oppid && (t = pfind(p->p_oppid)) != NULL) { 624 PROC_LOCK(p); --- 18 unchanged lines hidden (view full) --- 643 leavepgrp(p); 644 sx_xunlock(&proctree_lock); 645 646 /* 647 * As a side effect of this lock, we know that 648 * all other writes to this proc are visible now, so 649 * no more locking is needed for p. 650 */ | 616 617 /* 618 * If we got the child via a ptrace 'attach', 619 * we need to give it back to the old parent. 620 */ 621 PROC_UNLOCK(p); 622 if (p->p_oppid && (t = pfind(p->p_oppid)) != NULL) { 623 PROC_LOCK(p); --- 18 unchanged lines hidden (view full) --- 642 leavepgrp(p); 643 sx_xunlock(&proctree_lock); 644 645 /* 646 * As a side effect of this lock, we know that 647 * all other writes to this proc are visible now, so 648 * no more locking is needed for p. 649 */ |
651 mtx_lock(&Giant); | |
652 PROC_LOCK(p); 653 p->p_xstat = 0; /* XXX: why? */ 654 PROC_UNLOCK(p); 655 PROC_LOCK(q); | 650 PROC_LOCK(p); 651 p->p_xstat = 0; /* XXX: why? */ 652 PROC_UNLOCK(p); 653 PROC_LOCK(q); |
656 ruadd(&q->p_stats->p_cru, p->p_ru); | 654 ruadd(&q->p_stats->p_cru, &q->p_crux, p->p_ru, 655 &p->p_rux); |
657 PROC_UNLOCK(q); 658 FREE(p->p_ru, M_ZOMBIE); 659 p->p_ru = NULL; | 656 PROC_UNLOCK(q); 657 FREE(p->p_ru, M_ZOMBIE); 658 p->p_ru = NULL; |
660 mtx_unlock(&Giant); | |
661 662 /* 663 * Decrement the count of procs running with this uid. 664 */ 665 (void)chgproccnt(p->p_ucred->cr_ruidinfo, -1, 0); 666 667 /* 668 * Free credentials, arguments, and sigacts. --- 91 unchanged lines hidden --- | 659 660 /* 661 * Decrement the count of procs running with this uid. 662 */ 663 (void)chgproccnt(p->p_ucred->cr_ruidinfo, -1, 0); 664 665 /* 666 * Free credentials, arguments, and sigacts. --- 91 unchanged lines hidden --- |