1*9cdb398eSmaxv /* $NetBSD: linux32_socketcall.c,v 1.9 2014/06/21 10:23:07 maxv Exp $ */
2ee0c5b44Smanu
3ee0c5b44Smanu /*-
4ee0c5b44Smanu * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5ee0c5b44Smanu *
6ee0c5b44Smanu * Redistribution and use in source and binary forms, with or without
7ee0c5b44Smanu * modification, are permitted provided that the following conditions
8ee0c5b44Smanu * are met:
9ee0c5b44Smanu * 1. Redistributions of source code must retain the above copyright
10ee0c5b44Smanu * notice, this list of conditions and the following disclaimer.
11ee0c5b44Smanu * 2. Redistributions in binary form must reproduce the above copyright
12ee0c5b44Smanu * notice, this list of conditions and the following disclaimer in the
13ee0c5b44Smanu * documentation and/or other materials provided with the distribution.
14ee0c5b44Smanu * 3. All advertising materials mentioning features or use of this software
15ee0c5b44Smanu * must display the following acknowledgement:
16ee0c5b44Smanu * This product includes software developed by Emmanuel Dreyfus
17ee0c5b44Smanu * 4. The name of the author may not be used to endorse or promote
18ee0c5b44Smanu * products derived from this software without specific prior written
19ee0c5b44Smanu * permission.
20ee0c5b44Smanu *
21ee0c5b44Smanu * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22ee0c5b44Smanu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23ee0c5b44Smanu * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24ee0c5b44Smanu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25ee0c5b44Smanu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26ee0c5b44Smanu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27ee0c5b44Smanu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28ee0c5b44Smanu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29ee0c5b44Smanu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30ee0c5b44Smanu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31ee0c5b44Smanu * POSSIBILITY OF SUCH DAMAGE.
32ee0c5b44Smanu */
33ee0c5b44Smanu #include <sys/cdefs.h>
34*9cdb398eSmaxv __KERNEL_RCSID(0, "$NetBSD: linux32_socketcall.c,v 1.9 2014/06/21 10:23:07 maxv Exp $");
35ee0c5b44Smanu
36ee0c5b44Smanu #include <sys/types.h>
37ee0c5b44Smanu #include <sys/param.h>
38ee0c5b44Smanu #include <sys/time.h>
39d95fed73Sdsl #include <sys/proc.h>
40ee0c5b44Smanu #include <sys/ucred.h>
41d95fed73Sdsl #include <sys/ktrace.h>
42ee0c5b44Smanu
43ee0c5b44Smanu #include <compat/netbsd32/netbsd32.h>
44ee0c5b44Smanu #include <compat/netbsd32/netbsd32_syscallargs.h>
45ee0c5b44Smanu
46ee0c5b44Smanu #include <compat/linux/common/linux_types.h>
47ee0c5b44Smanu #include <compat/linux/common/linux_signal.h>
4892ce8c6aSad #include <compat/linux/common/linux_ipc.h>
4992ce8c6aSad #include <compat/linux/common/linux_sem.h>
50ee0c5b44Smanu #include <compat/linux/linux_syscallargs.h>
51ee0c5b44Smanu
52ee0c5b44Smanu #include <compat/linux32/common/linux32_types.h>
53ee0c5b44Smanu #include <compat/linux32/common/linux32_signal.h>
54ee0c5b44Smanu #include <compat/linux32/common/linux32_machdep.h>
55ee0c5b44Smanu #include <compat/linux32/common/linux32_sysctl.h>
56ee0c5b44Smanu #include <compat/linux32/common/linux32_socketcall.h>
57ee0c5b44Smanu #include <compat/linux32/linux32_syscallargs.h>
58ee0c5b44Smanu
59d1109b62Schristos #define sc(emul, fn) { "linux32/" #fn, sizeof (struct emul##_##fn##_args), \
607e2790cfSdsl (int (*)(struct lwp *, const void *, register_t *))emul##_##fn }
61ee0c5b44Smanu
62ee0c5b44Smanu static const struct {
63ee0c5b44Smanu const char *name;
64ee0c5b44Smanu int argsize;
657e2790cfSdsl int (*syscall)(struct lwp *, const void *, register_t *);
66ee0c5b44Smanu } linux32_socketcall[LINUX32_MAX_SOCKETCALL+1] = {
67ee0c5b44Smanu {"invalid", -1, NULL},
687e2790cfSdsl sc(linux32_sys, socket),
697e2790cfSdsl sc(linux32_sys, bind),
707e2790cfSdsl sc(linux32_sys, connect),
717e2790cfSdsl sc(netbsd32, listen),
727e2790cfSdsl sc(linux32_sys, accept),
737e2790cfSdsl sc(linux32_sys, getsockname),
747e2790cfSdsl sc(linux32_sys, getpeername),
757e2790cfSdsl sc(linux32_sys, socketpair),
767e2790cfSdsl sc(linux32_sys, send),
777e2790cfSdsl sc(linux32_sys, recv),
787e2790cfSdsl sc(linux32_sys, sendto),
797e2790cfSdsl sc(linux32_sys, recvfrom),
807e2790cfSdsl sc(netbsd32, shutdown),
817e2790cfSdsl sc(linux32_sys, setsockopt),
827e2790cfSdsl sc(linux32_sys, getsockopt),
837e2790cfSdsl sc(linux32_sys, sendmsg),
847e2790cfSdsl sc(linux32_sys, recvmsg),
85ee0c5b44Smanu };
867e2790cfSdsl #undef sc
877e2790cfSdsl
88ee0c5b44Smanu
89ee0c5b44Smanu int
linux32_sys_socketcall(struct lwp * l,const struct linux32_sys_socketcall_args * uap,register_t * retval)907e2790cfSdsl linux32_sys_socketcall(struct lwp *l, const struct linux32_sys_socketcall_args *uap, register_t *retval)
91ee0c5b44Smanu {
927e2790cfSdsl /* {
93ee0c5b44Smanu syscallarg(int) what;
94ee0c5b44Smanu syscallarg(netbsd32_voidp) args;
957e2790cfSdsl } */
96ee0c5b44Smanu union linux32_socketcall_args ua;
97ee0c5b44Smanu int error;
98ee0c5b44Smanu
99*9cdb398eSmaxv if (SCARG(uap, what) <= 0 || SCARG(uap, what) > LINUX32_MAX_SOCKETCALL)
100ee0c5b44Smanu return ENOSYS;
101ee0c5b44Smanu
102d364d308Sdsl if ((error = copyin(SCARG_P32(uap, args), &ua,
103ee0c5b44Smanu linux32_socketcall[SCARG(uap, what)].argsize)) != 0)
104ee0c5b44Smanu return error;
105ee0c5b44Smanu
106d95fed73Sdsl /* Trace the socket-call arguments as 'GIO' on fd -1 */
10763c45061Sad ktrkuser(linux32_socketcall[SCARG(uap, what)].name, &ua,
10863c45061Sad linux32_socketcall[SCARG(uap, what)].argsize);
109d95fed73Sdsl
110ee0c5b44Smanu return linux32_socketcall[SCARG(uap, what)].syscall(l, &ua, retval);
111ee0c5b44Smanu }
112