Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_lwp.c revision 1.12.4.3
      1  1.12.4.3      yamt /*	$NetBSD: netbsd32_lwp.c,v 1.12.4.3 2014/05/22 11:40:17 yamt Exp $	*/
      2       1.1      cube 
      3       1.1      cube /*
      4       1.1      cube  *  Copyright (c) 2005, 2006, 2007 The NetBSD Foundation.
      5       1.1      cube  *  All rights reserved.
      6       1.1      cube  *
      7       1.1      cube  *  Redistribution and use in source and binary forms, with or without
      8       1.1      cube  *  modification, are permitted provided that the following conditions
      9       1.1      cube  *  are met:
     10       1.1      cube  *  1. Redistributions of source code must retain the above copyright
     11       1.1      cube  *     notice, this list of conditions and the following disclaimer.
     12       1.1      cube  *  2. Redistributions in binary form must reproduce the above copyright
     13       1.1      cube  *     notice, this list of conditions and the following disclaimer in the
     14       1.1      cube  *     documentation and/or other materials provided with the distribution.
     15       1.1      cube  *
     16       1.1      cube  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17       1.1      cube  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18       1.1      cube  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19       1.1      cube  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20       1.1      cube  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21       1.1      cube  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22       1.1      cube  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23       1.1      cube  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24       1.1      cube  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25       1.1      cube  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1      cube  *  POSSIBILITY OF SUCH DAMAGE.
     27       1.1      cube  */
     28       1.1      cube 
     29       1.1      cube #include <sys/cdefs.h>
     30  1.12.4.3      yamt __KERNEL_RCSID(0, "$NetBSD: netbsd32_lwp.c,v 1.12.4.3 2014/05/22 11:40:17 yamt Exp $");
     31       1.1      cube 
     32       1.1      cube #include <sys/types.h>
     33       1.1      cube #include <sys/param.h>
     34       1.1      cube #include <sys/systm.h>
     35       1.1      cube #include <sys/kernel.h>
     36       1.1      cube #include <sys/dirent.h>
     37       1.1      cube #include <sys/mount.h>
     38       1.1      cube #include <sys/proc.h>
     39       1.1      cube #include <sys/syscallargs.h>
     40       1.8        ad #include <sys/lwpctl.h>
     41       1.1      cube 
     42       1.1      cube #include <compat/netbsd32/netbsd32.h>
     43       1.1      cube #include <compat/netbsd32/netbsd32_syscallargs.h>
     44       1.1      cube #include <compat/netbsd32/netbsd32_conv.h>
     45       1.1      cube 
     46       1.1      cube /* Sycalls conversion */
     47       1.1      cube 
     48       1.1      cube int
     49       1.9       dsl netbsd32__lwp_create(struct lwp *l, const struct netbsd32__lwp_create_args *uap, register_t *retval)
     50       1.1      cube {
     51       1.9       dsl 	/* {
     52       1.1      cube 		syscallarg(const netbsd32_ucontextp) ucp;
     53       1.1      cube 		syscallarg(netbsd32_u_long) flags;
     54       1.1      cube 		syscallarg(netbsd32_lwpidp) new_lwp;
     55       1.9       dsl 	} */
     56  1.12.4.1      yamt 	struct proc *p = l->l_proc;
     57  1.12.4.1      yamt 	ucontext32_t *newuc = NULL;
     58  1.12.4.1      yamt 	lwpid_t lid;
     59  1.12.4.1      yamt 	int error;
     60       1.1      cube 
     61  1.12.4.1      yamt 	KASSERT(p->p_emul->e_ucsize == sizeof(*newuc));
     62       1.1      cube 
     63  1.12.4.2      yamt 	newuc = kmem_alloc(sizeof(ucontext_t), KM_SLEEP);
     64  1.12.4.1      yamt 	error = copyin(SCARG_P32(uap, ucp), newuc, p->p_emul->e_ucsize);
     65  1.12.4.1      yamt 	if (error)
     66  1.12.4.1      yamt 		goto fail;
     67  1.12.4.1      yamt 
     68  1.12.4.1      yamt 	/* validate the ucontext */
     69  1.12.4.1      yamt 	if ((newuc->uc_flags & _UC_CPU) == 0) {
     70  1.12.4.1      yamt 		error = EINVAL;
     71  1.12.4.1      yamt 		goto fail;
     72  1.12.4.1      yamt 	}
     73  1.12.4.1      yamt 	error = cpu_mcontext32_validate(l, &newuc->uc_mcontext);
     74  1.12.4.1      yamt 	if (error)
     75  1.12.4.1      yamt 		goto fail;
     76  1.12.4.1      yamt 
     77  1.12.4.1      yamt 	error = do_lwp_create(l, newuc, SCARG(uap, flags), &lid);
     78  1.12.4.1      yamt 	if (error)
     79  1.12.4.1      yamt 		goto fail;
     80  1.12.4.1      yamt 
     81  1.12.4.1      yamt 	/*
     82  1.12.4.1      yamt 	 * do not free ucontext in case of an error here,
     83  1.12.4.1      yamt 	 * the lwp will actually run and access it
     84  1.12.4.1      yamt 	 */
     85  1.12.4.1      yamt 	return copyout(&lid, SCARG_P32(uap, new_lwp), sizeof(lid));
     86  1.12.4.1      yamt 
     87  1.12.4.1      yamt fail:
     88  1.12.4.2      yamt 	kmem_free(newuc, sizeof(ucontext_t));
     89  1.12.4.1      yamt 	return error;
     90       1.1      cube }
     91       1.1      cube 
     92       1.1      cube int
     93       1.9       dsl netbsd32__lwp_wait(struct lwp *l, const struct netbsd32__lwp_wait_args *uap, register_t *retval)
     94       1.1      cube {
     95       1.9       dsl 	/* {
     96       1.1      cube 		syscallarg(lwpid_t) wait_for;
     97       1.1      cube 		syscallarg(netbsd32_lwpidp) departed;
     98       1.9       dsl 	} */
     99       1.1      cube 	struct sys__lwp_wait_args ua;
    100       1.1      cube 
    101       1.1      cube 	NETBSD32TO64_UAP(wait_for);
    102       1.1      cube 	NETBSD32TOP_UAP(departed, lwpid_t);
    103       1.1      cube 	return sys__lwp_wait(l, &ua, retval);
    104       1.1      cube }
    105       1.1      cube 
    106       1.1      cube int
    107       1.9       dsl netbsd32__lwp_suspend(struct lwp *l, const struct netbsd32__lwp_suspend_args *uap, register_t *retval)
    108       1.1      cube {
    109       1.9       dsl 	/* {
    110       1.1      cube 		syscallarg(lwpid_t) target;
    111       1.9       dsl 	} */
    112       1.1      cube 	struct sys__lwp_suspend_args ua;
    113       1.1      cube 
    114       1.1      cube 	NETBSD32TO64_UAP(target);
    115       1.1      cube 	return sys__lwp_suspend(l, &ua, retval);
    116       1.1      cube }
    117       1.1      cube 
    118       1.1      cube int
    119       1.9       dsl netbsd32__lwp_continue(struct lwp *l, const struct netbsd32__lwp_continue_args *uap, register_t *retval)
    120       1.1      cube {
    121       1.9       dsl 	/* {
    122       1.1      cube 		syscallarg(lwpid_t) target;
    123       1.9       dsl 	} */
    124       1.1      cube 	struct sys__lwp_continue_args ua;
    125       1.1      cube 
    126       1.1      cube 	NETBSD32TO64_UAP(target);
    127       1.1      cube 	return sys__lwp_continue(l, &ua, retval);
    128       1.1      cube }
    129       1.1      cube 
    130       1.1      cube int
    131       1.9       dsl netbsd32__lwp_wakeup(struct lwp *l, const struct netbsd32__lwp_wakeup_args *uap, register_t *retval)
    132       1.1      cube {
    133       1.9       dsl 	/* {
    134       1.1      cube 		syscallarg(lwpid_t) target;
    135       1.9       dsl 	} */
    136       1.1      cube 	struct sys__lwp_wakeup_args ua;
    137       1.1      cube 
    138       1.1      cube 	NETBSD32TO64_UAP(target);
    139       1.1      cube 	return sys__lwp_wakeup(l, &ua, retval);
    140       1.1      cube }
    141       1.1      cube 
    142       1.1      cube int
    143       1.9       dsl netbsd32__lwp_setprivate(struct lwp *l, const struct netbsd32__lwp_setprivate_args *uap, register_t *retval)
    144       1.1      cube {
    145       1.9       dsl 	/* {
    146       1.1      cube 		syscallarg(netbsd32_voidp) ptr;
    147       1.9       dsl 	} */
    148       1.1      cube 	struct sys__lwp_setprivate_args ua;
    149       1.1      cube 
    150       1.1      cube 	NETBSD32TOP_UAP(ptr, void);
    151       1.1      cube 	return sys__lwp_setprivate(l, &ua, retval);
    152       1.1      cube }
    153       1.1      cube 
    154       1.1      cube int
    155  1.12.4.3      yamt netbsd32____lwp_park60(struct lwp *l,
    156  1.12.4.3      yamt     const struct netbsd32____lwp_park60_args *uap, register_t *retval)
    157       1.1      cube {
    158       1.9       dsl 	/* {
    159  1.12.4.3      yamt 		syscallarg(const netbsd32_clockid_t) clock_id;
    160  1.12.4.3      yamt 		syscallarg(int) flags;
    161      1.11  christos 		syscallarg(const netbsd32_timespec50p) ts;
    162  1.12.4.3      yamt 		syscallarg(netbsd32_lwpid_t) unpark;
    163       1.1      cube 		syscallarg(netbsd32_voidp) hint;
    164       1.6        ad 		syscallarg(netbsd32_voidp) unparkhint;
    165       1.9       dsl 	} */
    166       1.6        ad 	struct timespec ts, *tsp;
    167       1.5       dsl 	struct netbsd32_timespec ts32;
    168       1.5       dsl 	int error;
    169       1.1      cube 
    170       1.5       dsl 	if (SCARG_P32(uap, ts) == NULL)
    171       1.6        ad 		tsp = NULL;
    172       1.6        ad 	else {
    173       1.6        ad 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32);
    174       1.6        ad 		if (error != 0)
    175       1.6        ad 			return error;
    176       1.6        ad 		netbsd32_to_timespec(&ts32, &ts);
    177       1.6        ad 		tsp = &ts;
    178       1.6        ad 	}
    179       1.6        ad 
    180       1.6        ad 	if (SCARG(uap, unpark) != 0) {
    181       1.6        ad 		error = lwp_unpark(SCARG(uap, unpark),
    182       1.6        ad 		    SCARG_P32(uap, unparkhint));
    183       1.6        ad 		if (error != 0)
    184       1.6        ad 			return error;
    185       1.6        ad 	}
    186       1.5       dsl 
    187  1.12.4.3      yamt 	return lwp_park(SCARG(uap, clock_id), SCARG(uap, flags), tsp,
    188  1.12.4.3      yamt 	    SCARG_P32(uap, hint));
    189       1.1      cube }
    190       1.1      cube 
    191       1.1      cube int
    192       1.9       dsl netbsd32__lwp_kill(struct lwp *l, const struct netbsd32__lwp_kill_args *uap, register_t *retval)
    193       1.1      cube {
    194       1.9       dsl 	/* {
    195       1.1      cube 		syscallarg(lwpid_t) target;
    196       1.1      cube 		syscallarg(int) signo;
    197       1.9       dsl 	} */
    198       1.1      cube 	struct sys__lwp_kill_args ua;
    199       1.1      cube 
    200       1.1      cube 	NETBSD32TO64_UAP(target);
    201       1.1      cube 	NETBSD32TO64_UAP(signo);
    202       1.1      cube 	return sys__lwp_kill(l, &ua, retval);
    203       1.1      cube }
    204       1.1      cube int
    205       1.9       dsl netbsd32__lwp_detach(struct lwp *l, const struct netbsd32__lwp_detach_args *uap, register_t *retval)
    206       1.1      cube {
    207       1.9       dsl 	/* {
    208       1.1      cube 		syscallarg(lwpid_t) target;
    209       1.9       dsl 	} */
    210       1.1      cube 	struct sys__lwp_detach_args ua;
    211       1.1      cube 
    212       1.1      cube 	NETBSD32TO64_UAP(target);
    213       1.1      cube 	return sys__lwp_detach(l, &ua, retval);
    214       1.1      cube }
    215       1.1      cube 
    216       1.1      cube int
    217       1.9       dsl netbsd32__lwp_unpark(struct lwp *l, const struct netbsd32__lwp_unpark_args *uap, register_t *retval)
    218       1.1      cube {
    219       1.9       dsl 	/* {
    220       1.1      cube 		syscallarg(lwpid_t) target;
    221       1.1      cube 		syscallarg(netbsd32_voidp) hint;
    222       1.9       dsl 	} */
    223       1.1      cube 	struct sys__lwp_unpark_args ua;
    224       1.1      cube 
    225       1.1      cube 	NETBSD32TO64_UAP(target);
    226       1.1      cube 	NETBSD32TOP_UAP(hint, void);
    227       1.1      cube 	return sys__lwp_unpark(l, &ua, retval);
    228       1.1      cube }
    229       1.1      cube 
    230       1.1      cube int
    231       1.9       dsl netbsd32__lwp_unpark_all(struct lwp *l, const struct netbsd32__lwp_unpark_all_args *uap, register_t *retval)
    232       1.1      cube {
    233       1.9       dsl 	/* {
    234       1.1      cube 		syscallarg(const netbsd32_lwpidp) targets;
    235       1.1      cube 		syscallarg(netbsd32_size_t) ntargets;
    236       1.1      cube 		syscallarg(netbsd32_voidp) hint;
    237       1.9       dsl 	} */
    238       1.1      cube 	struct sys__lwp_unpark_all_args ua;
    239       1.1      cube 
    240       1.1      cube 	NETBSD32TOP_UAP(targets, const lwpid_t);
    241       1.1      cube 	NETBSD32TOX_UAP(ntargets, size_t);
    242       1.1      cube 	NETBSD32TOP_UAP(hint, void);
    243       1.1      cube 	return sys__lwp_unpark_all(l, &ua, retval);
    244       1.1      cube }
    245       1.8        ad 
    246       1.8        ad int
    247       1.9       dsl netbsd32__lwp_setname(struct lwp *l, const struct netbsd32__lwp_setname_args *uap, register_t *retval)
    248       1.8        ad {
    249       1.9       dsl 	/* {
    250       1.8        ad 		syscallarg(lwpid_t) target;
    251       1.8        ad 		syscallarg(const netbsd32_charp) name;
    252       1.9       dsl 	} */
    253       1.8        ad 	struct sys__lwp_setname_args ua;
    254       1.8        ad 
    255       1.8        ad 	NETBSD32TO64_UAP(target);
    256       1.8        ad 	NETBSD32TOP_UAP(name, char *);
    257       1.8        ad 	return sys__lwp_setname(l, &ua, retval);
    258       1.8        ad }
    259       1.8        ad 
    260       1.8        ad int
    261       1.9       dsl netbsd32__lwp_getname(struct lwp *l, const struct netbsd32__lwp_getname_args *uap, register_t *retval)
    262       1.8        ad {
    263       1.9       dsl 	/* {
    264       1.8        ad 		syscallarg(lwpid_t) target;
    265       1.8        ad 		syscallarg(netbsd32_charp) name;
    266       1.8        ad 		syscallarg(netbsd32_size_t) len;
    267       1.9       dsl 	} */
    268       1.8        ad 	struct sys__lwp_getname_args ua;
    269       1.8        ad 
    270       1.8        ad 	NETBSD32TO64_UAP(target);
    271       1.8        ad 	NETBSD32TOP_UAP(name, char *);
    272       1.8        ad 	NETBSD32TOX_UAP(len, size_t);
    273       1.8        ad 	return sys__lwp_getname(l, &ua, retval);
    274       1.8        ad }
    275       1.8        ad 
    276       1.8        ad int
    277       1.9       dsl netbsd32__lwp_ctl(struct lwp *l, const struct netbsd32__lwp_ctl_args *uap, register_t *retval)
    278       1.8        ad {
    279       1.9       dsl 	/* {
    280       1.8        ad 		syscallarg(int) features;
    281       1.8        ad 		syscallarg(netbsd32_pointer_t) address;
    282       1.9       dsl 	} */
    283       1.8        ad 	struct sys__lwp_ctl_args ua;
    284       1.8        ad 
    285       1.8        ad 	NETBSD32TO64_UAP(features);
    286       1.8        ad 	NETBSD32TOP_UAP(address, struct lwpctl *);
    287       1.8        ad 	return sys__lwp_ctl(l, &ua, retval);
    288       1.8        ad }
    289