1 /* $NetBSD: netbsd32_sem.c,v 1.7 2008/04/29 06:53:02 martin Exp $ */
4 * Copyright (c) 2006 The NetBSD Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_sem.c,v 1.7 2008/04/29 06:53:02 martin Exp $");
33 #include "opt_posix.h"
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/dirent.h>
42 #include <sys/mount.h>
44 #include <sys/syscallargs.h>
46 #include <compat/netbsd32/netbsd32.h>
47 #include <compat/netbsd32/netbsd32_syscallargs.h>
48 #include <compat/netbsd32/netbsd32_conv.h>
51 netbsd32_ksem_copyout(const void *src
, void *dst
, size_t size
)
53 const intptr_t *idp
= src
;
54 netbsd32_intptr_t id32
, *outidp
= dst
;
56 KASSERT(size
== sizeof(intptr_t));
58 /* Returning a kernel pointer to userspace sucks badly :-( */
59 id32
= (netbsd32_intptr_t
)*idp
;
60 return copyout(&id32
, outidp
, sizeof(id32
));
64 netbsd32__ksem_init(struct lwp
*l
, const struct netbsd32__ksem_init_args
*uap
, register_t
*retval
)
67 syscallarg(unsigned int) value;
68 syscallarg(netbsd32_semidp_t) idp;
71 return do_ksem_init(l
, SCARG(uap
, value
),
72 SCARG_P32(uap
, idp
), netbsd32_ksem_copyout
);
76 netbsd32__ksem_open(struct lwp
*l
, const struct netbsd32__ksem_open_args
*uap
, register_t
*retval
)
79 syscallarg(const netbsd32_charp) name;
80 syscallarg(int) oflag;
81 syscallarg(mode_t) mode;
82 syscallarg(unsigned int) value;
83 syscallarg(netbsd32_semidp_t) idp;
86 return do_ksem_open(l
, SCARG_P32(uap
, name
),
87 SCARG(uap
, oflag
), SCARG(uap
, mode
), SCARG(uap
, value
),
88 SCARG_P32(uap
, idp
), netbsd32_ksem_copyout
);
92 netbsd32__ksem_unlink(struct lwp
*l
, const struct netbsd32__ksem_unlink_args
*uap
, register_t
*retval
)
95 syscallarg(const netbsd32_charp) name;
97 struct sys__ksem_unlink_args ua
;
99 NETBSD32TOP_UAP(name
, const char);
100 return sys__ksem_unlink(l
, &ua
, retval
);
104 netbsd32__ksem_close(struct lwp
*l
, const struct netbsd32__ksem_close_args
*uap
, register_t
*retval
)
107 syscallarg(netbsd32_intptr_t) id;
109 struct sys__ksem_close_args ua
;
111 NETBSD32TOX_UAP(id
, intptr_t);
112 return sys__ksem_close(l
, &ua
, retval
);
116 netbsd32__ksem_post(struct lwp
*l
, const struct netbsd32__ksem_post_args
*uap
, register_t
*retval
)
119 syscallarg(netbsd32_intptr_t) id;
121 struct sys__ksem_post_args ua
;
123 NETBSD32TOX_UAP(id
, intptr_t);
124 return sys__ksem_post(l
, &ua
, retval
);
128 netbsd32__ksem_wait(struct lwp
*l
, const struct netbsd32__ksem_wait_args
*uap
, register_t
*retval
)
131 syscallarg(netbsd32_intptr_t) id;
133 struct sys__ksem_wait_args ua
;
135 NETBSD32TOX_UAP(id
, intptr_t);
136 return sys__ksem_wait(l
, &ua
, retval
);
140 netbsd32__ksem_trywait(struct lwp
*l
, const struct netbsd32__ksem_trywait_args
*uap
, register_t
*retval
)
143 syscallarg(netbsd32_intptr_t) id;
145 struct sys__ksem_trywait_args ua
;
147 NETBSD32TOX_UAP(id
, intptr_t);
148 return sys__ksem_trywait(l
, &ua
, retval
);
152 netbsd32__ksem_destroy(struct lwp
*l
, const struct netbsd32__ksem_destroy_args
*uap
, register_t
*retval
)
155 syscallarg(netbsd32_intptr_t) id;
157 struct sys__ksem_destroy_args ua
;
159 NETBSD32TOX_UAP(id
, intptr_t);
160 return sys__ksem_destroy(l
, &ua
, retval
);
164 netbsd32__ksem_getvalue(struct lwp
*l
, const struct netbsd32__ksem_getvalue_args
*uap
, register_t
*retval
)
167 syscallarg(netbsd32_intptr_t) id;
168 syscallarg(netbsd32_intp) value;
170 struct sys__ksem_getvalue_args ua
;
172 NETBSD32TOX_UAP(id
, intptr_t);
173 NETBSD32TOP_UAP(value
, unsigned int);
174 return sys__ksem_getvalue(l
, &ua
, retval
);