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