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