Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_14_sysv.c revision 1.3.14.1
      1  1.3.14.1   thorpej /*	$NetBSD: netbsd32_compat_14_sysv.c,v 1.3.14.1 2021/04/03 22:28:42 thorpej Exp $	*/
      2       1.2  pgoyette 
      3       1.2  pgoyette /*
      4       1.2  pgoyette  * Copyright (c) 1999 Eduardo E. Horvath
      5       1.2  pgoyette  * All rights reserved.
      6       1.2  pgoyette  *
      7       1.2  pgoyette  * Redistribution and use in source and binary forms, with or without
      8       1.2  pgoyette  * modification, are permitted provided that the following conditions
      9       1.2  pgoyette  * are met:
     10       1.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     11       1.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     12       1.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     14       1.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     15       1.2  pgoyette  * 3. The name of the author may not be used to endorse or promote products
     16       1.2  pgoyette  *    derived from this software without specific prior written permission.
     17       1.2  pgoyette  *
     18       1.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19       1.2  pgoyette  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20       1.2  pgoyette  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21       1.2  pgoyette  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22       1.2  pgoyette  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23       1.2  pgoyette  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24       1.2  pgoyette  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25       1.2  pgoyette  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26       1.2  pgoyette  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27       1.2  pgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28       1.2  pgoyette  * SUCH DAMAGE.
     29       1.2  pgoyette  */
     30       1.2  pgoyette 
     31       1.2  pgoyette #include <sys/cdefs.h>
     32  1.3.14.1   thorpej __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_14_sysv.c,v 1.3.14.1 2021/04/03 22:28:42 thorpej Exp $");
     33       1.2  pgoyette 
     34       1.2  pgoyette #ifdef _KERNEL_OPT
     35       1.2  pgoyette #include "opt_sysv.h"
     36       1.2  pgoyette #include "opt_compat_netbsd.h"
     37       1.2  pgoyette #endif
     38       1.2  pgoyette 
     39       1.2  pgoyette #include <sys/param.h>
     40       1.2  pgoyette #include <sys/ipc.h>
     41       1.2  pgoyette #include <sys/systm.h>
     42       1.2  pgoyette #include <sys/module.h>
     43       1.2  pgoyette #include <sys/signal.h>
     44       1.2  pgoyette #include <sys/proc.h>
     45       1.2  pgoyette #include <sys/mount.h>
     46       1.2  pgoyette #include <sys/msg.h>
     47       1.2  pgoyette #include <sys/sem.h>
     48       1.2  pgoyette #include <sys/shm.h>
     49       1.2  pgoyette 
     50       1.2  pgoyette #include <sys/syscallargs.h>
     51       1.2  pgoyette #include <sys/syscallvar.h>
     52       1.2  pgoyette 
     53       1.2  pgoyette #include <compat/netbsd32/netbsd32.h>
     54       1.2  pgoyette #include <compat/netbsd32/netbsd32_syscall.h>
     55       1.2  pgoyette #include <compat/netbsd32/netbsd32_syscallargs.h>
     56       1.2  pgoyette #include <compat/sys/siginfo.h>
     57       1.2  pgoyette #include <compat/sys/shm.h>
     58       1.2  pgoyette 
     59       1.2  pgoyette #if defined(COMPAT_14)
     60       1.2  pgoyette 
     61       1.2  pgoyette #if defined(SYSVMSG)
     62       1.2  pgoyette static inline void
     63       1.2  pgoyette netbsd32_ipc_perm14_to_native(struct netbsd32_ipc_perm14 *operm, struct ipc_perm *perm)
     64       1.2  pgoyette {
     65       1.2  pgoyette 
     66       1.2  pgoyette #define	CVT(x)	perm->x = operm->x
     67       1.2  pgoyette 	CVT(uid);
     68       1.2  pgoyette 	CVT(gid);
     69       1.2  pgoyette 	CVT(cuid);
     70       1.2  pgoyette 	CVT(cgid);
     71       1.2  pgoyette 	CVT(mode);
     72       1.2  pgoyette #undef CVT
     73       1.2  pgoyette }
     74       1.2  pgoyette 
     75       1.2  pgoyette static inline void
     76       1.2  pgoyette native_to_netbsd32_ipc_perm14(struct ipc_perm *perm, struct netbsd32_ipc_perm14 *operm)
     77       1.2  pgoyette {
     78       1.2  pgoyette 
     79       1.3       mrg 	memset(operm, 0, sizeof *operm);
     80       1.2  pgoyette #define	CVT(x)	operm->x = perm->x
     81       1.2  pgoyette 	CVT(uid);
     82       1.2  pgoyette 	CVT(gid);
     83       1.2  pgoyette 	CVT(cuid);
     84       1.2  pgoyette 	CVT(cgid);
     85       1.2  pgoyette 	CVT(mode);
     86       1.2  pgoyette #undef CVT
     87       1.2  pgoyette 
     88       1.2  pgoyette 	/*
     89       1.2  pgoyette 	 * Not part of the API, but some programs might look at it.
     90       1.2  pgoyette 	 */
     91       1.2  pgoyette 	operm->seq = perm->_seq;
     92       1.2  pgoyette 	operm->key = (key_t)perm->_key;
     93       1.2  pgoyette }
     94       1.2  pgoyette 
     95       1.2  pgoyette static inline void
     96       1.2  pgoyette netbsd32_msqid_ds14_to_native(struct netbsd32_msqid_ds14 *omsqbuf, struct msqid_ds *msqbuf)
     97       1.2  pgoyette {
     98       1.2  pgoyette 
     99       1.2  pgoyette 	netbsd32_ipc_perm14_to_native(&omsqbuf->msg_perm, &msqbuf->msg_perm);
    100       1.2  pgoyette 
    101       1.2  pgoyette #define	CVT(x)	msqbuf->x = omsqbuf->x
    102       1.2  pgoyette 	CVT(msg_qnum);
    103       1.2  pgoyette 	CVT(msg_qbytes);
    104       1.2  pgoyette 	CVT(msg_lspid);
    105       1.2  pgoyette 	CVT(msg_lrpid);
    106       1.2  pgoyette 	CVT(msg_stime);
    107       1.2  pgoyette 	CVT(msg_rtime);
    108       1.2  pgoyette 	CVT(msg_ctime);
    109       1.2  pgoyette #undef CVT
    110       1.2  pgoyette }
    111       1.2  pgoyette 
    112       1.2  pgoyette static inline void
    113       1.2  pgoyette native_to_netbsd32_msqid_ds14(struct msqid_ds *msqbuf, struct netbsd32_msqid_ds14 *omsqbuf)
    114       1.2  pgoyette {
    115       1.2  pgoyette 
    116       1.3       mrg 	memset(omsqbuf, 0, sizeof *omsqbuf);
    117       1.2  pgoyette 	native_to_netbsd32_ipc_perm14(&msqbuf->msg_perm, &omsqbuf->msg_perm);
    118       1.2  pgoyette 
    119       1.2  pgoyette #define	CVT(x)	omsqbuf->x = msqbuf->x
    120       1.2  pgoyette 	CVT(msg_qnum);
    121       1.2  pgoyette 	CVT(msg_qbytes);
    122       1.2  pgoyette 	CVT(msg_lspid);
    123       1.2  pgoyette 	CVT(msg_lrpid);
    124       1.2  pgoyette 	CVT(msg_stime);
    125       1.2  pgoyette 	CVT(msg_rtime);
    126       1.2  pgoyette 	CVT(msg_ctime);
    127       1.2  pgoyette #undef CVT
    128       1.2  pgoyette 
    129       1.2  pgoyette 	/*
    130       1.2  pgoyette 	 * Not part of the API, but some programs might look at it.
    131       1.2  pgoyette 	 */
    132       1.2  pgoyette 	omsqbuf->msg_cbytes = msqbuf->_msg_cbytes;
    133       1.2  pgoyette }
    134       1.2  pgoyette #endif
    135       1.2  pgoyette 
    136       1.2  pgoyette #if defined(SYSVSEM)
    137       1.2  pgoyette static inline void
    138       1.2  pgoyette netbsd32_semid_ds14_to_native(struct netbsd32_semid_ds14 *osembuf, struct semid_ds *sembuf)
    139       1.2  pgoyette {
    140       1.2  pgoyette 
    141       1.2  pgoyette 	netbsd32_ipc_perm14_to_native(&osembuf->sem_perm, &sembuf->sem_perm);
    142       1.2  pgoyette 
    143       1.2  pgoyette #define	CVT(x)	sembuf->x = osembuf->x
    144       1.2  pgoyette 	CVT(sem_nsems);
    145       1.2  pgoyette 	CVT(sem_otime);
    146       1.2  pgoyette 	CVT(sem_ctime);
    147       1.2  pgoyette #undef CVT
    148       1.2  pgoyette }
    149       1.2  pgoyette 
    150       1.2  pgoyette static inline void
    151       1.2  pgoyette native_to_netbsd32_semid_ds14(struct semid_ds *sembuf, struct netbsd32_semid_ds14 *osembuf)
    152       1.2  pgoyette {
    153       1.2  pgoyette 
    154       1.3       mrg 	memset(osembuf, 0, sizeof *osembuf);
    155       1.2  pgoyette 	native_to_netbsd32_ipc_perm14(&sembuf->sem_perm, &osembuf->sem_perm);
    156       1.2  pgoyette 
    157       1.2  pgoyette #define	CVT(x)	osembuf->x = sembuf->x
    158       1.2  pgoyette 	CVT(sem_nsems);
    159       1.2  pgoyette 	CVT(sem_otime);
    160       1.2  pgoyette 	CVT(sem_ctime);
    161       1.2  pgoyette #undef CVT
    162       1.2  pgoyette }
    163       1.2  pgoyette 
    164       1.2  pgoyette static inline void
    165       1.2  pgoyette netbsd32_shmid_ds14_to_native(struct netbsd32_shmid_ds14 *oshmbuf, struct shmid_ds *shmbuf)
    166       1.2  pgoyette {
    167       1.2  pgoyette 
    168       1.2  pgoyette 	netbsd32_ipc_perm14_to_native(&oshmbuf->shm_perm, &shmbuf->shm_perm);
    169       1.2  pgoyette 
    170       1.2  pgoyette #define	CVT(x)	shmbuf->x = oshmbuf->x
    171       1.2  pgoyette 	CVT(shm_segsz);
    172       1.2  pgoyette 	CVT(shm_lpid);
    173       1.2  pgoyette 	CVT(shm_cpid);
    174       1.2  pgoyette 	CVT(shm_nattch);
    175       1.2  pgoyette 	CVT(shm_atime);
    176       1.2  pgoyette 	CVT(shm_dtime);
    177       1.2  pgoyette 	CVT(shm_ctime);
    178       1.2  pgoyette #undef CVT
    179       1.2  pgoyette }
    180       1.2  pgoyette 
    181       1.2  pgoyette static inline void
    182       1.2  pgoyette native_to_netbsd32_shmid_ds14(struct shmid_ds *shmbuf, struct netbsd32_shmid_ds14 *oshmbuf)
    183       1.2  pgoyette {
    184       1.2  pgoyette 
    185       1.3       mrg 	memset(oshmbuf, 0, sizeof *oshmbuf);
    186       1.2  pgoyette 	native_to_netbsd32_ipc_perm14(&shmbuf->shm_perm, &oshmbuf->shm_perm);
    187       1.2  pgoyette 
    188       1.2  pgoyette #define	CVT(x)	oshmbuf->x = shmbuf->x
    189       1.2  pgoyette 	CVT(shm_segsz);
    190       1.2  pgoyette 	CVT(shm_lpid);
    191       1.2  pgoyette 	CVT(shm_cpid);
    192       1.2  pgoyette 	CVT(shm_nattch);
    193       1.2  pgoyette 	CVT(shm_atime);
    194       1.2  pgoyette 	CVT(shm_dtime);
    195       1.2  pgoyette 	CVT(shm_ctime);
    196       1.2  pgoyette #undef CVT
    197       1.2  pgoyette }
    198       1.2  pgoyette 
    199       1.2  pgoyette /*
    200       1.2  pgoyette  * the compat_14 system calls
    201       1.2  pgoyette  */
    202       1.2  pgoyette int
    203       1.2  pgoyette compat_14_netbsd32_msgctl(struct lwp *l, const struct compat_14_netbsd32_msgctl_args *uap, register_t *retval)
    204       1.2  pgoyette {
    205       1.2  pgoyette 	/* {
    206       1.2  pgoyette 		syscallarg(int) msqid;
    207       1.2  pgoyette 		syscallarg(int) cmd;
    208       1.2  pgoyette 		syscallarg(struct msqid_ds14 *) buf;
    209       1.2  pgoyette 	} */
    210       1.2  pgoyette 	struct msqid_ds msqbuf;
    211       1.2  pgoyette 	struct netbsd32_msqid_ds14 omsqbuf;
    212       1.2  pgoyette 	int cmd, error;
    213       1.2  pgoyette 
    214       1.2  pgoyette 	cmd = SCARG(uap, cmd);
    215       1.2  pgoyette 
    216       1.2  pgoyette 	if (cmd == IPC_SET) {
    217       1.2  pgoyette 		error = copyin(SCARG_P32(uap, buf),
    218       1.2  pgoyette 		    &omsqbuf, sizeof(omsqbuf));
    219       1.2  pgoyette 		if (error)
    220  1.3.14.1   thorpej 			return error;
    221       1.2  pgoyette 		netbsd32_msqid_ds14_to_native(&omsqbuf, &msqbuf);
    222       1.2  pgoyette 	}
    223       1.2  pgoyette 
    224       1.2  pgoyette 	error = msgctl1(l, SCARG(uap, msqid), cmd,
    225       1.2  pgoyette 	    (cmd == IPC_SET || cmd == IPC_STAT) ? &msqbuf : NULL);
    226       1.2  pgoyette 
    227       1.2  pgoyette 	if (error == 0 && cmd == IPC_STAT) {
    228       1.2  pgoyette 		native_to_netbsd32_msqid_ds14(&msqbuf, &omsqbuf);
    229       1.2  pgoyette 		error = copyout(&omsqbuf,
    230       1.2  pgoyette 		    SCARG_P32(uap, buf), sizeof(omsqbuf));
    231       1.2  pgoyette 	}
    232       1.2  pgoyette 
    233  1.3.14.1   thorpej 	return error;
    234       1.2  pgoyette }
    235       1.2  pgoyette #endif
    236       1.2  pgoyette 
    237       1.2  pgoyette #if defined(SYSVSEM)
    238       1.2  pgoyette int
    239       1.2  pgoyette compat_14_netbsd32___semctl(struct lwp *l, const struct compat_14_netbsd32___semctl_args *uap, register_t *retval)
    240       1.2  pgoyette {
    241       1.2  pgoyette 	/* {
    242       1.2  pgoyette 		syscallarg(int) semid;
    243       1.2  pgoyette 		syscallarg(int) semnum;
    244       1.2  pgoyette 		syscallarg(int) cmd;
    245       1.2  pgoyette 		syscallarg(union __semun *) arg;
    246       1.2  pgoyette 	} */
    247       1.2  pgoyette 	union __semun arg;
    248       1.2  pgoyette 	struct semid_ds sembuf;
    249       1.2  pgoyette 	struct netbsd32_semid_ds14 osembuf;
    250       1.2  pgoyette 	int cmd, error;
    251       1.2  pgoyette 	void *pass_arg = NULL;
    252       1.2  pgoyette 
    253       1.2  pgoyette 	cmd = SCARG(uap, cmd);
    254       1.2  pgoyette 
    255       1.2  pgoyette 	switch (cmd) {
    256       1.2  pgoyette 	case IPC_SET:
    257       1.2  pgoyette 	case IPC_STAT:
    258       1.2  pgoyette 		pass_arg = &sembuf;
    259       1.2  pgoyette 		break;
    260       1.2  pgoyette 
    261       1.2  pgoyette 	case GETALL:
    262       1.2  pgoyette 	case SETVAL:
    263       1.2  pgoyette 	case SETALL:
    264       1.2  pgoyette 		pass_arg = &arg;
    265       1.2  pgoyette 		break;
    266       1.2  pgoyette 	}
    267       1.2  pgoyette 
    268       1.2  pgoyette 	if (pass_arg != NULL) {
    269       1.2  pgoyette 		error = copyin(NETBSD32IPTR64(SCARG(uap, arg)), &arg,
    270       1.2  pgoyette 		    sizeof(arg));
    271       1.2  pgoyette 		if (error)
    272  1.3.14.1   thorpej 			return error;
    273       1.2  pgoyette 		if (cmd == IPC_SET) {
    274       1.2  pgoyette 			error = copyin(arg.buf, &osembuf, sizeof(osembuf));
    275       1.2  pgoyette 			if (error)
    276  1.3.14.1   thorpej 				return error;
    277       1.2  pgoyette 			netbsd32_semid_ds14_to_native(&osembuf, &sembuf);
    278       1.2  pgoyette 		}
    279       1.2  pgoyette 	}
    280       1.2  pgoyette 
    281       1.2  pgoyette 	error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
    282       1.2  pgoyette 	    pass_arg, retval);
    283       1.2  pgoyette 
    284       1.2  pgoyette 	if (error == 0 && cmd == IPC_STAT) {
    285       1.2  pgoyette 		native_to_netbsd32_semid_ds14(&sembuf, &osembuf);
    286       1.2  pgoyette 		error = copyout(&osembuf, arg.buf, sizeof(osembuf));
    287       1.2  pgoyette 	}
    288       1.2  pgoyette 
    289  1.3.14.1   thorpej 	return error;
    290       1.2  pgoyette }
    291       1.2  pgoyette #endif
    292       1.2  pgoyette 
    293       1.2  pgoyette #if defined(SYSVSHM)
    294       1.2  pgoyette int
    295       1.2  pgoyette compat_14_netbsd32_shmctl(struct lwp *l, const struct compat_14_netbsd32_shmctl_args *uap, register_t *retval)
    296       1.2  pgoyette {
    297       1.2  pgoyette 	/* {
    298       1.2  pgoyette 		syscallarg(int) shmid;
    299       1.2  pgoyette 		syscallarg(int) cmd;
    300       1.2  pgoyette 		syscallarg(struct netbsd32_shmid_ds14 *) buf;
    301       1.2  pgoyette 	} */
    302       1.2  pgoyette 	struct shmid_ds shmbuf;
    303       1.2  pgoyette 	struct netbsd32_shmid_ds14 oshmbuf;
    304       1.2  pgoyette 	int cmd, error;
    305       1.2  pgoyette 
    306       1.2  pgoyette 	cmd = SCARG(uap, cmd);
    307       1.2  pgoyette 
    308       1.2  pgoyette 	if (cmd == IPC_SET) {
    309       1.2  pgoyette 		error = copyin(SCARG_P32(uap, buf), &oshmbuf, sizeof(oshmbuf));
    310       1.2  pgoyette 		if (error)
    311  1.3.14.1   thorpej 			return error;
    312       1.2  pgoyette 		netbsd32_shmid_ds14_to_native(&oshmbuf, &shmbuf);
    313       1.2  pgoyette 	}
    314       1.2  pgoyette 
    315       1.2  pgoyette 	error = shmctl1(l, SCARG(uap, shmid), cmd,
    316       1.2  pgoyette 	    (cmd == IPC_SET || cmd == IPC_STAT) ? &shmbuf : NULL);
    317       1.2  pgoyette 
    318       1.2  pgoyette 	if (error == 0 && cmd == IPC_STAT) {
    319       1.2  pgoyette 		native_to_netbsd32_shmid_ds14(&shmbuf, &oshmbuf);
    320       1.2  pgoyette 		error = copyout(&oshmbuf, SCARG_P32(uap, buf), sizeof(oshmbuf));
    321       1.2  pgoyette 	}
    322       1.2  pgoyette 
    323  1.3.14.1   thorpej 	return error;
    324       1.2  pgoyette }
    325       1.2  pgoyette #endif
    326       1.2  pgoyette 
    327       1.2  pgoyette #define REQ1    "sysv_ipc,compat_sysv_14,"
    328       1.2  pgoyette #define REQ2    "compat_netbsd32,compat_netbsd32_sysvipc,"
    329       1.2  pgoyette #define REQ3    "compat_netbsd32_sysvipc_50"
    330       1.2  pgoyette 
    331       1.2  pgoyette #define _PKG_ENTRY(name)        \
    332       1.2  pgoyette 	{ NETBSD32_SYS_ ## name, 0, (sy_call_t *)name }
    333       1.2  pgoyette 
    334       1.2  pgoyette static const struct syscall_package compat_sysvipc_14_syscalls[] = {
    335       1.2  pgoyette #if defined(SYSVSEM)
    336       1.2  pgoyette 	_PKG_ENTRY(compat_14_netbsd32___semctl),
    337       1.2  pgoyette #endif
    338       1.2  pgoyette #if defined(SYSVSHM)
    339       1.2  pgoyette 	_PKG_ENTRY(compat_14_netbsd32_shmctl),
    340       1.2  pgoyette #endif
    341       1.2  pgoyette #if defined(SYSVMSG)
    342       1.2  pgoyette 	_PKG_ENTRY(compat_14_netbsd32_msgctl),
    343       1.2  pgoyette #endif
    344       1.2  pgoyette 	{ 0, 0, NULL }
    345       1.2  pgoyette };
    346       1.2  pgoyette 
    347       1.2  pgoyette #define REQ1    "sysv_ipc,compat_sysv_14,"
    348       1.2  pgoyette #define REQ2    "compat_netbsd32,compat_netbsd32_sysvipc,"
    349       1.2  pgoyette #define REQ3    "compat_netbsd32_sysvipc_50"
    350       1.2  pgoyette 
    351       1.2  pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_sysvipc_14, REQ1 REQ2 REQ3 );
    352       1.2  pgoyette 
    353       1.2  pgoyette static int
    354       1.2  pgoyette compat_netbsd32_sysvipc_14_modcmd(modcmd_t cmd, void *arg)
    355       1.2  pgoyette {
    356       1.2  pgoyette 
    357       1.2  pgoyette 	switch (cmd) {
    358       1.2  pgoyette 	case MODULE_CMD_INIT:
    359       1.2  pgoyette 		return syscall_establish(&emul_netbsd32,
    360       1.2  pgoyette 		    compat_sysvipc_14_syscalls);
    361       1.2  pgoyette 
    362       1.2  pgoyette 	case MODULE_CMD_FINI:
    363       1.2  pgoyette 		return syscall_disestablish(&emul_netbsd32,
    364       1.2  pgoyette 		    compat_sysvipc_14_syscalls);
    365       1.2  pgoyette 
    366       1.2  pgoyette 	default:
    367       1.2  pgoyette 		return ENOTTY;
    368       1.2  pgoyette 	}
    369       1.2  pgoyette }
    370       1.2  pgoyette 
    371       1.2  pgoyette #endif /* COMPAT_14 */
    372