Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_wait.c revision 1.23.20.1
      1  1.23.20.1    martin /*	$NetBSD: netbsd32_wait.c,v 1.23.20.1 2022/08/03 11:11:31 martin 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.23.20.1    martin __KERNEL_RCSID(0, "$NetBSD: netbsd32_wait.c,v 1.23.20.1 2022/08/03 11:11:31 martin 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.20  christos netbsd32___wait450(struct lwp *l, const struct netbsd32___wait450_args *uap,
     50       1.20  christos     register_t *retval)
     51        1.1       mrg {
     52       1.17       dsl 	/* {
     53        1.1       mrg 		syscallarg(int) pid;
     54        1.1       mrg 		syscallarg(netbsd32_intp) status;
     55        1.1       mrg 		syscallarg(int) options;
     56        1.1       mrg 		syscallarg(netbsd32_rusagep_t) rusage;
     57       1.17       dsl 	} */
     58       1.21     rmind 	int error, status, pid = SCARG(uap, pid);
     59       1.21     rmind 	struct netbsd32_rusage ru32;
     60       1.21     rmind 	struct rusage ru;
     61        1.8      cube 
     62       1.21     rmind 	error = do_sys_wait(&pid, &status, SCARG(uap, options),
     63       1.21     rmind 	    SCARG_P32(uap, rusage) != NULL ? &ru : NULL);
     64        1.1       mrg 
     65       1.17       dsl 	retval[0] = pid;
     66       1.17       dsl 	if (pid == 0)
     67        1.6       dsl 		return error;
     68        1.6       dsl 
     69       1.15       dsl 	if (SCARG_P32(uap, rusage)) {
     70       1.15       dsl 		netbsd32_from_rusage(&ru, &ru32);
     71       1.14       dsl 		error = copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
     72        1.1       mrg 	}
     73        1.6       dsl 
     74       1.15       dsl 	if (error == 0 && SCARG_P32(uap, status))
     75       1.15       dsl 		error = copyout(&status, SCARG_P32(uap, status), sizeof(status));
     76       1.15       dsl 
     77        1.8      cube 	return error;
     78        1.1       mrg }
     79        1.1       mrg 
     80       1.23     skrll int
     81       1.23     skrll netbsd32_wait6(struct lwp *l, const struct netbsd32_wait6_args *uap,
     82       1.23     skrll     register_t *retval)
     83       1.23     skrll {
     84       1.23     skrll 	/* {
     85       1.23     skrll 		syscallarg(idtype_t) idtype;
     86       1.23     skrll 		syscallarg(id_t) id;
     87       1.23     skrll 		syscallarg(netbsd32_intp) status;
     88       1.23     skrll 		syscallarg(int) options;
     89       1.23     skrll 		syscallarg(netbsd32_wrusagep_t) wru;
     90       1.23     skrll 		syscallarg(netbsd32_siginfop_t) info;
     91       1.23     skrll 	} */
     92       1.23     skrll 	idtype_t idtype = SCARG(uap, idtype);
     93       1.23     skrll 	id_t id = SCARG(uap, id);
     94       1.23     skrll 	struct wrusage wru, *wrup;
     95       1.23     skrll 	siginfo_t si, *sip;
     96       1.23     skrll 	int status;
     97       1.23     skrll 	int pid;
     98       1.23     skrll 
     99       1.23     skrll 	if (SCARG_P32(uap, wru) != NULL)
    100       1.23     skrll 		wrup = &wru;
    101       1.23     skrll 	else
    102       1.23     skrll 		wrup = NULL;
    103       1.23     skrll 
    104       1.23     skrll 	if (SCARG_P32(uap, info) != NULL)
    105       1.23     skrll 		sip = &si;
    106       1.23     skrll 	else
    107       1.23     skrll 		sip = NULL;
    108       1.23     skrll 
    109       1.23     skrll 	/*
    110       1.23     skrll 	 *  We expect all callers of wait6() to know about WEXITED and
    111       1.23     skrll 	 *  WTRAPPED.
    112       1.23     skrll 	 */
    113       1.23     skrll 	int error = do_sys_waitid(idtype, id, &pid, &status,
    114       1.23     skrll 	    SCARG(uap, options), wrup, sip);
    115       1.23     skrll 
    116       1.23     skrll 	retval[0] = pid; 	/* tell userland who it was */
    117       1.23     skrll 
    118       1.23     skrll #if 0
    119       1.23     skrll 	/*
    120       1.23     skrll 	 * should we copyout if there was no process, hence no useful data?
    121       1.23     skrll 	 * We don't for an old sytle wait4() (etc) but I believe
    122       1.23     skrll 	 * FreeBSD does for wait6(), so a tossup...  Go with FreeBSD for now.
    123       1.23     skrll 	 */
    124       1.23     skrll 	if (pid == 0)
    125       1.23     skrll 		return error;
    126       1.23     skrll #endif
    127       1.23     skrll 
    128       1.23     skrll 
    129       1.23     skrll 	if (error == 0 && SCARG_P32(uap, status))
    130       1.23     skrll 		error = copyout(&status, SCARG_P32(uap, status),
    131       1.23     skrll 		    sizeof(status));
    132       1.23     skrll 	if (wrup != NULL && error == 0) {
    133       1.23     skrll 		struct netbsd32_wrusage wru32;
    134       1.23     skrll 
    135  1.23.20.1    martin 		memset(&wru32, 0, sizeof(wru32));
    136       1.23     skrll 		netbsd32_from_rusage(&wrup->wru_self, &wru32.wru_self);
    137       1.23     skrll 		netbsd32_from_rusage(&wrup->wru_children, &wru32.wru_children);
    138       1.23     skrll 		error = copyout(&wru32, SCARG_P32(uap, wru), sizeof(wru32));
    139       1.23     skrll 	}
    140       1.23     skrll 	if (sip != NULL && error == 0) {
    141       1.23     skrll 	    	siginfo32_t si32;
    142       1.23     skrll 
    143       1.23     skrll 		netbsd32_si_to_si32(&si32, sip);
    144       1.23     skrll 		error = copyout(&si32, SCARG_P32(uap, info), sizeof(si32));
    145       1.23     skrll 	}
    146       1.23     skrll 
    147       1.23     skrll 	return error;
    148       1.23     skrll }
    149       1.15       dsl 
    150        1.1       mrg int
    151       1.20  christos netbsd32___getrusage50(struct lwp *l,
    152       1.20  christos     const struct netbsd32___getrusage50_args *uap, register_t *retval)
    153        1.1       mrg {
    154       1.17       dsl 	/* {
    155        1.1       mrg 		syscallarg(int) who;
    156        1.1       mrg 		syscallarg(netbsd32_rusagep_t) rusage;
    157       1.17       dsl 	} */
    158       1.22     njoly 	int error;
    159        1.5   thorpej 	struct proc *p = l->l_proc;
    160       1.22     njoly 	struct rusage ru;
    161       1.22     njoly 	struct netbsd32_rusage ru32;
    162        1.1       mrg 
    163       1.22     njoly 	error = getrusage1(p, SCARG(uap, who), &ru);
    164       1.22     njoly 	if (error != 0)
    165       1.22     njoly 		return error;
    166        1.1       mrg 
    167       1.22     njoly 	netbsd32_from_rusage(&ru, &ru32);
    168       1.22     njoly 	return copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
    169        1.1       mrg }
    170