1*d91f98a8Spgoyette /* $NetBSD: sysv_sem_14.c,v 1.17 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_sem_14.c,v 1.17 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/sem.h>
459244fc5bSthorpej
46df68499fSjdolecek #ifndef SYSVSEM
479244fc5bSthorpej #define SYSVSEM
48df68499fSjdolecek #endif
499244fc5bSthorpej
509244fc5bSthorpej #include <sys/syscallargs.h>
519244fc5bSthorpej
52063b880cSchristos #include <compat/sys/sem.h>
53063b880cSchristos
549244fc5bSthorpej
559244fc5bSthorpej int
compat_14_sys___semctl(struct lwp * l,const struct compat_14_sys___semctl_args * uap,register_t * retval)567e2790cfSdsl compat_14_sys___semctl(struct lwp *l, const struct compat_14_sys___semctl_args *uap, register_t *retval)
579244fc5bSthorpej {
587e2790cfSdsl /* {
599244fc5bSthorpej syscallarg(int) semid;
609244fc5bSthorpej syscallarg(int) semnum;
619244fc5bSthorpej syscallarg(int) cmd;
629244fc5bSthorpej syscallarg(union __semun *) arg;
637e2790cfSdsl } */
649244fc5bSthorpej union __semun arg;
659244fc5bSthorpej struct semid_ds sembuf;
669244fc5bSthorpej struct semid_ds14 osembuf;
679244fc5bSthorpej int cmd, error;
6882cfad02Sdsl void *pass_arg;
699244fc5bSthorpej
709244fc5bSthorpej cmd = SCARG(uap, cmd);
719244fc5bSthorpej
7282cfad02Sdsl pass_arg = get_semctl_arg(cmd, &sembuf, &arg);
739244fc5bSthorpej
749244fc5bSthorpej if (pass_arg != NULL) {
759244fc5bSthorpej error = copyin(SCARG(uap, arg), &arg, sizeof(arg));
769244fc5bSthorpej if (error)
779244fc5bSthorpej return (error);
789244fc5bSthorpej if (cmd == IPC_SET) {
799244fc5bSthorpej error = copyin(arg.buf, &osembuf, sizeof(osembuf));
809244fc5bSthorpej if (error)
819244fc5bSthorpej return (error);
82461a86f9Schristos __semid_ds14_to_native(&osembuf, &sembuf);
839244fc5bSthorpej }
849244fc5bSthorpej }
859244fc5bSthorpej
86f474dcebSad error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
879244fc5bSthorpej pass_arg, retval);
889244fc5bSthorpej
899244fc5bSthorpej if (error == 0 && cmd == IPC_STAT) {
90461a86f9Schristos __native_to_semid_ds14(&sembuf, &osembuf);
919244fc5bSthorpej error = copyout(&osembuf, arg.buf, sizeof(osembuf));
929244fc5bSthorpej }
939244fc5bSthorpej
949244fc5bSthorpej return (error);
959244fc5bSthorpej }
96