Subject: Re: SysV SHM locking and reallocating support
To: None <tech-kern@netbsd.org>
From: Mindaugas <unex@linija.org>
List: tech-kern
Date: 10/14/2006 03:22:25
This is a multi-part message in MIME format.
--Multipart=_Sat__14_Oct_2006_03_22_25_+0300_n5yR1KJPd6x3h=BM
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Could someone would review a UVM part of this patch before submitting a PR?
Thanks.
--
Best regards,
Mindaugas
--Multipart=_Sat__14_Oct_2006_03_22_25_+0300_n5yR1KJPd6x3h=BM
Content-Type: application/octet-stream;
name="sysv_3.diff"
Content-Disposition: attachment;
filename="sysv_3.diff"
Content-Transfer-Encoding: quoted-printable
Index: lib/libc/gen/sysconf.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/libc/gen/sysconf.c,v
retrieving revision 1.21
diff -u -r1.21 sysconf.c
--- lib/libc/gen/sysconf.c 10 Nov 2004 04:46:01 -0000 1.21
+++ lib/libc/gen/sysconf.c 14 Oct 2006 00:05:25 -0000
@@ -74,7 +74,7 @@
{
struct rlimit rl;
size_t len;
- int mib[2], value;
+ int mib[3], value;
struct clockinfo tmpclock;
static int clk_tck;
=20
@@ -282,8 +282,13 @@
break;
case _SC_XOPEN_SHM:
mib[0] =3D CTL_KERN;
- mib[1] =3D KERN_SYSVSHM;
- goto yesno;
+ mib[1] =3D KERN_SYSVIPC;
+ mib[2] =3D KERN_SYSVIPC_SHM;
+ if (sysctl(mib, 3, &value, &len, NULL, 0) =3D=3D -1)
+ return (-1);
+ if (value =3D=3D 0)
+ return (-1);
+ return (0);
=20
/* 1003.1-2001, XSI Option Group */
case _SC_ATEXIT_MAX:
Index: lib/libc/gen/sysctl.3
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/libc/gen/sysctl.3,v
retrieving revision 1.177.2.3
diff -u -r1.177.2.3 sysctl.3
--- lib/libc/gen/sysctl.3 8 Sep 2006 18:59:08 -0000 1.177.2.3
+++ lib/libc/gen/sysctl.3 14 Oct 2006 00:05:26 -0000
@@ -469,10 +469,7 @@
.It KERN\_SAVED\_IDS integer no
.It KERN\_SECURELVL integer raise only
.It KERN\_SYNCHRONIZED\_IO integer no
-.It KERN\_SYSVIPC\_INFO node not applicable
-.It KERN\_SYSVMSG integer no
-.It KERN\_SYSVSEM integer no
-.It KERN\_SYSVSHM integer no
+.It KERN\_SYSVIPC node not applicable
.It KERN\_TIMEX struct no
.It KERN\_TKSTAT node not applicable
.It KERN\_URANDOM integer no
@@ -862,11 +859,39 @@
Returns 1 if the POSIX 1003.1b Synchronized I/O Option is available
on this system,
otherwise 0.
+.It Li KERN_SYSVIPC
+Return information about the SysV IPC parameters. The third
+level names for the ipc variables are detailed below.
+.Bl -column "KERN_SYSVIPC_MSGXXX" "integerXXX" "noXXX" -offset indent
+.It Sy Third level name Type Changeable
+.It KERN\_SYSVIPC\_MSG integer no
+.It KERN\_SYSVIPC\_SEM integer no
+.It KERN\_SYSVIPC\_SHM integer no
+.It KERN\_SYSVIPC\_INFO struct no
+.It KERN\_SYSVIPC\_SHMMAX integer no
+.It KERN\_SYSVIPC\_SHMMNI integer yes
+.It KERN\_SYSVIPC\_SHMSEG integer yes
+.It KERN\_SYSVIPC\_SHMMAXPGS integer yes
+.It KERN\_SYSVIPC\_SHMUSEPHYS integer yes
+.El
+.Bl -tag -width "123456"
+.It Li KERN_SYSVIPC_MSG
+Returns 1 if System V style message queue functionality is available
+on this system,
+otherwise 0.
+.It Li KERN_SYSVIPC_SEM
+Returns 1 if System V style semaphore functionality is available
+on this system,
+otherwise 0.
+.It Li KERN_SYSVIPC_SHM
+Returns 1 if System V style share memory functionality is available
+on this system,
+otherwise 0.
.It Li KERN_SYSVIPC_INFO
Return System V style IPC configuration and run-time information.
The third level name selects the System V style IPC facility.
.Bl -column "KERN_SYSVIPC_MSG_INFOXXX" "struct shm_sysctl_infoXXX" -offset=
indent
-.It Sy Third level name Type
+.It Sy Fourth level name Type
.It KERN\_SYSVIPC\_MSG\_INFO struct msg_sysctl_info
.It KERN\_SYSVIPC\_SEM\_INFO struct sem_sysctl_info
.It KERN\_SYSVIPC\_SHM\_INFO struct shm_sysctl_info
@@ -892,18 +917,18 @@
structure is defined in
.Aq Pa sys/shm.h .
.El
-.It Li KERN_SYSVMSG
-Returns 1 if System V style message queue functionality is available
-on this system,
-otherwise 0.
-.It Li KERN_SYSVSEM
-Returns 1 if System V style semaphore functionality is available
-on this system,
-otherwise 0.
-.It Li KERN_SYSVSHM
-Returns 1 if System V style share memory functionality is available
-on this system,
-otherwise 0.
+.It Li KERN_SYSVIPC_SHMMAX
+Max shared memory segment size in bytes.
+.It Li KERN_SYSVIPC_SHMMNI
+Max number of shared memory identifiers.
+.It Li KERN_SYSVIPC_SHMSEG
+Max shared memory segments per process.
+.It Li KERN_SYSVIPC_SHMMAXPGS
+Max amount of shared memory in pages.
+.It Li KERN_SYSVIPC_SHMUSEPHYS
+Locking of shared memory in physical memory. If 0, memory can be swaped
+out, otherwise it will be locked in physical memory.
+.El
.It Li KERN_TIMEX
Not available.
.It Li KERN_TKSTAT
Index: lib/libc/sys/shmctl.2
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/libc/sys/shmctl.2,v
retrieving revision 1.16
diff -u -r1.16 shmctl.2
--- lib/libc/sys/shmctl.2 13 May 2004 10:20:58 -0000 1.16
+++ lib/libc/sys/shmctl.2 14 Oct 2006 00:05:26 -0000
@@ -113,6 +113,15 @@
or
.Va shm_perm.uid
values in the data structure associated with the queue can do this.
+.It Dv SHM_LOCK
+Lock the shared memory segment specified by
+.Fa shmid
+in memory.
+This operation can only be executed by the super-user.
+.It Dv SHM_UNLOCK
+Unlock the shared memory segment=A0specified by
+.Fa shmid .
+This operation can only be executed by the super-user.
.El
.Pp
The read and write permissions on a shared memory identifier
@@ -157,6 +166,10 @@
through
.Dv IPC_SET
but the caller is not the super-user.
+.Pp
+The
+.Fa cmd
+is equal to SHM_LOCK or SHM_UNLOCK and the caller is not the super-user.
.It Bq Er EACCES
The command is
.Dv IPC_STAT
@@ -170,6 +183,10 @@
.It Bq Er EFAULT
.Fa buf
specifies an invalid address.
+.It Bq Er ENOMEM
+The
+.Fa cmd
+is equal to SHM_LOCK and there is not enough physical memory.
.El
.Sh SEE ALSO
.Xr ipcrm 1 ,
Index: sbin/sysctl/sysctl.8
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/sbin/sysctl/sysctl.8,v
retrieving revision 1.149.2.2
diff -u -r1.149.2.2 sysctl.8
--- sbin/sysctl/sysctl.8 8 Sep 2006 18:59:08 -0000 1.149.2.2
+++ sbin/sysctl/sysctl.8 14 Oct 2006 00:05:29 -0000
@@ -363,10 +363,15 @@
.It kern.securelevel integer raise only
.It kern.somaxkva integer yes
.It kern.synchronized_io integer no
-.It kern.sysvipc_info struct no
-.It kern.sysvmsg integer no
-.It kern.sysvsem integer no
-.It kern.sysvshm integer no
+.It kern.ipc.sysvipc_info struct no
+.It kern.ipc.sysvmsg integer no
+.It kern.ipc.sysvsem integer no
+.It kern.ipc.sysvshm integer no
+.It kern.ipc.shmmax integer no
+.It kern.ipc.shmmni integer yes
+.It kern.ipc.shmseg integer yes
+.It kern.ipc.shmmaxpgs integer yes
+.It kern.ipc.shm_use_phys integer yes
.It kern.timecounter.choice string no
.It kern.timecounter.hardware string yes
.It kern.timecounter.timestepwarnings integer yes
Index: sys/kern/init_sysctl.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/sys/kern/init_sysctl.c,v
retrieving revision 1.81
diff -u -r1.81 init_sysctl.c
--- sys/kern/init_sysctl.c 26 Jul 2006 09:33:57 -0000 1.81
+++ sys/kern/init_sysctl.c 14 Oct 2006 00:05:43 -0000
@@ -77,19 +77,6 @@
#include <sys/stat.h>
#include <sys/kauth.h>
=20
-#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
-#include <sys/ipc.h>
-#endif
-#ifdef SYSVMSG
-#include <sys/msg.h>
-#endif
-#ifdef SYSVSEM
-#include <sys/sem.h>
-#endif
-#ifdef SYSVSHM
-#include <sys/shm.h>
-#endif
-
#include <machine/cpu.h>
=20
/* XXX this should not be here */
@@ -140,9 +127,6 @@
static int sysctl_msgbuf(SYSCTLFN_PROTO);
static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
static int sysctl_kern_cptime(SYSCTLFN_PROTO);
-#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
-static int sysctl_kern_sysvipc(SYSCTLFN_PROTO);
-#endif /* defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM) */
#if NPTY > 0
static int sysctl_kern_maxptys(SYSCTLFN_PROTO);
#endif /* NPTY > 0 */
@@ -482,6 +466,12 @@
NULL, 1, NULL, 0,
CTL_KERN, KERN_FSYNC, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "ipc",
+ SYSCTL_DESCR("SysV IPC options"),
+ NULL, 0, NULL, 0,
+ CTL_KERN, KERN_SYSVIPC, CTL_EOL);
+ sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
CTLTYPE_INT, "sysvmsg",
SYSCTL_DESCR("System V style message support available"),
@@ -491,29 +481,29 @@
#else /* SYSVMSG */
0,
#endif /* SYSVMSG */
- NULL, 0, CTL_KERN, KERN_SYSVMSG, CTL_EOL);
+ NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_MSG, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
CTLTYPE_INT, "sysvsem",
SYSCTL_DESCR("System V style semaphore support "
- "available"), NULL,
+ "available"), NULL,
#ifdef SYSVSEM
1,
#else /* SYSVSEM */
0,
#endif /* SYSVSEM */
- NULL, 0, CTL_KERN, KERN_SYSVSEM, CTL_EOL);
+ NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SEM, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
CTLTYPE_INT, "sysvshm",
SYSCTL_DESCR("System V style shared memory support "
- "available"), NULL,
+ "available"), NULL,
#ifdef SYSVSHM
1,
#else /* SYSVSHM */
0,
#endif /* SYSVSHM */
- NULL, 0, CTL_KERN, KERN_SYSVSHM, CTL_EOL);
+ NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHM, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
CTLTYPE_INT, "synchronized_io",
@@ -595,14 +585,6 @@
SYSCTL_DESCR("Clock ticks spent in different CPU states"),
sysctl_kern_cptime, 0, NULL, 0,
CTL_KERN, KERN_CP_TIME, CTL_EOL);
-#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
- sysctl_createv(clog, 0, NULL, NULL,
- CTLFLAG_PERMANENT,
- CTLTYPE_STRUCT, "sysvipc_info",
- SYSCTL_DESCR("System V style IPC information"),
- sysctl_kern_sysvipc, 0, NULL, 0,
- CTL_KERN, KERN_SYSVIPC_INFO, CTL_EOL);
-#endif /* SYSVMSG || SYSVSEM || SYSVSHM */
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_INT, "msgbuf",
@@ -1576,194 +1558,6 @@
#endif /* MULTIPROCESSOR */
}
=20
-#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
-/*
- * sysctl helper routine for kern.sysvipc_info subtree.
- */
-
-#define FILL_PERM(src, dst) do { \
- (dst)._key =3D (src)._key; \
- (dst).uid =3D (src).uid; \
- (dst).gid =3D (src).gid; \
- (dst).cuid =3D (src).cuid; \
- (dst).cgid =3D (src).cgid; \
- (dst).mode =3D (src).mode; \
- (dst)._seq =3D (src)._seq; \
-} while (/*CONSTCOND*/ 0);
-#define FILL_MSG(src, dst) do { \
- FILL_PERM((src).msg_perm, (dst).msg_perm); \
- (dst).msg_qnum =3D (src).msg_qnum; \
- (dst).msg_qbytes =3D (src).msg_qbytes; \
- (dst)._msg_cbytes =3D (src)._msg_cbytes; \
- (dst).msg_lspid =3D (src).msg_lspid; \
- (dst).msg_lrpid =3D (src).msg_lrpid; \
- (dst).msg_stime =3D (src).msg_stime; \
- (dst).msg_rtime =3D (src).msg_rtime; \
- (dst).msg_ctime =3D (src).msg_ctime; \
-} while (/*CONSTCOND*/ 0)
-#define FILL_SEM(src, dst) do { \
- FILL_PERM((src).sem_perm, (dst).sem_perm); \
- (dst).sem_nsems =3D (src).sem_nsems; \
- (dst).sem_otime =3D (src).sem_otime; \
- (dst).sem_ctime =3D (src).sem_ctime; \
-} while (/*CONSTCOND*/ 0)
-#define FILL_SHM(src, dst) do { \
- FILL_PERM((src).shm_perm, (dst).shm_perm); \
- (dst).shm_segsz =3D (src).shm_segsz; \
- (dst).shm_lpid =3D (src).shm_lpid; \
- (dst).shm_cpid =3D (src).shm_cpid; \
- (dst).shm_atime =3D (src).shm_atime; \
- (dst).shm_dtime =3D (src).shm_dtime; \
- (dst).shm_ctime =3D (src).shm_ctime; \
- (dst).shm_nattch =3D (src).shm_nattch; \
-} while (/*CONSTCOND*/ 0)
-
-static int
-sysctl_kern_sysvipc(SYSCTLFN_ARGS)
-{
- void *where =3D oldp;
- size_t *sizep =3D oldlenp;
-#ifdef SYSVMSG
- struct msg_sysctl_info *msgsi =3D NULL;
-#endif
-#ifdef SYSVSEM
- struct sem_sysctl_info *semsi =3D NULL;
-#endif
-#ifdef SYSVSHM
- struct shm_sysctl_info *shmsi =3D NULL;
-#endif
- size_t infosize, dssize, tsize, buflen;
- void *bf =3D NULL;
- char *start;
- int32_t nds;
- int i, error, ret;
-
- if (namelen !=3D 1)
- return (EINVAL);
-
- start =3D where;
- buflen =3D *sizep;
-
- switch (*name) {
- case KERN_SYSVIPC_MSG_INFO:
-#ifdef SYSVMSG
- infosize =3D sizeof(msgsi->msginfo);
- nds =3D msginfo.msgmni;
- dssize =3D sizeof(msgsi->msgids[0]);
- break;
-#else
- return (EINVAL);
-#endif
- case KERN_SYSVIPC_SEM_INFO:
-#ifdef SYSVSEM
- infosize =3D sizeof(semsi->seminfo);
- nds =3D seminfo.semmni;
- dssize =3D sizeof(semsi->semids[0]);
- break;
-#else
- return (EINVAL);
-#endif
- case KERN_SYSVIPC_SHM_INFO:
-#ifdef SYSVSHM
- infosize =3D sizeof(shmsi->shminfo);
- nds =3D shminfo.shmmni;
- dssize =3D sizeof(shmsi->shmids[0]);
- break;
-#else
- return (EINVAL);
-#endif
- default:
- return (EINVAL);
- }
- /*
- * Round infosize to 64 bit boundary if requesting more than just
- * the info structure or getting the total data size.
- */
- if (where =3D=3D NULL || *sizep > infosize)
- infosize =3D ((infosize + 7) / 8) * 8;
- tsize =3D infosize + nds * dssize;
-
- /* Return just the total size required. */
- if (where =3D=3D NULL) {
- *sizep =3D tsize;
- return (0);
- }
-
- /* Not enough room for even the info struct. */
- if (buflen < infosize) {
- *sizep =3D 0;
- return (ENOMEM);
- }
- bf =3D malloc(min(tsize, buflen), M_TEMP, M_WAITOK);
- memset(bf, 0, min(tsize, buflen));
-
- switch (*name) {
-#ifdef SYSVMSG
- case KERN_SYSVIPC_MSG_INFO:
- msgsi =3D (struct msg_sysctl_info *)bf;
- msgsi->msginfo =3D msginfo;
- break;
-#endif
-#ifdef SYSVSEM
- case KERN_SYSVIPC_SEM_INFO:
- semsi =3D (struct sem_sysctl_info *)bf;
- semsi->seminfo =3D seminfo;
- break;
-#endif
-#ifdef SYSVSHM
- case KERN_SYSVIPC_SHM_INFO:
- shmsi =3D (struct shm_sysctl_info *)bf;
- shmsi->shminfo =3D shminfo;
- break;
-#endif
- }
- buflen -=3D infosize;
-
- ret =3D 0;
- if (buflen > 0) {
- /* Fill in the IPC data structures. */
- for (i =3D 0; i < nds; i++) {
- if (buflen < dssize) {
- ret =3D ENOMEM;
- break;
- }
- switch (*name) {
-#ifdef SYSVMSG
- case KERN_SYSVIPC_MSG_INFO:
- FILL_MSG(msqids[i], msgsi->msgids[i]);
- break;
-#endif
-#ifdef SYSVSEM
- case KERN_SYSVIPC_SEM_INFO:
- FILL_SEM(sema[i], semsi->semids[i]);
- break;
-#endif
-#ifdef SYSVSHM
- case KERN_SYSVIPC_SHM_INFO:
- FILL_SHM(shmsegs[i], shmsi->shmids[i]);
- break;
-#endif
- }
- buflen -=3D dssize;
- }
- }
- *sizep -=3D buflen;
- error =3D copyout(bf, start, *sizep);
- /* If copyout succeeded, use return code set earlier. */
- if (error =3D=3D 0)
- error =3D ret;
- if (bf)
- free(bf, M_TEMP);
- return (error);
-}
-
-#undef FILL_PERM
-#undef FILL_MSG
-#undef FILL_SEM
-#undef FILL_SHM
-
-#endif /* defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM) */
-
#if NPTY > 0
/*
* sysctl helper routine for kern.maxptys. ensures that any new value
Index: sys/kern/sysv_ipc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/sys/kern/sysv_ipc.c,v
retrieving revision 1.17
diff -u -r1.17 sysv_ipc.c
--- sys/kern/sysv_ipc.c 14 May 2006 21:15:11 -0000 1.17
+++ sys/kern/sysv_ipc.c 14 Oct 2006 00:05:44 -0000
@@ -39,11 +39,24 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysv_ipc.c,v 1.17 2006/05/14 21:15:11 elad Exp=
$");
=20
+#include "opt_sysv.h"
+
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/ipc.h>
+#ifdef SYSVMSG
+#include <sys/msg.h>
+#endif
+#ifdef SYSVSEM
+#include <sys/sem.h>
+#endif
+#ifdef SYSVSHM
+#include <sys/shm.h>
+#endif
+#include <sys/sysctl.h>
#include <sys/systm.h>
+#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/vnode.h>
#include <sys/stat.h>
@@ -97,3 +110,212 @@
mask |=3D S_IWOTH;
return ((perm->mode & mask) =3D=3D mask ? 0 : EACCES);
}
+
+/*
+ * sysctl helper routine for kern.ipc.sysvipc_info subtree.
+ */
+
+#define FILL_PERM(src, dst) do { \
+ (dst)._key =3D (src)._key; \
+ (dst).uid =3D (src).uid; \
+ (dst).gid =3D (src).gid; \
+ (dst).cuid =3D (src).cuid; \
+ (dst).cgid =3D (src).cgid; \
+ (dst).mode =3D (src).mode; \
+ (dst)._seq =3D (src)._seq; \
+} while (/*CONSTCOND*/ 0);
+#define FILL_MSG(src, dst) do { \
+FILL_PERM((src).msg_perm, (dst).msg_perm); \
+ (dst).msg_qnum =3D (src).msg_qnum; \
+ (dst).msg_qbytes =3D (src).msg_qbytes; \
+ (dst)._msg_cbytes =3D (src)._msg_cbytes; \
+ (dst).msg_lspid =3D (src).msg_lspid; \
+ (dst).msg_lrpid =3D (src).msg_lrpid; \
+ (dst).msg_stime =3D (src).msg_stime; \
+ (dst).msg_rtime =3D (src).msg_rtime; \
+ (dst).msg_ctime =3D (src).msg_ctime; \
+} while (/*CONSTCOND*/ 0)
+#define FILL_SEM(src, dst) do { \
+ FILL_PERM((src).sem_perm, (dst).sem_perm); \
+ (dst).sem_nsems =3D (src).sem_nsems; \
+ (dst).sem_otime =3D (src).sem_otime; \
+ (dst).sem_ctime =3D (src).sem_ctime; \
+} while (/*CONSTCOND*/ 0)
+#define FILL_SHM(src, dst) do { \
+ FILL_PERM((src).shm_perm, (dst).shm_perm); \
+ (dst).shm_segsz =3D (src).shm_segsz; \
+ (dst).shm_lpid =3D (src).shm_lpid; \
+ (dst).shm_cpid =3D (src).shm_cpid; \
+ (dst).shm_atime =3D (src).shm_atime; \
+ (dst).shm_dtime =3D (src).shm_dtime; \
+ (dst).shm_ctime =3D (src).shm_ctime; \
+ (dst).shm_nattch =3D (src).shm_nattch; \
+} while (/*CONSTCOND*/ 0)
+
+static int
+sysctl_kern_sysvipc(SYSCTLFN_ARGS)
+{
+ void *where =3D oldp;
+ size_t *sizep =3D oldlenp;
+#ifdef SYSVMSG
+ struct msg_sysctl_info *msgsi =3D NULL;
+#endif
+#ifdef SYSVSEM
+ struct sem_sysctl_info *semsi =3D NULL;
+#endif
+#ifdef SYSVSHM
+ struct shm_sysctl_info *shmsi =3D NULL;
+#endif
+ size_t infosize, dssize, tsize, buflen;
+ void *bf =3D NULL;
+ char *start;
+ int32_t nds;
+ int i, error, ret;
+
+ if (namelen !=3D 1)
+ return (EINVAL);
+
+ start =3D where;
+ buflen =3D *sizep;
+
+ switch (*name) {
+ case KERN_SYSVIPC_MSG_INFO:
+#ifdef SYSVMSG
+ infosize =3D sizeof(msgsi->msginfo);
+ nds =3D msginfo.msgmni;
+ dssize =3D sizeof(msgsi->msgids[0]);
+ break;
+#else
+ return (EINVAL);
+#endif
+ case KERN_SYSVIPC_SEM_INFO:
+#ifdef SYSVSEM
+ infosize =3D sizeof(semsi->seminfo);
+ nds =3D seminfo.semmni;
+ dssize =3D sizeof(semsi->semids[0]);
+ break;
+#else
+ return (EINVAL);
+#endif
+ case KERN_SYSVIPC_SHM_INFO:
+#ifdef SYSVSHM
+ infosize =3D sizeof(shmsi->shminfo);
+ nds =3D shminfo.shmmni;
+ dssize =3D sizeof(shmsi->shmids[0]);
+ break;
+#else
+ return (EINVAL);
+#endif
+ default:
+ return (EINVAL);
+ }
+ /*
+ * Round infosize to 64 bit boundary if requesting more than just
+ * the info structure or getting the total data size.
+ */
+ if (where =3D=3D NULL || *sizep > infosize)
+ infosize =3D ((infosize + 7) / 8) * 8;
+ tsize =3D infosize + nds * dssize;
+
+ /* Return just the total size required. */
+ if (where =3D=3D NULL) {
+ *sizep =3D tsize;
+ return (0);
+ }
+
+ /* Not enough room for even the info struct. */
+ if (buflen < infosize) {
+ *sizep =3D 0;
+ return (ENOMEM);
+ }
+ bf =3D malloc(min(tsize, buflen), M_TEMP, M_WAITOK);
+ memset(bf, 0, min(tsize, buflen));
+
+ switch (*name) {
+#ifdef SYSVMSG
+ case KERN_SYSVIPC_MSG_INFO:
+ msgsi =3D (struct msg_sysctl_info *)bf;
+ msgsi->msginfo =3D msginfo;
+ break;
+#endif
+#ifdef SYSVSEM
+ case KERN_SYSVIPC_SEM_INFO:
+ semsi =3D (struct sem_sysctl_info *)bf;
+ semsi->seminfo =3D seminfo;
+ break;
+#endif
+#ifdef SYSVSHM
+ case KERN_SYSVIPC_SHM_INFO:
+ shmsi =3D (struct shm_sysctl_info *)bf;
+ shmsi->shminfo =3D shminfo;
+ break;
+#endif
+ }
+ buflen -=3D infosize;
+
+ ret =3D 0;
+ if (buflen > 0) {
+ /* Fill in the IPC data structures. */
+ for (i =3D 0; i < nds; i++) {
+ if (buflen < dssize) {
+ ret =3D ENOMEM;
+ break;
+ }
+ switch (*name) {
+#ifdef SYSVMSG
+ case KERN_SYSVIPC_MSG_INFO:
+ FILL_MSG(msqids[i], msgsi->msgids[i]);
+ break;
+#endif
+#ifdef SYSVSEM
+ case KERN_SYSVIPC_SEM_INFO:
+ FILL_SEM(sema[i], semsi->semids[i]);
+ break;
+#endif
+#ifdef SYSVSHM
+ case KERN_SYSVIPC_SHM_INFO:
+ FILL_SHM(shmsegs[i], shmsi->shmids[i]);
+ break;
+#endif
+ }
+ buflen -=3D dssize;
+ }
+ }
+ *sizep -=3D buflen;
+ error =3D copyout(bf, start, *sizep);
+ /* If copyout succeeded, use return code set earlier. */
+ if (error =3D=3D 0)
+ error =3D ret;
+ if (bf)
+ free(bf, M_TEMP);
+ return (error);
+}
+
+#undef FILL_PERM
+#undef FILL_MSG
+#undef FILL_SEM
+#undef FILL_SHM
+
+SYSCTL_SETUP(sysctl_ipc_setup, "sysctl kern.ipc subtree setup")
+{
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "kern", NULL,
+ NULL, 0, NULL, 0,
+ CTL_KERN, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "ipc",
+ SYSCTL_DESCR("SysV IPC options"),
+ NULL, 0, NULL, 0,
+ CTL_KERN, KERN_SYSVIPC, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_STRUCT, "sysvipc_info",
+ SYSCTL_DESCR("System V style IPC information"),
+ sysctl_kern_sysvipc, 0, NULL, 0,
+ CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_INFO, CTL_EOL);
+}
+
Index: sys/kern/sysv_shm.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/sys/kern/sysv_shm.c,v
retrieving revision 1.89
diff -u -r1.89 sysv_shm.c
--- sys/kern/sysv_shm.c 23 Jul 2006 22:06:11 -0000 1.89
+++ sys/kern/sysv_shm.c 14 Oct 2006 00:05:44 -0000
@@ -75,6 +75,7 @@
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/shm.h>
+#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -112,7 +113,9 @@
int shmid;
};
=20
-static int shm_last_free, shm_committed;
+struct simplelock shm_slock;
+
+static int shm_last_free, shm_committed, shm_use_phys =3D 0;
=20
static POOL_INIT(shmmap_entry_pool, sizeof(struct shmmap_entry), 0, 0, 0,
"shmmp", &pool_allocator_nointr);
@@ -353,10 +356,21 @@
error =3D uvm_map(&p->p_vmspace->vm_map, &attach_va, size,
uobj, 0, 0,
UVM_MAPFLAG(prot, prot, UVM_INH_SHARE, UVM_ADV_RANDOM, 0));
- if (error) {
- (*uobj->pgops->pgo_detach)(uobj);
- return error;
+ if (error)
+ goto error;
+
+ /* Lock the memory */
+ if (shm_use_phys || (shmseg->shm_perm.mode & SHMSEG_WIRED)) {
+ /* Wire the map */
+ error =3D uvm_map_pageable(&p->p_vmspace->vm_map, attach_va,
+ attach_va + size, FALSE, 0);
+ if (error) {
+ if (error =3D=3D EFAULT)
+ error =3D ENOMEM;
+ goto error;
+ }
}
+
shmmap_se =3D pool_get(&shmmap_entry_pool, PR_WAITOK);
shmmap_se->va =3D attach_va;
shmmap_se->shmid =3D SCARG(uap, shmid);
@@ -372,6 +386,10 @@
=20
retval[0] =3D attach_va;
return 0;
+
+error:
+ (*uobj->pgops->pgo_detach)(uobj);
+ return error;
}
=20
int
@@ -406,12 +424,17 @@
shmctl1(struct lwp *l, int shmid, int cmd, struct shmid_ds *shmbuf)
{
kauth_cred_t cred =3D l->l_cred;
+ struct proc *p =3D l->l_proc;
struct shmid_ds *shmseg;
+ struct shmmap_entry *shmmap_se;
+ struct shmmap_state *shmmap_s;
int error =3D 0;
+ size_t size;
=20
shmseg =3D shm_find_segment_by_shmid(shmid);
if (shmseg =3D=3D NULL)
return EINVAL;
+
switch (cmd) {
case IPC_STAT:
if ((error =3D ipcperm(cred, &shmseg->shm_perm, IPC_R)) !=3D 0)
@@ -440,6 +463,53 @@
break;
case SHM_LOCK:
case SHM_UNLOCK:
+ if ((error =3D kauth_authorize_generic(cred, KAUTH_GENERIC_ISSUSER, NULL=
)) !=3D 0)
+ return error;
+ shmmap_s =3D shmmap_getprivate(p);
+ /* Find our shared memory address by shmid */
+ SLIST_FOREACH(shmmap_se, &shmmap_s->entries, next) {
+ if (shmmap_se->shmid !=3D shmid)
+ continue;
+
+ size =3D (shmseg->shm_segsz + PGOFSET) & ~PGOFSET;
+
+ if (cmd =3D=3D SHM_LOCK && !(shmseg->shm_perm.mode & SHMSEG_WIRED)) {
+ /* Wire the entire object */
+ error =3D uobj_wirepages(shmseg->_shm_internal, 0,
+ round_page(shmseg->shm_segsz));
+ if (error)
+ return EIO;
+ /* Wire the map */
+ error =3D uvm_map_pageable(&p->p_vmspace->vm_map,
+ shmmap_se->va, shmmap_se->va + size, FALSE, 0);
+ if (error) {
+ uobj_unwirepages(shmseg->_shm_internal, 0,
+ round_page(shmseg->shm_segsz));
+ if (error =3D=3D EFAULT)
+ error =3D ENOMEM;
+ return error;
+ }
+ /* Tag as wired */
+ shmseg->shm_perm.mode |=3D SHMSEG_WIRED;
+
+ } else if (cmd =3D=3D SHM_UNLOCK && (shmseg->shm_perm.mode & SHMSEG_WIR=
ED)) {
+ /* Unwire the object */
+ uobj_unwirepages(shmseg->_shm_internal, 0,
+ round_page(shmseg->shm_segsz));
+ error =3D uvm_map_pageable(&p->p_vmspace->vm_map,
+ shmmap_se->va, shmmap_se->va + size, TRUE, 0);
+ if (error) {
+ /*
+ * In fact, uvm_map_pageable could fail only if arguments
+ * is invalid, otherwise it should allways return 0.
+ */
+ return EIO;
+ }
+ /* Tag as unwired */
+ shmseg->shm_perm.mode &=3D ~SHMSEG_WIRED;
+ }
+ }
+ break;
default:
return EINVAL;
}
@@ -539,6 +609,20 @@
shmseg->shm_perm.mode &=3D ~SHMSEG_WANTED;
wakeup((caddr_t)shmseg);
}
+
+ /* Lock the memory */
+ if (shm_use_phys) {
+ /* Wire the entire object */
+ error =3D uobj_wirepages(shmseg->_shm_internal, 0,
+ round_page(shmseg->shm_segsz));
+ if (error) {
+ shm_deallocate_segment(shmseg);
+ } else {
+ /* Tag as wired */
+ shmseg->shm_perm.mode |=3D SHMSEG_WIRED;
+ }
+ }
+
return error;
}
=20
@@ -631,12 +715,54 @@
free(shmmap_s, M_SHM);
}
=20
+int
+shmrealloc(int newshmni)
+{
+ int i, sz;
+ vaddr_t v;
+ struct shmid_ds *newshmsegs;
+
+ /* XXX: Would be good to have a upper limit */
+ if (newshmni < 1)
+ return (EINVAL);
+
+ /* We can't reallocate lesser memory than we use */
+ if (shm_nused > newshmni)
+ return (EPERM);
+
+ /* Allocate new memory area */
+ sz =3D newshmni * sizeof(struct shmid_ds);
+ v =3D uvm_km_alloc(kernel_map, round_page(sz), 0, UVM_KMF_WIRED);
+ if (v =3D=3D 0)
+ return (ENOMEM);
+
+ newshmsegs =3D (void *)v;
+
+ /* Copy all memory to the new area */
+ for (i =3D 0; i < shm_nused; i++)
+ memcpy(&newshmsegs[i], &shmsegs[i], sizeof(newshmsegs[0]));
+
+ /* Mark as free all new segments, if there is any */
+ for (; i < newshmni; i++) {
+ newshmsegs[i].shm_perm.mode =3D SHMSEG_FREE;
+ newshmsegs[i].shm_perm._seq =3D 0;
+ }
+
+ sz =3D shminfo.shmmni * sizeof(struct shmid_ds);
+ uvm_km_free(kernel_map, (vaddr_t)shmsegs, sz, UVM_KMF_WIRED);
+ shmsegs =3D newshmsegs;
+
+ return 0;
+}
+
void
shminit(void)
{
int i, sz;
vaddr_t v;
=20
+ simple_lock_init(&shm_slock);
+
/* Allocate pageable memory for our structures */
sz =3D shminfo.shmmni * sizeof(struct shmid_ds);
v =3D uvm_km_alloc(kernel_map, round_page(sz), 0, UVM_KMF_WIRED);
@@ -654,3 +780,99 @@
shm_nused =3D 0;
shm_committed =3D 0;
}
+
+static int
+sysctl_ipc_shmmni(SYSCTLFN_ARGS)
+{
+ int newsize, error;
+ struct sysctlnode node;
+ node =3D *rnode;
+ node.sysctl_data =3D &newsize;
+
+ newsize =3D shminfo.shmmni;
+ error =3D sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp =3D=3D NULL)
+ return (error);
+
+ simple_lock(&shm_slock);
+ error =3D shmrealloc(newsize);
+ if (error =3D=3D 0)
+ shminfo.shmmni =3D newsize;
+ simple_unlock(&shm_slock);
+
+ return (error);
+}
+
+static int
+sysctl_ipc_shmmaxpgs(SYSCTLFN_ARGS)
+{
+ int newsize, error;
+ struct sysctlnode node;
+ node =3D *rnode;
+ node.sysctl_data =3D &newsize;
+ newsize =3D shminfo.shmall;
+ error =3D sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp =3D=3D NULL)
+ return (error);
+
+ /* XXX: Would be good to have a upper limit */
+ if (newsize < 1)
+ return (EINVAL);
+
+ shminfo.shmall =3D newsize;
+ shminfo.shmmax =3D shminfo.shmall * PAGE_SIZE;
+
+ return 0;
+}
+
+SYSCTL_SETUP(sysctl_ipc_shm_setup, "sysctl kern.ipc subtree setup")
+{
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "kern", NULL,
+ NULL, 0, NULL, 0,
+ CTL_KERN, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "ipc",
+ SYSCTL_DESCR("SysV IPC options"),
+ NULL, 0, NULL, 0,
+ CTL_KERN, KERN_SYSVIPC, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT | CTLFLAG_READONLY,
+ CTLTYPE_INT, "shmmax",
+ SYSCTL_DESCR("Max shared memory segment size in bytes"),
+ NULL, 0, &shminfo.shmmax, 0,
+ CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHMMAX, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "shmmni",
+ SYSCTL_DESCR("Max number of shared memory identifiers"),
+ sysctl_ipc_shmmni, 0, &shminfo.shmmni, 0,
+ CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHMMNI, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "shmseg",
+ SYSCTL_DESCR("Max shared memory segments per process"),
+ NULL, 0, &shminfo.shmseg, 0,
+ CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHMSEG, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "shmmaxpgs",
+ SYSCTL_DESCR("Max amount of shared memory in pages"),
+ sysctl_ipc_shmmaxpgs, 0, &shminfo.shmall, 0,
+ CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHMMAXPGS, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "shm_use_phys",
+ SYSCTL_DESCR("Enable/disable locking of shared memory in physical memory=
"),
+ NULL, 0, &shm_use_phys, 0,
+ CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHMUSEPHYS, CTL_EOL);
+}
+
Index: sys/sys/shm.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/sys/sys/shm.h,v
retrieving revision 1.41
diff -u -r1.41 shm.h
--- sys/sys/shm.h 23 Jul 2006 22:06:14 -0000 1.41
+++ sys/sys/shm.h 14 Oct 2006 00:05:46 -0000
@@ -123,7 +123,6 @@
#if defined(_NETBSD_SOURCE)
/*
* Some systems (e.g. HP-UX) take these as the second (cmd) arg to shmctl(=
).
- * XXX Currently not implemented.
*/
#define SHM_LOCK 3 /* Lock segment in memory. */
#define SHM_UNLOCK 4 /* Unlock a segment locked by SHM_LOCK. */
@@ -177,10 +176,12 @@
#define SHMSEG_ALLOCATED 0x0800
#define SHMSEG_WANTED 0x1000
#define SHMSEG_RMLINGER 0x2000
+#define SHMSEG_WIRED 0x4000
=20
struct vmspace;
=20
void shminit(void);
+int shmrealloc(int);
void shmfork(struct vmspace *, struct vmspace *);
void shmexit(struct vmspace *);
int shmctl1(struct lwp *, int, int, struct shmid_ds *);
Index: sys/sys/sysctl.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/sys/sys/sysctl.h,v
retrieving revision 1.155
diff -u -r1.155 sysctl.h
--- sys/sys/sysctl.h 30 Jul 2006 17:38:19 -0000 1.155
+++ sys/sys/sysctl.h 14 Oct 2006 00:05:46 -0000
@@ -222,9 +222,7 @@
#define KERN_ROOT_DEVICE 30 /* string: root device */
#define KERN_MSGBUFSIZE 31 /* int: max # of chars in msg buffer */
#define KERN_FSYNC 32 /* int: file synchronization support */
-#define KERN_SYSVMSG 33 /* int: SysV message queue suppoprt */
-#define KERN_SYSVSEM 34 /* int: SysV semaphore support */
-#define KERN_SYSVSHM 35 /* int: SysV shared memory support */
+/* XXX: 33, 34, 35 unused */
#define KERN_OLDSHORTCORENAME 36 /* old, unimplemented */
#define KERN_SYNCHRONIZED_IO 37 /* int: POSIX synchronized I/O */
#define KERN_IOV_MAX 38 /* int: max iovec's for readv(2) etc. */
@@ -241,7 +239,7 @@
#define KERN_FSCALE 49 /* int: fixpt FSCALE */
#define KERN_CCPU 50 /* int: fixpt ccpu */
#define KERN_CP_TIME 51 /* struct: CPU time counters */
-#define KERN_SYSVIPC_INFO 52 /* number of valid kern ids */
+#define KERN_SYSVIPC 52 /* node: SysV IPC parameters */
#define KERN_MSGBUF 53 /* kernel message buffer */
#define KERN_CONSDEV 54 /* dev_t: console terminal device */
#define KERN_MAXPTYS 55 /* int: maximum number of ptys */
@@ -275,7 +273,6 @@
#define KERN_HARDCLOCK_TICKS 80 /* int: number of hardclock ticks */
#define KERN_MAXID 81 /* number of valid kern ids */
=20
-
#define CTL_KERN_NAMES { \
{ 0, 0 }, \
{ "ostype", CTLTYPE_STRING }, \
@@ -596,6 +593,19 @@
#define KERN_PROC_NENV 4 /* number of strings in above */
=20
/*
+ * KERN_SYSVIPC subtypes
+ */
+#define KERN_SYSVIPC_INFO 1 /* struct: number of valid kern ids */
+#define KERN_SYSVIPC_MSG 2 /* int: SysV message queue suppoprt */
+#define KERN_SYSVIPC_SEM 3 /* int: SysV semaphore support */
+#define KERN_SYSVIPC_SHM 4 /* int: SysV shared memory support */
+#define KERN_SYSVIPC_SHMMAX 5 /* int: max shared memory segment size (byt=
es) */
+#define KERN_SYSVIPC_SHMMNI 6 /* int: max number of shared memory identif=
iers */
+#define KERN_SYSVIPC_SHMSEG 7 /* int: max shared memory segments per proc=
ess */
+#define KERN_SYSVIPC_SHMMAXPGS 8 /* int: max amount of shared memory (pag=
es) */
+#define KERN_SYSVIPC_SHMUSEPHYS 9 /* int: physical memory usage */
+
+/*
* KERN_SYSVIPC_INFO subtypes
*/
#define KERN_SYSVIPC_MSG_INFO 1 /* msginfo and msqid_ds */
Index: usr.bin/ipcs/ipcs.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/usr.bin/ipcs/ipcs.c,v
retrieving revision 1.35
diff -u -r1.35 ipcs.c
--- usr.bin/ipcs/ipcs.c 28 Apr 2006 20:35:15 -0000 1.35
+++ usr.bin/ipcs/ipcs.c 14 Oct 2006 00:05:49 -0000
@@ -470,15 +470,16 @@
{
struct msg_sysctl_info *msgsi;
void *buf;
- int mib[3];
+ int mib[4];
size_t len;
int i, valid;
=20
mib[0] =3D CTL_KERN;
- mib[1] =3D KERN_SYSVMSG;
+ mib[1] =3D KERN_SYSVIPC;
+ mib[2] =3D KERN_SYSVIPC_MSG;
len =3D sizeof(valid);
- if (sysctl(mib, 2, &valid, &len, NULL, 0) < 0) {
- warn("sysctl(KERN_SYSVMSG)");
+ if (sysctl(mib, 3, &valid, &len, NULL, 0) < 0) {
+ warn("sysctl(KERN_SYSVIPC_MSG)");
return;
}
if (!valid) {
@@ -487,14 +488,15 @@
}
=20
mib[0] =3D CTL_KERN;
- mib[1] =3D KERN_SYSVIPC_INFO;
- mib[2] =3D KERN_SYSVIPC_MSG_INFO;
+ mib[1] =3D KERN_SYSVIPC;
+ mib[2] =3D KERN_SYSVIPC_INFO;
+ mib[3] =3D KERN_SYSVIPC_MSG_INFO;
=20
if (!(display & MSGINFO)) {
/* totals only */
len =3D sizeof(struct msginfo);
} else {
- if (sysctl(mib, 3, NULL, &len, NULL, 0) < 0) {
+ if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0) {
warn("sysctl(KERN_SYSVIPC_MSG_INFO)");
return;
}
@@ -503,7 +505,7 @@
if ((buf =3D malloc(len)) =3D=3D NULL)
err(1, "malloc");
msgsi =3D (struct msg_sysctl_info *)buf;
- if (sysctl(mib, 3, msgsi, &len, NULL, 0) < 0) {
+ if (sysctl(mib, 4, msgsi, &len, NULL, 0) < 0) {
warn("sysctl(KERN_SYSVIPC_MSG_INFO)");
goto done;
}
@@ -543,16 +545,17 @@
{
struct shm_sysctl_info *shmsi;
void *buf;
- int mib[3];
+ int mib[4];
size_t len;
int i /*, valid */;
long valid;
=20
mib[0] =3D CTL_KERN;
- mib[1] =3D KERN_SYSVSHM;
+ mib[1] =3D KERN_SYSVIPC;
+ mib[2] =3D KERN_SYSVIPC_SHM;
len =3D sizeof(valid);
- if (sysctl(mib, 2, &valid, &len, NULL, 0) < 0) {
- warn("sysctl(KERN_SYSVSHM)");
+ if (sysctl(mib, 3, &valid, &len, NULL, 0) < 0) {
+ warn("sysctl(KERN_SYSVIPC_SHM)");
return;
}
if (!valid) {
@@ -561,14 +564,15 @@
}
=20
mib[0] =3D CTL_KERN;
- mib[1] =3D KERN_SYSVIPC_INFO;
- mib[2] =3D KERN_SYSVIPC_SHM_INFO;
+ mib[1] =3D KERN_SYSVIPC;
+ mib[2] =3D KERN_SYSVIPC_INFO;
+ mib[3] =3D KERN_SYSVIPC_SHM_INFO;
=20
if (!(display & SHMINFO)) {
/* totals only */
len =3D sizeof(struct shminfo);
} else {
- if (sysctl(mib, 3, NULL, &len, NULL, 0) < 0) {
+ if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0) {
warn("sysctl(KERN_SYSVIPC_SHM_INFO)");
return;
}
@@ -577,7 +581,7 @@
if ((buf =3D malloc(len)) =3D=3D NULL)
err(1, "malloc");
shmsi =3D (struct shm_sysctl_info *)buf;
- if (sysctl(mib, 3, shmsi, &len, NULL, 0) < 0) {
+ if (sysctl(mib, 4, shmsi, &len, NULL, 0) < 0) {
warn("sysctl(KERN_SYSVIPC_SHM_INFO)");
goto done;
}
@@ -616,15 +620,16 @@
{
struct sem_sysctl_info *semsi;
void *buf;
- int mib[3];
+ int mib[4];
size_t len;
int i, valid;
=20
mib[0] =3D CTL_KERN;
- mib[1] =3D KERN_SYSVSEM;
+ mib[1] =3D KERN_SYSVIPC;
+ mib[2] =3D KERN_SYSVIPC_SEM;
len =3D sizeof(valid);
- if (sysctl(mib, 2, &valid, &len, NULL, 0) < 0) {
- warn("sysctl(KERN_SYSVSEM)");
+ if (sysctl(mib, 3, &valid, &len, NULL, 0) < 0) {
+ warn("sysctl(KERN_SYSVIPC_SEM)");
return;
}
if (!valid) {
@@ -633,14 +638,15 @@
}
=20
mib[0] =3D CTL_KERN;
- mib[1] =3D KERN_SYSVIPC_INFO;
- mib[2] =3D KERN_SYSVIPC_SEM_INFO;
+ mib[1] =3D KERN_SYSVIPC;
+ mib[2] =3D KERN_SYSVIPC_INFO;
+ mib[3] =3D KERN_SYSVIPC_SEM_INFO;
=20
if (!(display & SEMINFO)) {
/* totals only */
len =3D sizeof(struct seminfo);
} else {
- if (sysctl(mib, 3, NULL, &len, NULL, 0) < 0) {
+ if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0) {
warn("sysctl(KERN_SYSVIPC_SEM_INFO)");
return;
}
@@ -649,7 +655,7 @@
if ((buf =3D malloc(len)) =3D=3D NULL)
err(1, "malloc");
semsi =3D (struct sem_sysctl_info *)buf;
- if (sysctl(mib, 3, semsi, &len, NULL, 0) < 0) {
+ if (sysctl(mib, 4, semsi, &len, NULL, 0) < 0) {
warn("sysctl(KERN_SYSVIPC_SEM_INFO)");
goto done;
}
--Multipart=_Sat__14_Oct_2006_03_22_25_+0300_n5yR1KJPd6x3h=BM--