Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_10_sysv.c revision 1.2
      1  1.2  pgoyette /*	$NetBSD: netbsd32_compat_10_sysv.c,v 1.2 2019/01/27 02:08:40 pgoyette Exp $	*/
      2  1.2  pgoyette 
      3  1.2  pgoyette /*
      4  1.2  pgoyette  * Copyright (c) 1994 Adam Glass and Charles M. Hannum.  All rights reserved.
      5  1.2  pgoyette  *
      6  1.2  pgoyette  * Redistribution and use in source and binary forms, with or without
      7  1.2  pgoyette  * modification, are permitted provided that the following conditions
      8  1.2  pgoyette  * are met:
      9  1.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     10  1.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     11  1.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     13  1.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     14  1.2  pgoyette  * 3. All advertising materials mentioning features or use of this software
     15  1.2  pgoyette  *    must display the following acknowledgement:
     16  1.2  pgoyette  *	This product includes software developed by Adam Glass and Charles M.
     17  1.2  pgoyette  *	Hannum.
     18  1.2  pgoyette  * 4. The names of the authors may not be used to endorse or promote products
     19  1.2  pgoyette  *    derived from this software without specific prior written permission.
     20  1.2  pgoyette  *
     21  1.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     22  1.2  pgoyette  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.2  pgoyette  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.2  pgoyette  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.2  pgoyette  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.2  pgoyette  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.2  pgoyette  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.2  pgoyette  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.2  pgoyette  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.2  pgoyette  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.2  pgoyette  */
     32  1.2  pgoyette 
     33  1.2  pgoyette #include <sys/cdefs.h>
     34  1.2  pgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_10_sysv.c,v 1.2 2019/01/27 02:08:40 pgoyette Exp $");
     35  1.2  pgoyette 
     36  1.2  pgoyette #ifdef _KERNEL_OPT
     37  1.2  pgoyette #include "opt_sysv.h"
     38  1.2  pgoyette #include "opt_compat_netbsd.h"
     39  1.2  pgoyette #endif
     40  1.2  pgoyette 
     41  1.2  pgoyette #include <sys/param.h>
     42  1.2  pgoyette #include <sys/systm.h>
     43  1.2  pgoyette #include <sys/module.h>
     44  1.2  pgoyette #include <sys/kernel.h>
     45  1.2  pgoyette #include <sys/proc.h>
     46  1.2  pgoyette #include <sys/sem.h>
     47  1.2  pgoyette 
     48  1.2  pgoyette #include <sys/mount.h>
     49  1.2  pgoyette #include <sys/syscallargs.h>
     50  1.2  pgoyette #include <sys/syscallvar.h>
     51  1.2  pgoyette 
     52  1.2  pgoyette #include <compat/netbsd32/netbsd32.h>
     53  1.2  pgoyette #include <compat/netbsd32/netbsd32_syscall.h>
     54  1.2  pgoyette #include <compat/netbsd32/netbsd32_syscallargs.h>
     55  1.2  pgoyette #include <compat/sys/shm.h>
     56  1.2  pgoyette 
     57  1.2  pgoyette #if defined(COMPAT_10)
     58  1.2  pgoyette 
     59  1.2  pgoyette #if defined(SYSVSEM)
     60  1.2  pgoyette int
     61  1.2  pgoyette compat_10_netbsd32_semsys(struct lwp *l, const struct compat_10_netbsd32_semsys_args *uap, register_t *retval)
     62  1.2  pgoyette {
     63  1.2  pgoyette 	/* {
     64  1.2  pgoyette 		syscallarg(int) which;
     65  1.2  pgoyette 		syscallarg(int) a2;
     66  1.2  pgoyette 		syscallarg(int) a3;
     67  1.2  pgoyette 		syscallarg(int) a4;
     68  1.2  pgoyette 		syscallarg(int) a5;
     69  1.2  pgoyette 	} */
     70  1.2  pgoyette 	struct compat_50_netbsd32___semctl14_args /* {
     71  1.2  pgoyette 		syscallarg(int) semid;
     72  1.2  pgoyette 		syscallarg(int) semnum;
     73  1.2  pgoyette 		syscallarg(int) cmd;
     74  1.2  pgoyette 		syscallarg(union semun *) arg;
     75  1.2  pgoyette 	} */ __semctl_args;
     76  1.2  pgoyette 	struct sys_semget_args /* {
     77  1.2  pgoyette 		syscallarg(key_t) key;
     78  1.2  pgoyette 		syscallarg(int) nsems;
     79  1.2  pgoyette 		syscallarg(int) semflg;
     80  1.2  pgoyette 	} */ semget_args;
     81  1.2  pgoyette 	struct sys_semop_args /* {
     82  1.2  pgoyette 		syscallarg(int) semid;
     83  1.2  pgoyette 		syscallarg(struct sembuf *) sops;
     84  1.2  pgoyette 		syscallarg(u_int) nsops;
     85  1.2  pgoyette 	} */ semop_args;
     86  1.2  pgoyette 	struct sys_semconfig_args /* {
     87  1.2  pgoyette 		syscallarg(int) flag;
     88  1.2  pgoyette 	} */ semconfig_args;
     89  1.2  pgoyette 	int a5;
     90  1.2  pgoyette 
     91  1.2  pgoyette 	switch (SCARG(uap, which)) {
     92  1.2  pgoyette 	case 0:						/* __semctl() */
     93  1.2  pgoyette 		SCARG(&__semctl_args, semid) = SCARG(uap, a2);
     94  1.2  pgoyette 		SCARG(&__semctl_args, semnum) = SCARG(uap, a3);
     95  1.2  pgoyette 		SCARG(&__semctl_args, cmd) = SCARG(uap, a4);
     96  1.2  pgoyette 		a5 = SCARG(uap, a5);
     97  1.2  pgoyette 		return do_netbsd32___semctl14(l, &__semctl_args, retval, &a5);
     98  1.2  pgoyette 
     99  1.2  pgoyette 	case 1:						/* semget() */
    100  1.2  pgoyette 		SCARG(&semget_args, key) = SCARG(uap, a2);
    101  1.2  pgoyette 		SCARG(&semget_args, nsems) = SCARG(uap, a3);
    102  1.2  pgoyette 		SCARG(&semget_args, semflg) = SCARG(uap, a4);
    103  1.2  pgoyette 		return (sys_semget(l, &semget_args, retval));
    104  1.2  pgoyette 
    105  1.2  pgoyette 	case 2:						/* semop() */
    106  1.2  pgoyette 		SCARG(&semop_args, semid) = SCARG(uap, a2);
    107  1.2  pgoyette 		SCARG(&semop_args, sops) = NETBSD32IPTR64(SCARG(uap, a3));
    108  1.2  pgoyette 		SCARG(&semop_args, nsops) = SCARG(uap, a4);
    109  1.2  pgoyette 		return (sys_semop(l, &semop_args, retval));
    110  1.2  pgoyette 
    111  1.2  pgoyette 	case 3:						/* semconfig() */
    112  1.2  pgoyette 		SCARG(&semconfig_args, flag) = SCARG(uap, a2);
    113  1.2  pgoyette 		return (sys_semconfig(l, &semconfig_args, retval));
    114  1.2  pgoyette 
    115  1.2  pgoyette 	default:
    116  1.2  pgoyette 		return (EINVAL);
    117  1.2  pgoyette 	}
    118  1.2  pgoyette }
    119  1.2  pgoyette #endif
    120  1.2  pgoyette 
    121  1.2  pgoyette #if defined(SYSVSHM)
    122  1.2  pgoyette int
    123  1.2  pgoyette compat_10_netbsd32_shmsys(struct lwp *l, const struct compat_10_netbsd32_shmsys_args *uap, register_t *retval)
    124  1.2  pgoyette {
    125  1.2  pgoyette 	/* {
    126  1.2  pgoyette 		syscallarg(int) which;
    127  1.2  pgoyette 		syscallarg(int) a2;
    128  1.2  pgoyette 		syscallarg(int) a3;
    129  1.2  pgoyette 		syscallarg(int) a4;
    130  1.2  pgoyette 	} */
    131  1.2  pgoyette 	struct sys_shmat_args /* {
    132  1.2  pgoyette 		syscallarg(int) shmid;
    133  1.2  pgoyette 		syscallarg(void *) shmaddr;
    134  1.2  pgoyette 		syscallarg(int) shmflg;
    135  1.2  pgoyette 	} */ shmat_args;
    136  1.2  pgoyette 	struct compat_14_sys_shmctl_args /* {
    137  1.2  pgoyette 		syscallarg(int) shmid;
    138  1.2  pgoyette 		syscallarg(int) cmd;
    139  1.2  pgoyette 		syscallarg(struct shmid_ds50 *) buf;
    140  1.2  pgoyette 	} */ shmctl_args;
    141  1.2  pgoyette 	struct sys_shmdt_args /* {
    142  1.2  pgoyette 		syscallarg(void *) shmaddr;
    143  1.2  pgoyette 	} */ shmdt_args;
    144  1.2  pgoyette 	struct sys_shmget_args /* {
    145  1.2  pgoyette 		syscallarg(key_t) key;
    146  1.2  pgoyette 		syscallarg(int) size;
    147  1.2  pgoyette 		syscallarg(int) shmflg;
    148  1.2  pgoyette 	} */ shmget_args;
    149  1.2  pgoyette 
    150  1.2  pgoyette 	switch (SCARG(uap, which)) {
    151  1.2  pgoyette 	case 0:						/* shmat() */
    152  1.2  pgoyette 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    153  1.2  pgoyette 		SCARG(&shmat_args, shmaddr) = NETBSD32IPTR64(SCARG(uap, a3));
    154  1.2  pgoyette 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    155  1.2  pgoyette 		return (sys_shmat(l, &shmat_args, retval));
    156  1.2  pgoyette 
    157  1.2  pgoyette 	case 1:						/* shmctl() */
    158  1.2  pgoyette 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    159  1.2  pgoyette 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    160  1.2  pgoyette 		SCARG(&shmctl_args, buf) = NETBSD32IPTR64(SCARG(uap, a4));
    161  1.2  pgoyette 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    162  1.2  pgoyette 
    163  1.2  pgoyette 	case 2:						/* shmdt() */
    164  1.2  pgoyette 		SCARG(&shmdt_args, shmaddr) = NETBSD32IPTR64(SCARG(uap, a2));
    165  1.2  pgoyette 		return (sys_shmdt(l, &shmdt_args, retval));
    166  1.2  pgoyette 
    167  1.2  pgoyette 	case 3:						/* shmget() */
    168  1.2  pgoyette 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    169  1.2  pgoyette 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    170  1.2  pgoyette 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
    171  1.2  pgoyette 		return (sys_shmget(l, &shmget_args, retval));
    172  1.2  pgoyette 
    173  1.2  pgoyette 	default:
    174  1.2  pgoyette 		return (EINVAL);
    175  1.2  pgoyette 	}
    176  1.2  pgoyette }
    177  1.2  pgoyette #endif
    178  1.2  pgoyette 
    179  1.2  pgoyette #if defined(SYSVMSG)
    180  1.2  pgoyette int
    181  1.2  pgoyette compat_10_netbsd32_msgsys(struct lwp *l, const struct compat_10_netbsd32_msgsys_args *uap, register_t *retval)
    182  1.2  pgoyette {
    183  1.2  pgoyette 	/* {
    184  1.2  pgoyette 		syscallarg(int) which;
    185  1.2  pgoyette 		syscallarg(int) a2;
    186  1.2  pgoyette 		syscallarg(int) a3;
    187  1.2  pgoyette 		syscallarg(int) a4;
    188  1.2  pgoyette 		syscallarg(int) a5;
    189  1.2  pgoyette 		syscallarg(int) a6;
    190  1.2  pgoyette 	} */
    191  1.2  pgoyette 	struct compat_14_sys_msgctl_args /* {
    192  1.2  pgoyette 		syscallarg(int) msqid;
    193  1.2  pgoyette 		syscallarg(int) cmd;
    194  1.2  pgoyette 		syscallarg(struct msqid_ds *) buf;
    195  1.2  pgoyette 	} */ msgctl_args;
    196  1.2  pgoyette 	struct sys_msgget_args /* {
    197  1.2  pgoyette 		syscallarg(key_t) key;
    198  1.2  pgoyette 		syscallarg(int) msgflg;
    199  1.2  pgoyette 	} */ msgget_args;
    200  1.2  pgoyette 	struct sys_msgsnd_args /* {
    201  1.2  pgoyette 		syscallarg(int) msqid;
    202  1.2  pgoyette 		syscallarg(void *) msgp;
    203  1.2  pgoyette 		syscallarg(size_t) msgsz;
    204  1.2  pgoyette 		syscallarg(int) msgflg;
    205  1.2  pgoyette 	} */ msgsnd_args;
    206  1.2  pgoyette 	struct sys_msgrcv_args /* {
    207  1.2  pgoyette 		syscallarg(int) msqid;
    208  1.2  pgoyette 		syscallarg(void *) msgp;
    209  1.2  pgoyette 		syscallarg(size_t) msgsz;
    210  1.2  pgoyette 		syscallarg(long) msgtyp;
    211  1.2  pgoyette 		syscallarg(int) msgflg;
    212  1.2  pgoyette 	} */ msgrcv_args;
    213  1.2  pgoyette 
    214  1.2  pgoyette 	switch (SCARG(uap, which)) {
    215  1.2  pgoyette 	case 0:					/* msgctl()*/
    216  1.2  pgoyette 		SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
    217  1.2  pgoyette 		SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
    218  1.2  pgoyette 		SCARG(&msgctl_args, buf) = NETBSD32IPTR64(SCARG(uap, a4));
    219  1.2  pgoyette 		return (compat_14_sys_msgctl(l, &msgctl_args, retval));
    220  1.2  pgoyette 
    221  1.2  pgoyette 	case 1:					/* msgget() */
    222  1.2  pgoyette 		SCARG(&msgget_args, key) = SCARG(uap, a2);
    223  1.2  pgoyette 		SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
    224  1.2  pgoyette 		return (sys_msgget(l, &msgget_args, retval));
    225  1.2  pgoyette 
    226  1.2  pgoyette 	case 2:					/* msgsnd() */
    227  1.2  pgoyette 		SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
    228  1.2  pgoyette 		SCARG(&msgsnd_args, msgp) = NETBSD32IPTR64(SCARG(uap, a3));
    229  1.2  pgoyette 		SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
    230  1.2  pgoyette 		SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
    231  1.2  pgoyette 		return (sys_msgsnd(l, &msgsnd_args, retval));
    232  1.2  pgoyette 
    233  1.2  pgoyette 	case 3:					/* msgrcv() */
    234  1.2  pgoyette 		SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
    235  1.2  pgoyette 		SCARG(&msgrcv_args, msgp) = NETBSD32IPTR64(SCARG(uap, a3));
    236  1.2  pgoyette 		SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
    237  1.2  pgoyette 		SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
    238  1.2  pgoyette 		SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
    239  1.2  pgoyette 		return (sys_msgrcv(l, &msgrcv_args, retval));
    240  1.2  pgoyette 
    241  1.2  pgoyette 	default:
    242  1.2  pgoyette 		return (EINVAL);
    243  1.2  pgoyette 	}
    244  1.2  pgoyette }
    245  1.2  pgoyette #endif
    246  1.2  pgoyette 
    247  1.2  pgoyette #define _PKG_ENTRY(name)        \
    248  1.2  pgoyette 	{ NETBSD32_SYS_ ## name, 0, (sy_call_t *)name }
    249  1.2  pgoyette 
    250  1.2  pgoyette #define _PKG_ENTRY2(code, name) \
    251  1.2  pgoyette 	{ NETBSD32_SYS_ ## code, 0, (sy_call_t *)name }
    252  1.2  pgoyette 
    253  1.2  pgoyette static const struct syscall_package compat_sysvipc_10_syscalls[] = {
    254  1.2  pgoyette #if defined(SYSVSEM)
    255  1.2  pgoyette 	_PKG_ENTRY2(compat_10_osemsys, compat_10_netbsd32_semsys),
    256  1.2  pgoyette #endif
    257  1.2  pgoyette #if defined(SYSVSHM)
    258  1.2  pgoyette 	_PKG_ENTRY2(compat_10_oshmsys, compat_10_netbsd32_shmsys),
    259  1.2  pgoyette #endif
    260  1.2  pgoyette #if defined(SYSVMSG)
    261  1.2  pgoyette 	_PKG_ENTRY2(compat_10_omsgsys, compat_10_netbsd32_msgsys),
    262  1.2  pgoyette #endif
    263  1.2  pgoyette 	{ 0, 0, NULL }
    264  1.2  pgoyette };
    265  1.2  pgoyette 
    266  1.2  pgoyette #define	REQ1    "sysv_ipc,compat_sysv_10,"
    267  1.2  pgoyette #define	REQ2    "compat_netbsd32,compat_netbsd32_sysvipc,"
    268  1.2  pgoyette #define	REQ3	"compat_netbsd32_sysvipc_14,compat_netbsd32_sysvipc_50"
    269  1.2  pgoyette 
    270  1.2  pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_sysvipc_10, REQ1 REQ2 REQ3 );
    271  1.2  pgoyette 
    272  1.2  pgoyette static int
    273  1.2  pgoyette compat_netbsd32_sysvipc_10_modcmd(modcmd_t cmd, void *arg)
    274  1.2  pgoyette {
    275  1.2  pgoyette 
    276  1.2  pgoyette 	switch (cmd) {
    277  1.2  pgoyette 	case MODULE_CMD_INIT:
    278  1.2  pgoyette 		return syscall_establish(&emul_netbsd32,
    279  1.2  pgoyette 		    compat_sysvipc_10_syscalls);
    280  1.2  pgoyette 
    281  1.2  pgoyette 	case MODULE_CMD_FINI:
    282  1.2  pgoyette 		return syscall_disestablish(&emul_netbsd32,
    283  1.2  pgoyette 		    compat_sysvipc_10_syscalls);
    284  1.2  pgoyette 
    285  1.2  pgoyette 	default:
    286  1.2  pgoyette 		return ENOTTY;
    287  1.2  pgoyette 	}
    288  1.2  pgoyette }
    289  1.2  pgoyette 
    290  1.2  pgoyette #endif /* COMPAT_10 */
    291