1 /* $NetBSD: sysv_ipc_50.c,v 1.1 2009/01/19 19:39:41 christos Exp $ */
4 * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: sysv_ipc_50.c,v 1.1 2009/01/19 19:39:41 christos Exp $");
37 #include "opt_compat_netbsd.h"
40 #include <sys/param.h>
41 #include <sys/kernel.h>
53 #include <sys/systm.h>
54 #include <sys/malloc.h>
55 #include <sys/mount.h>
56 #include <sys/vnode.h>
58 #include <sys/sysctl.h>
59 #include <sys/kauth.h>
62 #include <compat/sys/ipc.h>
64 #include <compat/sys/msg.h>
67 #include <compat/sys/sem.h>
70 #include <compat/sys/shm.h>
74 * Check for ipc permission
78 sysctl_kern_sysvipc50(SYSCTLFN_ARGS
)
81 size_t *sizep
= oldlenp
;
83 struct msg_sysctl_info50
*msgsi
= NULL
;
86 struct sem_sysctl_info50
*semsi
= NULL
;
89 struct shm_sysctl_info50
*shmsi
= NULL
;
91 size_t infosize
, dssize
, tsize
, buflen
;
104 case KERN_SYSVIPC_OMSG_INFO
:
106 infosize
= sizeof(msgsi
->msginfo
);
107 nds
= msginfo
.msgmni
;
108 dssize
= sizeof(msgsi
->msgids
[0]);
113 case KERN_SYSVIPC_OSEM_INFO
:
115 infosize
= sizeof(semsi
->seminfo
);
116 nds
= seminfo
.semmni
;
117 dssize
= sizeof(semsi
->semids
[0]);
122 case KERN_SYSVIPC_OSHM_INFO
:
124 infosize
= sizeof(shmsi
->shminfo
);
125 nds
= shminfo
.shmmni
;
126 dssize
= sizeof(shmsi
->shmids
[0]);
135 * Round infosize to 64 bit boundary if requesting more than just
136 * the info structure or getting the total data size.
138 if (where
== NULL
|| *sizep
> infosize
)
139 infosize
= roundup(infosize
, sizeof(quad_t
));
140 tsize
= infosize
+ nds
* dssize
;
142 /* Return just the total size required. */
148 /* Not enough room for even the info struct. */
149 if (buflen
< infosize
) {
153 bf
= malloc(min(tsize
, buflen
), M_TEMP
, M_WAITOK
| M_ZERO
);
157 case KERN_SYSVIPC_OMSG_INFO
:
158 msgsi
= (struct msg_sysctl_info50
*)bf
;
159 msgsi
->msginfo
= msginfo
;
163 case KERN_SYSVIPC_OSEM_INFO
:
164 semsi
= (struct sem_sysctl_info50
*)bf
;
165 semsi
->seminfo
= seminfo
;
169 case KERN_SYSVIPC_OSHM_INFO
:
170 shmsi
= (struct shm_sysctl_info50
*)bf
;
171 shmsi
->shminfo
= shminfo
;
179 /* Fill in the IPC data structures. */
180 for (i
= 0; i
< nds
; i
++) {
181 if (buflen
< dssize
) {
187 case KERN_SYSVIPC_OMSG_INFO
:
188 mutex_enter(&msgmutex
);
189 SYSCTL_FILL_MSG(msqs
[i
].msq_u
, msgsi
->msgids
[i
]);
190 mutex_exit(&msgmutex
);
194 case KERN_SYSVIPC_OSEM_INFO
:
195 SYSCTL_FILL_SEM(sema
[i
], semsi
->semids
[i
]);
199 case KERN_SYSVIPC_OSHM_INFO
:
200 SYSCTL_FILL_SHM(shmsegs
[i
], shmsi
->shmids
[i
]);
208 error
= copyout(bf
, start
, *sizep
);
209 /* If copyout succeeded, use return code set earlier. */