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