xref: /netbsd-src/sys/compat/common/sysv_shm_14.c (revision d91f98a8715141154279122ae81737cb65179572)
1*d91f98a8Spgoyette /*	$NetBSD: sysv_shm_14.c,v 1.18 2019/01/27 02:08:39 pgoyette Exp $	*/
29244fc5bSthorpej 
39244fc5bSthorpej /*-
49244fc5bSthorpej  * Copyright (c) 1999 The NetBSD Foundation, Inc.
59244fc5bSthorpej  * All rights reserved.
69244fc5bSthorpej  *
79244fc5bSthorpej  * This code is derived from software contributed to The NetBSD Foundation
89244fc5bSthorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
99244fc5bSthorpej  * NASA Ames Research Center.
109244fc5bSthorpej  *
119244fc5bSthorpej  * Redistribution and use in source and binary forms, with or without
129244fc5bSthorpej  * modification, are permitted provided that the following conditions
139244fc5bSthorpej  * are met:
149244fc5bSthorpej  * 1. Redistributions of source code must retain the above copyright
159244fc5bSthorpej  *    notice, this list of conditions and the following disclaimer.
169244fc5bSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
179244fc5bSthorpej  *    notice, this list of conditions and the following disclaimer in the
189244fc5bSthorpej  *    documentation and/or other materials provided with the distribution.
199244fc5bSthorpej  *
209244fc5bSthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
219244fc5bSthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
229244fc5bSthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
239244fc5bSthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
249244fc5bSthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
259244fc5bSthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
269244fc5bSthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
279244fc5bSthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
289244fc5bSthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
299244fc5bSthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
309244fc5bSthorpej  * POSSIBILITY OF SUCH DAMAGE.
319244fc5bSthorpej  */
329244fc5bSthorpej 
33dab6ef8bSlukem #include <sys/cdefs.h>
34*d91f98a8Spgoyette __KERNEL_RCSID(0, "$NetBSD: sysv_shm_14.c,v 1.18 2019/01/27 02:08:39 pgoyette Exp $");
35*d91f98a8Spgoyette 
36*d91f98a8Spgoyette #if defined(_KERNEL_OPT)
37*d91f98a8Spgoyette #include "opt_compat_netbsd.h"
38*d91f98a8Spgoyette #endif
39dab6ef8bSlukem 
409244fc5bSthorpej #include <sys/param.h>
419244fc5bSthorpej #include <sys/systm.h>
429244fc5bSthorpej #include <sys/signal.h>
439244fc5bSthorpej #include <sys/proc.h>
449244fc5bSthorpej #include <sys/shm.h>
459244fc5bSthorpej 
46df68499fSjdolecek #ifndef SYSVSHM
479244fc5bSthorpej #define	SYSVSHM
48df68499fSjdolecek #endif
499244fc5bSthorpej 
509244fc5bSthorpej #include <sys/syscallargs.h>
519244fc5bSthorpej 
522a4a5534Schristos #include <compat/sys/shm.h>
532a4a5534Schristos 
549244fc5bSthorpej 
559244fc5bSthorpej int
compat_14_sys_shmctl(struct lwp * l,const struct compat_14_sys_shmctl_args * uap,register_t * retval)567e2790cfSdsl compat_14_sys_shmctl(struct lwp *l, const struct compat_14_sys_shmctl_args *uap, register_t *retval)
579244fc5bSthorpej {
587e2790cfSdsl 	/* {
599244fc5bSthorpej 		syscallarg(int) shmid;
609244fc5bSthorpej 		syscallarg(int) cmd;
619244fc5bSthorpej 		syscallarg(struct shmid_ds14 *) buf;
627e2790cfSdsl 	} */
639244fc5bSthorpej 	struct shmid_ds shmbuf;
649244fc5bSthorpej 	struct shmid_ds14 oshmbuf;
659244fc5bSthorpej 	int cmd, error;
669244fc5bSthorpej 
679244fc5bSthorpej 	cmd = SCARG(uap, cmd);
689244fc5bSthorpej 
699244fc5bSthorpej 	if (cmd == IPC_SET) {
709244fc5bSthorpej 		error = copyin(SCARG(uap, buf), &oshmbuf, sizeof(oshmbuf));
719244fc5bSthorpej 		if (error)
729244fc5bSthorpej 			return (error);
73461a86f9Schristos 		__shmid_ds14_to_native(&oshmbuf, &shmbuf);
749244fc5bSthorpej 	}
759244fc5bSthorpej 
76f474dcebSad 	error = shmctl1(l, SCARG(uap, shmid), cmd,
779244fc5bSthorpej 	    (cmd == IPC_SET || cmd == IPC_STAT) ? &shmbuf : NULL);
789244fc5bSthorpej 
799244fc5bSthorpej 	if (error == 0 && cmd == IPC_STAT) {
80461a86f9Schristos 		__native_to_shmid_ds14(&shmbuf, &oshmbuf);
819244fc5bSthorpej 		error = copyout(&oshmbuf, SCARG(uap, buf), sizeof(oshmbuf));
829244fc5bSthorpej 	}
839244fc5bSthorpej 
849244fc5bSthorpej 	return (error);
859244fc5bSthorpej }
86