xref: /netbsd-src/sys/compat/common/sysv_sem_50.c (revision 1e72df6a037fdd3c6d3014a2679ffff7daab84ca)
1*1e72df6aStsutsui /*	$NetBSD: sysv_sem_50.c,v 1.5 2019/12/15 16:48:26 tsutsui Exp $	*/
2461a86f9Schristos 
3461a86f9Schristos /*-
4461a86f9Schristos  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5461a86f9Schristos  * All rights reserved.
6461a86f9Schristos  *
7461a86f9Schristos  * This code is derived from software contributed to The NetBSD Foundation
8461a86f9Schristos  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9461a86f9Schristos  * NASA Ames Research Center.
10461a86f9Schristos  *
11461a86f9Schristos  * Redistribution and use in source and binary forms, with or without
12461a86f9Schristos  * modification, are permitted provided that the following conditions
13461a86f9Schristos  * are met:
14461a86f9Schristos  * 1. Redistributions of source code must retain the above copyright
15461a86f9Schristos  *    notice, this list of conditions and the following disclaimer.
16461a86f9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
17461a86f9Schristos  *    notice, this list of conditions and the following disclaimer in the
18461a86f9Schristos  *    documentation and/or other materials provided with the distribution.
19461a86f9Schristos  *
20461a86f9Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21461a86f9Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22461a86f9Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23461a86f9Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24461a86f9Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25461a86f9Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26461a86f9Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27461a86f9Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28461a86f9Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29461a86f9Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30461a86f9Schristos  * POSSIBILITY OF SUCH DAMAGE.
31461a86f9Schristos  */
32461a86f9Schristos 
33461a86f9Schristos #include <sys/cdefs.h>
34*1e72df6aStsutsui __KERNEL_RCSID(0, "$NetBSD: sysv_sem_50.c,v 1.5 2019/12/15 16:48:26 tsutsui Exp $");
35d91f98a8Spgoyette 
36d91f98a8Spgoyette #if defined(_KERNEL_OPT)
37d91f98a8Spgoyette #include "opt_compat_netbsd.h"
38d91f98a8Spgoyette #endif
39461a86f9Schristos 
40461a86f9Schristos #include <sys/param.h>
41461a86f9Schristos #include <sys/systm.h>
42461a86f9Schristos #include <sys/signal.h>
43461a86f9Schristos #include <sys/proc.h>
44461a86f9Schristos #include <sys/sem.h>
45461a86f9Schristos 
46461a86f9Schristos #ifndef SYSVSEM
47461a86f9Schristos #define	SYSVSEM
48461a86f9Schristos #endif
49461a86f9Schristos 
50461a86f9Schristos #include <sys/syscallargs.h>
51461a86f9Schristos 
52461a86f9Schristos #include <compat/sys/sem.h>
53461a86f9Schristos 
54461a86f9Schristos int
compat_50_sys_____semctl13(struct lwp * l,const struct compat_50_sys_____semctl13_args * uap,register_t * retval)55461a86f9Schristos compat_50_sys_____semctl13(struct lwp *l, const struct compat_50_sys_____semctl13_args *uap, register_t *retval)
56461a86f9Schristos {
57461a86f9Schristos 	/* {
58461a86f9Schristos 		syscallarg(int) semid;
59461a86f9Schristos 		syscallarg(int) semnum;
60461a86f9Schristos 		syscallarg(int) cmd;
61461a86f9Schristos 		syscallarg(union __semun *) arg;
62461a86f9Schristos 	} */
63461a86f9Schristos 	union __semun arg;
64461a86f9Schristos 	struct semid_ds sembuf;
65461a86f9Schristos 	struct semid_ds13 osembuf;
66461a86f9Schristos 	int cmd, error;
67461a86f9Schristos 	void *pass_arg;
68461a86f9Schristos 
69461a86f9Schristos 	cmd = SCARG(uap, cmd);
70461a86f9Schristos 
71461a86f9Schristos 	pass_arg = get_semctl_arg(cmd, &sembuf, &arg);
72461a86f9Schristos 
73461a86f9Schristos 	if (pass_arg != NULL) {
74461a86f9Schristos 		error = copyin(SCARG(uap, arg), &arg, sizeof(arg));
75461a86f9Schristos 		if (error)
76461a86f9Schristos 			return (error);
77461a86f9Schristos 		if (cmd == IPC_SET) {
78461a86f9Schristos 			error = copyin(arg.buf, &osembuf, sizeof(osembuf));
79461a86f9Schristos 			if (error)
80461a86f9Schristos 				return (error);
81461a86f9Schristos 			__semid_ds13_to_native(&osembuf, &sembuf);
82461a86f9Schristos 		}
83461a86f9Schristos 	}
84461a86f9Schristos 
85461a86f9Schristos 	error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
86461a86f9Schristos 	    pass_arg, retval);
87461a86f9Schristos 
88461a86f9Schristos 	if (error == 0 && cmd == IPC_STAT) {
89461a86f9Schristos 		__native_to_semid_ds13(&sembuf, &osembuf);
90461a86f9Schristos 		error = copyout(&osembuf, arg.buf, sizeof(osembuf));
91461a86f9Schristos 	}
92461a86f9Schristos 
93461a86f9Schristos 	return (error);
94461a86f9Schristos }
95