Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_14_sysv.c revision 1.2
      1  1.2  pgoyette /*	$NetBSD: netbsd32_compat_14_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) 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.2  pgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_14_sysv.c,v 1.2 2019/01/27 02:08:40 pgoyette 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.2  pgoyette #define	CVT(x)	operm->x = perm->x
     80  1.2  pgoyette 	CVT(uid);
     81  1.2  pgoyette 	CVT(gid);
     82  1.2  pgoyette 	CVT(cuid);
     83  1.2  pgoyette 	CVT(cgid);
     84  1.2  pgoyette 	CVT(mode);
     85  1.2  pgoyette #undef CVT
     86  1.2  pgoyette 
     87  1.2  pgoyette 	/*
     88  1.2  pgoyette 	 * Not part of the API, but some programs might look at it.
     89  1.2  pgoyette 	 */
     90  1.2  pgoyette 	operm->seq = perm->_seq;
     91  1.2  pgoyette 	operm->key = (key_t)perm->_key;
     92  1.2  pgoyette }
     93  1.2  pgoyette 
     94  1.2  pgoyette static inline void
     95  1.2  pgoyette netbsd32_msqid_ds14_to_native(struct netbsd32_msqid_ds14 *omsqbuf, struct msqid_ds *msqbuf)
     96  1.2  pgoyette {
     97  1.2  pgoyette 
     98  1.2  pgoyette 	netbsd32_ipc_perm14_to_native(&omsqbuf->msg_perm, &msqbuf->msg_perm);
     99  1.2  pgoyette 
    100  1.2  pgoyette #define	CVT(x)	msqbuf->x = omsqbuf->x
    101  1.2  pgoyette 	CVT(msg_qnum);
    102  1.2  pgoyette 	CVT(msg_qbytes);
    103  1.2  pgoyette 	CVT(msg_lspid);
    104  1.2  pgoyette 	CVT(msg_lrpid);
    105  1.2  pgoyette 	CVT(msg_stime);
    106  1.2  pgoyette 	CVT(msg_rtime);
    107  1.2  pgoyette 	CVT(msg_ctime);
    108  1.2  pgoyette #undef CVT
    109  1.2  pgoyette }
    110  1.2  pgoyette 
    111  1.2  pgoyette static inline void
    112  1.2  pgoyette native_to_netbsd32_msqid_ds14(struct msqid_ds *msqbuf, struct netbsd32_msqid_ds14 *omsqbuf)
    113  1.2  pgoyette {
    114  1.2  pgoyette 
    115  1.2  pgoyette 	memset(omsqbuf, 0, sizeof(*omsqbuf));
    116  1.2  pgoyette 	native_to_netbsd32_ipc_perm14(&msqbuf->msg_perm, &omsqbuf->msg_perm);
    117  1.2  pgoyette 
    118  1.2  pgoyette #define	CVT(x)	omsqbuf->x = msqbuf->x
    119  1.2  pgoyette 	CVT(msg_qnum);
    120  1.2  pgoyette 	CVT(msg_qbytes);
    121  1.2  pgoyette 	CVT(msg_lspid);
    122  1.2  pgoyette 	CVT(msg_lrpid);
    123  1.2  pgoyette 	CVT(msg_stime);
    124  1.2  pgoyette 	CVT(msg_rtime);
    125  1.2  pgoyette 	CVT(msg_ctime);
    126  1.2  pgoyette #undef CVT
    127  1.2  pgoyette 
    128  1.2  pgoyette 	/*
    129  1.2  pgoyette 	 * Not part of the API, but some programs might look at it.
    130  1.2  pgoyette 	 */
    131  1.2  pgoyette 	omsqbuf->msg_cbytes = msqbuf->_msg_cbytes;
    132  1.2  pgoyette }
    133  1.2  pgoyette #endif
    134  1.2  pgoyette 
    135  1.2  pgoyette #if defined(SYSVSEM)
    136  1.2  pgoyette static inline void
    137  1.2  pgoyette netbsd32_semid_ds14_to_native(struct netbsd32_semid_ds14 *osembuf, struct semid_ds *sembuf)
    138  1.2  pgoyette {
    139  1.2  pgoyette 
    140  1.2  pgoyette 	netbsd32_ipc_perm14_to_native(&osembuf->sem_perm, &sembuf->sem_perm);
    141  1.2  pgoyette 
    142  1.2  pgoyette #define	CVT(x)	sembuf->x = osembuf->x
    143  1.2  pgoyette 	CVT(sem_nsems);
    144  1.2  pgoyette 	CVT(sem_otime);
    145  1.2  pgoyette 	CVT(sem_ctime);
    146  1.2  pgoyette #undef CVT
    147  1.2  pgoyette }
    148  1.2  pgoyette 
    149  1.2  pgoyette static inline void
    150  1.2  pgoyette native_to_netbsd32_semid_ds14(struct semid_ds *sembuf, struct netbsd32_semid_ds14 *osembuf)
    151  1.2  pgoyette {
    152  1.2  pgoyette 
    153  1.2  pgoyette 	native_to_netbsd32_ipc_perm14(&sembuf->sem_perm, &osembuf->sem_perm);
    154  1.2  pgoyette 
    155  1.2  pgoyette #define	CVT(x)	osembuf->x = sembuf->x
    156  1.2  pgoyette 	CVT(sem_nsems);
    157  1.2  pgoyette 	CVT(sem_otime);
    158  1.2  pgoyette 	CVT(sem_ctime);
    159  1.2  pgoyette #undef CVT
    160  1.2  pgoyette }
    161  1.2  pgoyette 
    162  1.2  pgoyette static inline void
    163  1.2  pgoyette netbsd32_shmid_ds14_to_native(struct netbsd32_shmid_ds14 *oshmbuf, struct shmid_ds *shmbuf)
    164  1.2  pgoyette {
    165  1.2  pgoyette 
    166  1.2  pgoyette 	netbsd32_ipc_perm14_to_native(&oshmbuf->shm_perm, &shmbuf->shm_perm);
    167  1.2  pgoyette 
    168  1.2  pgoyette #define	CVT(x)	shmbuf->x = oshmbuf->x
    169  1.2  pgoyette 	CVT(shm_segsz);
    170  1.2  pgoyette 	CVT(shm_lpid);
    171  1.2  pgoyette 	CVT(shm_cpid);
    172  1.2  pgoyette 	CVT(shm_nattch);
    173  1.2  pgoyette 	CVT(shm_atime);
    174  1.2  pgoyette 	CVT(shm_dtime);
    175  1.2  pgoyette 	CVT(shm_ctime);
    176  1.2  pgoyette #undef CVT
    177  1.2  pgoyette }
    178  1.2  pgoyette 
    179  1.2  pgoyette static inline void
    180  1.2  pgoyette native_to_netbsd32_shmid_ds14(struct shmid_ds *shmbuf, struct netbsd32_shmid_ds14 *oshmbuf)
    181  1.2  pgoyette {
    182  1.2  pgoyette 
    183  1.2  pgoyette 	native_to_netbsd32_ipc_perm14(&shmbuf->shm_perm, &oshmbuf->shm_perm);
    184  1.2  pgoyette 
    185  1.2  pgoyette #define	CVT(x)	oshmbuf->x = shmbuf->x
    186  1.2  pgoyette 	CVT(shm_segsz);
    187  1.2  pgoyette 	CVT(shm_lpid);
    188  1.2  pgoyette 	CVT(shm_cpid);
    189  1.2  pgoyette 	CVT(shm_nattch);
    190  1.2  pgoyette 	CVT(shm_atime);
    191  1.2  pgoyette 	CVT(shm_dtime);
    192  1.2  pgoyette 	CVT(shm_ctime);
    193  1.2  pgoyette #undef CVT
    194  1.2  pgoyette }
    195  1.2  pgoyette 
    196  1.2  pgoyette /*
    197  1.2  pgoyette  * the compat_14 system calls
    198  1.2  pgoyette  */
    199  1.2  pgoyette int
    200  1.2  pgoyette compat_14_netbsd32_msgctl(struct lwp *l, const struct compat_14_netbsd32_msgctl_args *uap, register_t *retval)
    201  1.2  pgoyette {
    202  1.2  pgoyette 	/* {
    203  1.2  pgoyette 		syscallarg(int) msqid;
    204  1.2  pgoyette 		syscallarg(int) cmd;
    205  1.2  pgoyette 		syscallarg(struct msqid_ds14 *) buf;
    206  1.2  pgoyette 	} */
    207  1.2  pgoyette 	struct msqid_ds msqbuf;
    208  1.2  pgoyette 	struct netbsd32_msqid_ds14 omsqbuf;
    209  1.2  pgoyette 	int cmd, error;
    210  1.2  pgoyette 
    211  1.2  pgoyette 	cmd = SCARG(uap, cmd);
    212  1.2  pgoyette 
    213  1.2  pgoyette 	if (cmd == IPC_SET) {
    214  1.2  pgoyette 		error = copyin(SCARG_P32(uap, buf),
    215  1.2  pgoyette 		    &omsqbuf, sizeof(omsqbuf));
    216  1.2  pgoyette 		if (error)
    217  1.2  pgoyette 			return (error);
    218  1.2  pgoyette 		netbsd32_msqid_ds14_to_native(&omsqbuf, &msqbuf);
    219  1.2  pgoyette 	}
    220  1.2  pgoyette 
    221  1.2  pgoyette 	error = msgctl1(l, SCARG(uap, msqid), cmd,
    222  1.2  pgoyette 	    (cmd == IPC_SET || cmd == IPC_STAT) ? &msqbuf : NULL);
    223  1.2  pgoyette 
    224  1.2  pgoyette 	if (error == 0 && cmd == IPC_STAT) {
    225  1.2  pgoyette 		native_to_netbsd32_msqid_ds14(&msqbuf, &omsqbuf);
    226  1.2  pgoyette 		error = copyout(&omsqbuf,
    227  1.2  pgoyette 		    SCARG_P32(uap, buf), sizeof(omsqbuf));
    228  1.2  pgoyette 	}
    229  1.2  pgoyette 
    230  1.2  pgoyette 	return (error);
    231  1.2  pgoyette }
    232  1.2  pgoyette #endif
    233  1.2  pgoyette 
    234  1.2  pgoyette #if defined(SYSVSEM)
    235  1.2  pgoyette int
    236  1.2  pgoyette compat_14_netbsd32___semctl(struct lwp *l, const struct compat_14_netbsd32___semctl_args *uap, register_t *retval)
    237  1.2  pgoyette {
    238  1.2  pgoyette 	/* {
    239  1.2  pgoyette 		syscallarg(int) semid;
    240  1.2  pgoyette 		syscallarg(int) semnum;
    241  1.2  pgoyette 		syscallarg(int) cmd;
    242  1.2  pgoyette 		syscallarg(union __semun *) arg;
    243  1.2  pgoyette 	} */
    244  1.2  pgoyette 	union __semun arg;
    245  1.2  pgoyette 	struct semid_ds sembuf;
    246  1.2  pgoyette 	struct netbsd32_semid_ds14 osembuf;
    247  1.2  pgoyette 	int cmd, error;
    248  1.2  pgoyette 	void *pass_arg = NULL;
    249  1.2  pgoyette 
    250  1.2  pgoyette 	cmd = SCARG(uap, cmd);
    251  1.2  pgoyette 
    252  1.2  pgoyette 	switch (cmd) {
    253  1.2  pgoyette 	case IPC_SET:
    254  1.2  pgoyette 	case IPC_STAT:
    255  1.2  pgoyette 		pass_arg = &sembuf;
    256  1.2  pgoyette 		break;
    257  1.2  pgoyette 
    258  1.2  pgoyette 	case GETALL:
    259  1.2  pgoyette 	case SETVAL:
    260  1.2  pgoyette 	case SETALL:
    261  1.2  pgoyette 		pass_arg = &arg;
    262  1.2  pgoyette 		break;
    263  1.2  pgoyette 	}
    264  1.2  pgoyette 
    265  1.2  pgoyette 	if (pass_arg != NULL) {
    266  1.2  pgoyette 		error = copyin(NETBSD32IPTR64(SCARG(uap, arg)), &arg,
    267  1.2  pgoyette 		    sizeof(arg));
    268  1.2  pgoyette 		if (error)
    269  1.2  pgoyette 			return (error);
    270  1.2  pgoyette 		if (cmd == IPC_SET) {
    271  1.2  pgoyette 			error = copyin(arg.buf, &osembuf, sizeof(osembuf));
    272  1.2  pgoyette 			if (error)
    273  1.2  pgoyette 				return (error);
    274  1.2  pgoyette 			netbsd32_semid_ds14_to_native(&osembuf, &sembuf);
    275  1.2  pgoyette 		}
    276  1.2  pgoyette 	}
    277  1.2  pgoyette 
    278  1.2  pgoyette 	error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
    279  1.2  pgoyette 	    pass_arg, retval);
    280  1.2  pgoyette 
    281  1.2  pgoyette 	if (error == 0 && cmd == IPC_STAT) {
    282  1.2  pgoyette 		native_to_netbsd32_semid_ds14(&sembuf, &osembuf);
    283  1.2  pgoyette 		error = copyout(&osembuf, arg.buf, sizeof(osembuf));
    284  1.2  pgoyette 	}
    285  1.2  pgoyette 
    286  1.2  pgoyette 	return (error);
    287  1.2  pgoyette }
    288  1.2  pgoyette #endif
    289  1.2  pgoyette 
    290  1.2  pgoyette #if defined(SYSVSHM)
    291  1.2  pgoyette int
    292  1.2  pgoyette compat_14_netbsd32_shmctl(struct lwp *l, const struct compat_14_netbsd32_shmctl_args *uap, register_t *retval)
    293  1.2  pgoyette {
    294  1.2  pgoyette 	/* {
    295  1.2  pgoyette 		syscallarg(int) shmid;
    296  1.2  pgoyette 		syscallarg(int) cmd;
    297  1.2  pgoyette 		syscallarg(struct netbsd32_shmid_ds14 *) buf;
    298  1.2  pgoyette 	} */
    299  1.2  pgoyette 	struct shmid_ds shmbuf;
    300  1.2  pgoyette 	struct netbsd32_shmid_ds14 oshmbuf;
    301  1.2  pgoyette 	int cmd, error;
    302  1.2  pgoyette 
    303  1.2  pgoyette 	cmd = SCARG(uap, cmd);
    304  1.2  pgoyette 
    305  1.2  pgoyette 	if (cmd == IPC_SET) {
    306  1.2  pgoyette 		error = copyin(SCARG_P32(uap, buf), &oshmbuf, sizeof(oshmbuf));
    307  1.2  pgoyette 		if (error)
    308  1.2  pgoyette 			return (error);
    309  1.2  pgoyette 		netbsd32_shmid_ds14_to_native(&oshmbuf, &shmbuf);
    310  1.2  pgoyette 	}
    311  1.2  pgoyette 
    312  1.2  pgoyette 	error = shmctl1(l, SCARG(uap, shmid), cmd,
    313  1.2  pgoyette 	    (cmd == IPC_SET || cmd == IPC_STAT) ? &shmbuf : NULL);
    314  1.2  pgoyette 
    315  1.2  pgoyette 	if (error == 0 && cmd == IPC_STAT) {
    316  1.2  pgoyette 		native_to_netbsd32_shmid_ds14(&shmbuf, &oshmbuf);
    317  1.2  pgoyette 		error = copyout(&oshmbuf, SCARG_P32(uap, buf), sizeof(oshmbuf));
    318  1.2  pgoyette 	}
    319  1.2  pgoyette 
    320  1.2  pgoyette 	return (error);
    321  1.2  pgoyette }
    322  1.2  pgoyette #endif
    323  1.2  pgoyette 
    324  1.2  pgoyette #define REQ1    "sysv_ipc,compat_sysv_14,"
    325  1.2  pgoyette #define REQ2    "compat_netbsd32,compat_netbsd32_sysvipc,"
    326  1.2  pgoyette #define REQ3    "compat_netbsd32_sysvipc_50"
    327  1.2  pgoyette 
    328  1.2  pgoyette #define _PKG_ENTRY(name)        \
    329  1.2  pgoyette 	{ NETBSD32_SYS_ ## name, 0, (sy_call_t *)name }
    330  1.2  pgoyette 
    331  1.2  pgoyette static const struct syscall_package compat_sysvipc_14_syscalls[] = {
    332  1.2  pgoyette #if defined(SYSVSEM)
    333  1.2  pgoyette 	_PKG_ENTRY(compat_14_netbsd32___semctl),
    334  1.2  pgoyette #endif
    335  1.2  pgoyette #if defined(SYSVSHM)
    336  1.2  pgoyette 	_PKG_ENTRY(compat_14_netbsd32_shmctl),
    337  1.2  pgoyette #endif
    338  1.2  pgoyette #if defined(SYSVMSG)
    339  1.2  pgoyette 	_PKG_ENTRY(compat_14_netbsd32_msgctl),
    340  1.2  pgoyette #endif
    341  1.2  pgoyette 	{ 0, 0, NULL }
    342  1.2  pgoyette };
    343  1.2  pgoyette 
    344  1.2  pgoyette #define REQ1    "sysv_ipc,compat_sysv_14,"
    345  1.2  pgoyette #define REQ2    "compat_netbsd32,compat_netbsd32_sysvipc,"
    346  1.2  pgoyette #define REQ3    "compat_netbsd32_sysvipc_50"
    347  1.2  pgoyette 
    348  1.2  pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_sysvipc_14, REQ1 REQ2 REQ3 );
    349  1.2  pgoyette 
    350  1.2  pgoyette static int
    351  1.2  pgoyette compat_netbsd32_sysvipc_14_modcmd(modcmd_t cmd, void *arg)
    352  1.2  pgoyette {
    353  1.2  pgoyette 
    354  1.2  pgoyette 	switch (cmd) {
    355  1.2  pgoyette 	case MODULE_CMD_INIT:
    356  1.2  pgoyette 		return syscall_establish(&emul_netbsd32,
    357  1.2  pgoyette 		    compat_sysvipc_14_syscalls);
    358  1.2  pgoyette 
    359  1.2  pgoyette 	case MODULE_CMD_FINI:
    360  1.2  pgoyette 		return syscall_disestablish(&emul_netbsd32,
    361  1.2  pgoyette 		    compat_sysvipc_14_syscalls);
    362  1.2  pgoyette 
    363  1.2  pgoyette 	default:
    364  1.2  pgoyette 		return ENOTTY;
    365  1.2  pgoyette 	}
    366  1.2  pgoyette }
    367  1.2  pgoyette 
    368  1.2  pgoyette #endif /* COMPAT_14 */
    369