Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_lwp.c revision 1.12.10.2
      1  1.12.10.2       riz /*	$NetBSD: netbsd32_lwp.c,v 1.12.10.2 2012/07/21 00:01:45 riz 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.10.2       riz __KERNEL_RCSID(0, "$NetBSD: netbsd32_lwp.c,v 1.12.10.2 2012/07/21 00:01:45 riz 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.10.1       riz 	struct proc *p = l->l_proc;
     57  1.12.10.1       riz 	ucontext32_t *newuc = NULL;
     58  1.12.10.1       riz 	lwpid_t lid;
     59  1.12.10.1       riz 	int error;
     60        1.1      cube 
     61  1.12.10.1       riz 	KASSERT(p->p_emul->e_ucsize == sizeof(*newuc));
     62        1.1      cube 
     63  1.12.10.2       riz 	newuc = kmem_alloc(sizeof(ucontext_t), KM_SLEEP);
     64  1.12.10.1       riz 	error = copyin(SCARG_P32(uap, ucp), newuc, p->p_emul->e_ucsize);
     65  1.12.10.1       riz 	if (error)
     66  1.12.10.1       riz 		goto fail;
     67  1.12.10.1       riz 
     68  1.12.10.1       riz 	/* validate the ucontext */
     69  1.12.10.1       riz 	if ((newuc->uc_flags & _UC_CPU) == 0) {
     70  1.12.10.1       riz 		error = EINVAL;
     71  1.12.10.1       riz 		goto fail;
     72  1.12.10.1       riz 	}
     73  1.12.10.1       riz 	error = cpu_mcontext32_validate(l, &newuc->uc_mcontext);
     74  1.12.10.1       riz 	if (error)
     75  1.12.10.1       riz 		goto fail;
     76  1.12.10.1       riz 
     77  1.12.10.1       riz 	error = do_lwp_create(l, newuc, SCARG(uap, flags), &lid);
     78  1.12.10.1       riz 	if (error)
     79  1.12.10.1       riz 		goto fail;
     80  1.12.10.1       riz 
     81  1.12.10.1       riz 	/*
     82  1.12.10.1       riz 	 * do not free ucontext in case of an error here,
     83  1.12.10.1       riz 	 * the lwp will actually run and access it
     84  1.12.10.1       riz 	 */
     85  1.12.10.1       riz 	return copyout(&lid, SCARG_P32(uap, new_lwp), sizeof(lid));
     86  1.12.10.1       riz 
     87  1.12.10.1       riz fail:
     88  1.12.10.2       riz 	kmem_free(newuc, sizeof(ucontext_t));
     89  1.12.10.1       riz 	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.11  christos netbsd32____lwp_park50(struct lwp *l,
    156       1.11  christos     const struct netbsd32____lwp_park50_args *uap, register_t *retval)
    157        1.1      cube {
    158        1.9       dsl 	/* {
    159       1.11  christos 		syscallarg(const netbsd32_timespec50p) ts;
    160        1.6        ad 		syscallarg(lwpid_t) unpark;
    161        1.1      cube 		syscallarg(netbsd32_voidp) hint;
    162        1.6        ad 		syscallarg(netbsd32_voidp) unparkhint;
    163        1.9       dsl 	} */
    164        1.6        ad 	struct timespec ts, *tsp;
    165        1.5       dsl 	struct netbsd32_timespec ts32;
    166        1.5       dsl 	int error;
    167        1.1      cube 
    168        1.5       dsl 	if (SCARG_P32(uap, ts) == NULL)
    169        1.6        ad 		tsp = NULL;
    170        1.6        ad 	else {
    171        1.6        ad 		error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32);
    172        1.6        ad 		if (error != 0)
    173        1.6        ad 			return error;
    174        1.6        ad 		netbsd32_to_timespec(&ts32, &ts);
    175        1.6        ad 		tsp = &ts;
    176        1.6        ad 	}
    177        1.6        ad 
    178        1.6        ad 	if (SCARG(uap, unpark) != 0) {
    179        1.6        ad 		error = lwp_unpark(SCARG(uap, unpark),
    180        1.6        ad 		    SCARG_P32(uap, unparkhint));
    181        1.6        ad 		if (error != 0)
    182        1.6        ad 			return error;
    183        1.6        ad 	}
    184        1.5       dsl 
    185        1.6        ad 	return lwp_park(tsp, SCARG_P32(uap, hint));
    186        1.1      cube }
    187        1.1      cube 
    188        1.1      cube int
    189        1.9       dsl netbsd32__lwp_kill(struct lwp *l, const struct netbsd32__lwp_kill_args *uap, register_t *retval)
    190        1.1      cube {
    191        1.9       dsl 	/* {
    192        1.1      cube 		syscallarg(lwpid_t) target;
    193        1.1      cube 		syscallarg(int) signo;
    194        1.9       dsl 	} */
    195        1.1      cube 	struct sys__lwp_kill_args ua;
    196        1.1      cube 
    197        1.1      cube 	NETBSD32TO64_UAP(target);
    198        1.1      cube 	NETBSD32TO64_UAP(signo);
    199        1.1      cube 	return sys__lwp_kill(l, &ua, retval);
    200        1.1      cube }
    201        1.1      cube int
    202        1.9       dsl netbsd32__lwp_detach(struct lwp *l, const struct netbsd32__lwp_detach_args *uap, register_t *retval)
    203        1.1      cube {
    204        1.9       dsl 	/* {
    205        1.1      cube 		syscallarg(lwpid_t) target;
    206        1.9       dsl 	} */
    207        1.1      cube 	struct sys__lwp_detach_args ua;
    208        1.1      cube 
    209        1.1      cube 	NETBSD32TO64_UAP(target);
    210        1.1      cube 	return sys__lwp_detach(l, &ua, retval);
    211        1.1      cube }
    212        1.1      cube 
    213        1.1      cube int
    214        1.9       dsl netbsd32__lwp_unpark(struct lwp *l, const struct netbsd32__lwp_unpark_args *uap, register_t *retval)
    215        1.1      cube {
    216        1.9       dsl 	/* {
    217        1.1      cube 		syscallarg(lwpid_t) target;
    218        1.1      cube 		syscallarg(netbsd32_voidp) hint;
    219        1.9       dsl 	} */
    220        1.1      cube 	struct sys__lwp_unpark_args ua;
    221        1.1      cube 
    222        1.1      cube 	NETBSD32TO64_UAP(target);
    223        1.1      cube 	NETBSD32TOP_UAP(hint, void);
    224        1.1      cube 	return sys__lwp_unpark(l, &ua, retval);
    225        1.1      cube }
    226        1.1      cube 
    227        1.1      cube int
    228        1.9       dsl netbsd32__lwp_unpark_all(struct lwp *l, const struct netbsd32__lwp_unpark_all_args *uap, register_t *retval)
    229        1.1      cube {
    230        1.9       dsl 	/* {
    231        1.1      cube 		syscallarg(const netbsd32_lwpidp) targets;
    232        1.1      cube 		syscallarg(netbsd32_size_t) ntargets;
    233        1.1      cube 		syscallarg(netbsd32_voidp) hint;
    234        1.9       dsl 	} */
    235        1.1      cube 	struct sys__lwp_unpark_all_args ua;
    236        1.1      cube 
    237        1.1      cube 	NETBSD32TOP_UAP(targets, const lwpid_t);
    238        1.1      cube 	NETBSD32TOX_UAP(ntargets, size_t);
    239        1.1      cube 	NETBSD32TOP_UAP(hint, void);
    240        1.1      cube 	return sys__lwp_unpark_all(l, &ua, retval);
    241        1.1      cube }
    242        1.8        ad 
    243        1.8        ad int
    244        1.9       dsl netbsd32__lwp_setname(struct lwp *l, const struct netbsd32__lwp_setname_args *uap, register_t *retval)
    245        1.8        ad {
    246        1.9       dsl 	/* {
    247        1.8        ad 		syscallarg(lwpid_t) target;
    248        1.8        ad 		syscallarg(const netbsd32_charp) name;
    249        1.9       dsl 	} */
    250        1.8        ad 	struct sys__lwp_setname_args ua;
    251        1.8        ad 
    252        1.8        ad 	NETBSD32TO64_UAP(target);
    253        1.8        ad 	NETBSD32TOP_UAP(name, char *);
    254        1.8        ad 	return sys__lwp_setname(l, &ua, retval);
    255        1.8        ad }
    256        1.8        ad 
    257        1.8        ad int
    258        1.9       dsl netbsd32__lwp_getname(struct lwp *l, const struct netbsd32__lwp_getname_args *uap, register_t *retval)
    259        1.8        ad {
    260        1.9       dsl 	/* {
    261        1.8        ad 		syscallarg(lwpid_t) target;
    262        1.8        ad 		syscallarg(netbsd32_charp) name;
    263        1.8        ad 		syscallarg(netbsd32_size_t) len;
    264        1.9       dsl 	} */
    265        1.8        ad 	struct sys__lwp_getname_args ua;
    266        1.8        ad 
    267        1.8        ad 	NETBSD32TO64_UAP(target);
    268        1.8        ad 	NETBSD32TOP_UAP(name, char *);
    269        1.8        ad 	NETBSD32TOX_UAP(len, size_t);
    270        1.8        ad 	return sys__lwp_getname(l, &ua, retval);
    271        1.8        ad }
    272        1.8        ad 
    273        1.8        ad int
    274        1.9       dsl netbsd32__lwp_ctl(struct lwp *l, const struct netbsd32__lwp_ctl_args *uap, register_t *retval)
    275        1.8        ad {
    276        1.9       dsl 	/* {
    277        1.8        ad 		syscallarg(int) features;
    278        1.8        ad 		syscallarg(netbsd32_pointer_t) address;
    279        1.9       dsl 	} */
    280        1.8        ad 	struct sys__lwp_ctl_args ua;
    281        1.8        ad 
    282        1.8        ad 	NETBSD32TO64_UAP(features);
    283        1.8        ad 	NETBSD32TOP_UAP(address, struct lwpctl *);
    284        1.8        ad 	return sys__lwp_ctl(l, &ua, retval);
    285        1.8        ad }
    286