Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_wait.c revision 1.19.12.2
      1  1.19.12.2  christos /*	$NetBSD: netbsd32_wait.c,v 1.19.12.2 2009/01/04 01:56:02 christos Exp $	*/
      2  1.19.12.2  christos 
      3  1.19.12.2  christos /*
      4  1.19.12.2  christos  * Copyright (c) 1998, 2001 Matthew R. Green
      5  1.19.12.2  christos  * All rights reserved.
      6  1.19.12.2  christos  *
      7  1.19.12.2  christos  * Redistribution and use in source and binary forms, with or without
      8  1.19.12.2  christos  * modification, are permitted provided that the following conditions
      9  1.19.12.2  christos  * are met:
     10  1.19.12.2  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.19.12.2  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.19.12.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.19.12.2  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.19.12.2  christos  *    documentation and/or other materials provided with the distribution.
     15  1.19.12.2  christos  *
     16  1.19.12.2  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.19.12.2  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.19.12.2  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.19.12.2  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.19.12.2  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  1.19.12.2  christos  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  1.19.12.2  christos  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  1.19.12.2  christos  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  1.19.12.2  christos  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.19.12.2  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.19.12.2  christos  * SUCH DAMAGE.
     27  1.19.12.2  christos  */
     28  1.19.12.2  christos 
     29  1.19.12.2  christos #include <sys/cdefs.h>
     30  1.19.12.2  christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_wait.c,v 1.19.12.2 2009/01/04 01:56:02 christos Exp $");
     31  1.19.12.2  christos 
     32  1.19.12.2  christos #include <sys/param.h>
     33  1.19.12.2  christos #include <sys/systm.h>
     34  1.19.12.2  christos #include <sys/mount.h>
     35  1.19.12.2  christos #include <sys/time.h>
     36  1.19.12.2  christos #include <sys/wait.h>
     37  1.19.12.2  christos #include <sys/ptrace.h>
     38  1.19.12.2  christos #include <sys/resourcevar.h>
     39  1.19.12.2  christos #include <sys/vnode.h>
     40  1.19.12.2  christos #include <sys/pool.h>
     41  1.19.12.2  christos #include <sys/proc.h>
     42  1.19.12.2  christos #include <sys/dirent.h>
     43  1.19.12.2  christos 
     44  1.19.12.2  christos #include <compat/netbsd32/netbsd32.h>
     45  1.19.12.2  christos #include <compat/netbsd32/netbsd32_syscallargs.h>
     46  1.19.12.2  christos #include <compat/netbsd32/netbsd32_conv.h>
     47  1.19.12.2  christos 
     48  1.19.12.2  christos int
     49  1.19.12.2  christos netbsd32___wait450(struct lwp *l, const struct netbsd32___wait450_args *uap,
     50  1.19.12.2  christos     register_t *retval)
     51  1.19.12.2  christos {
     52  1.19.12.2  christos 	/* {
     53  1.19.12.2  christos 		syscallarg(int) pid;
     54  1.19.12.2  christos 		syscallarg(netbsd32_intp) status;
     55  1.19.12.2  christos 		syscallarg(int) options;
     56  1.19.12.2  christos 		syscallarg(netbsd32_rusagep_t) rusage;
     57  1.19.12.2  christos 	} */
     58  1.19.12.2  christos 	int		status, error;
     59  1.19.12.2  christos 	int		was_zombie;
     60  1.19.12.2  christos 	struct rusage	ru;
     61  1.19.12.2  christos 	struct netbsd32_rusage	ru32;
     62  1.19.12.2  christos 	int pid = SCARG(uap, pid);
     63  1.19.12.2  christos 
     64  1.19.12.2  christos 	error = do_sys_wait(l, &pid, &status, SCARG(uap, options),
     65  1.19.12.2  christos 	    SCARG_P32(uap, rusage) != NULL ? &ru : NULL, &was_zombie);
     66  1.19.12.2  christos 
     67  1.19.12.2  christos 	retval[0] = pid;
     68  1.19.12.2  christos 	if (pid == 0)
     69  1.19.12.2  christos 		return error;
     70  1.19.12.2  christos 
     71  1.19.12.2  christos 	if (SCARG_P32(uap, rusage)) {
     72  1.19.12.2  christos 		netbsd32_from_rusage(&ru, &ru32);
     73  1.19.12.2  christos 		error = copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
     74  1.19.12.2  christos 	}
     75  1.19.12.2  christos 
     76  1.19.12.2  christos 	if (error == 0 && SCARG_P32(uap, status))
     77  1.19.12.2  christos 		error = copyout(&status, SCARG_P32(uap, status), sizeof(status));
     78  1.19.12.2  christos 
     79  1.19.12.2  christos 	return error;
     80  1.19.12.2  christos }
     81  1.19.12.2  christos 
     82  1.19.12.2  christos 
     83  1.19.12.2  christos int
     84  1.19.12.2  christos netbsd32___getrusage50(struct lwp *l,
     85  1.19.12.2  christos     const struct netbsd32___getrusage50_args *uap, register_t *retval)
     86  1.19.12.2  christos {
     87  1.19.12.2  christos 	/* {
     88  1.19.12.2  christos 		syscallarg(int) who;
     89  1.19.12.2  christos 		syscallarg(netbsd32_rusagep_t) rusage;
     90  1.19.12.2  christos 	} */
     91  1.19.12.2  christos 	struct proc *p = l->l_proc;
     92  1.19.12.2  christos 	struct rusage *rup;
     93  1.19.12.2  christos 	struct netbsd32_rusage ru;
     94  1.19.12.2  christos 
     95  1.19.12.2  christos 	switch (SCARG(uap, who)) {
     96  1.19.12.2  christos 
     97  1.19.12.2  christos 	case RUSAGE_SELF:
     98  1.19.12.2  christos 		rup = &p->p_stats->p_ru;
     99  1.19.12.2  christos 		mutex_enter(p->p_lock);
    100  1.19.12.2  christos 		calcru(p, &rup->ru_utime, &rup->ru_stime, NULL, NULL);
    101  1.19.12.2  christos 		mutex_exit(p->p_lock);
    102  1.19.12.2  christos 		break;
    103  1.19.12.2  christos 
    104  1.19.12.2  christos 	case RUSAGE_CHILDREN:
    105  1.19.12.2  christos 		rup = &p->p_stats->p_cru;
    106  1.19.12.2  christos 		break;
    107  1.19.12.2  christos 
    108  1.19.12.2  christos 	default:
    109  1.19.12.2  christos 		return (EINVAL);
    110  1.19.12.2  christos 	}
    111  1.19.12.2  christos 	netbsd32_from_rusage(rup, &ru);
    112  1.19.12.2  christos 	return copyout(&ru, SCARG_P32(uap, rusage), sizeof(ru));
    113  1.19.12.2  christos }
    114