Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Aug 2001 01:08:59 +0200 (CEST)
From:      Michael Reifenberger <root@nihil.plaut.de>
To:        Julian Elischer <julian@elischer.org>
Cc:        FreeBSD-Current <current@FreeBSD.ORG>, <freebsd-emulation@FreeBSD.ORG>
Subject:   Re: Anyone working on missing sysv* ipc functionality
Message-ID:  <20010813004824.L1212-200000@nihil>
In-Reply-To: <3B76B032.1491F636@elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Sun, 12 Aug 2001, Julian Elischer wrote:
...
> my guess is that you are....
Lets see...
Attached is a first shot to get /compat/linux/usr/bin/ipcs -s working.
I extended sem.h for SEM_STAT and gave it a special handling
in  __semctl() to accept a index number.
Please review and commmit if acceptable.

BTW: In sysv_*.c the sysctls got extended to be tunables.
This left the question how (readonly)sysctl vars should get initialised in
modules.
FE: semmni is currently readonly and used on modload time to allocate a scruct.
Because the sysctl var doesn't exist before modload but is used during modload
there is no possibility to preset the value except on compile-time.
One sollution is to use tunables but can they be changed after startup?

BTW2: Is it possible that changing a sysctl(from userland) var calls a
kernel function (maybe for sanity checks)?
Or has the sysct to be of the type SYSCTL_PROC?

Bye!
----
Michael Reifenberger
^.*Plaut.*$, IT, R/3 Basis, GPS

[-- Attachment #2 --]
--- ./i386/linux/linux.h.orig	Wed Aug  8 00:09:28 2001
+++ ./i386/linux/linux.h	Mon Aug 13 00:41:50 2001
@@ -457,4 +457,6 @@
 #define	LINUX_SETVAL		16
 #define	LINUX_SETALL		17
+#define	LINUX_SEM_STAT		18
+#define	LINUX_SEM_INFO		19
 
 /*
--- ./kern/sysv_sem.c.orig	Sun Aug 12 13:18:34 2001
+++ ./kern/sysv_sem.c	Sun Aug 12 23:31:10 2001
@@ -171,4 +171,14 @@
 	register int i;
 
+	TUNABLE_INT_FETCH("kern.ipc.semmap", &seminfo.semmap);
+	TUNABLE_INT_FETCH("kern.ipc.semmni", &seminfo.semmni);
+	TUNABLE_INT_FETCH("kern.ipc.semmns", &seminfo.semmns);
+	TUNABLE_INT_FETCH("kern.ipc.semmnu", &seminfo.semmnu);
+	TUNABLE_INT_FETCH("kern.ipc.semmsl", &seminfo.semmsl);
+	TUNABLE_INT_FETCH("kern.ipc.semopm", &seminfo.semopm);
+	TUNABLE_INT_FETCH("kern.ipc.semume", &seminfo.semume);
+	TUNABLE_INT_FETCH("kern.ipc.semusz", &seminfo.semusz);
+	TUNABLE_INT_FETCH("kern.ipc.semvmx", &seminfo.semvmx);
+	TUNABLE_INT_FETCH("kern.ipc.semaem", &seminfo.semaem);
 	sem = malloc(sizeof(struct sem) * seminfo.semmns, M_SEM, M_WAITOK);
 	if (sem == NULL)
@@ -471,4 +481,21 @@
 		return (ENOSYS);
 
+	switch(cmd) {
+	case SEM_STAT:
+		if (semid < 0 || semid >= seminfo.semmsl)
+	 		return(EINVAL);
+		semaptr = &sema[semid];
+		if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 )
+			return(EINVAL);
+		if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
+			return(eval);
+		if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
+			return(eval);
+		eval = copyout((caddr_t)semaptr, real_arg.buf,
+		    sizeof(struct semid_ds));
+		rval = IXSEQ_TO_IPCID(semid,semaptr->sem_perm);
+		goto out;
+	}
+
 	semid = IPCID_TO_IX(semid);
 	if (semid < 0 || semid >= seminfo.semmsl)
@@ -602,4 +629,6 @@
 		return(EINVAL);
 	}
+	
+out:
 
 	if (eval == 0)
--- ./kern/sysv_shm.c.orig	Sun Aug 12 13:18:43 2001
+++ ./kern/sysv_shm.c	Sun Aug 12 21:11:36 2001
@@ -716,4 +716,10 @@
 	int i;
 
+TUNABLE_INT_FETCH("kern.ipc.shmmaxpgs", &shminfo.shmall);
+shminfo.shmmax = shminfo.shmall * PAGE_SIZE;
+TUNABLE_INT_FETCH("kern.ipc.shmmin", &shminfo.shmmin);
+TUNABLE_INT_FETCH("kern.ipc.shmmni", &shminfo.shmmni);
+TUNABLE_INT_FETCH("kern.ipc.shmseg", &shminfo.shmseg);
+TUNABLE_INT_FETCH("kern.ipc.shm_use_phys", &shm_use_phys);
 	shmalloced = shminfo.shmmni;
 	shmsegs = malloc(shmalloced * sizeof(shmsegs[0]), M_SHM, M_WAITOK);
--- ./sys/sem.h.orig	Sun Aug 12 23:17:32 2001
+++ ./sys/sem.h	Mon Aug 13 00:40:50 2001
@@ -59,4 +59,6 @@
 #define SETVAL	8	/* Set the value of semval to arg.val {ALTER} */
 #define SETALL	9	/* Set semvals from arg.array {ALTER} */
+#define SEM_STAT 10 /* Like IPC_STAT but treats semid as sema-index*/
+#define SEM_INFO 11 /* for future use */
 
 /*
--- ./compat/linux/linux_ipc.c.orig	Sat Aug  4 17:49:33 2001
+++ ./compat/linux/linux_ipc.c	Mon Aug 13 00:45:27 2001
@@ -41,4 +41,34 @@
 #include <compat/linux/linux_util.h>
 
+struct linux_seminfo {
+        int semmap;
+        int semmni;
+        int semmns;
+        int semmnu;
+        int semmsl;
+        int semopm;
+        int semume;
+        int semusz;
+        int semvmx;
+        int semaem;
+};
+
+struct linux_shminfo {
+        int shmmax;
+        int shmmin;
+        int shmmni;
+        int shmseg;
+        int shmall;
+};
+
+struct linux_shm_info {
+        int used_ids;
+        unsigned long shm_tot;  /* total allocated shm */
+        unsigned long shm_rss;  /* total resident shm */
+        unsigned long shm_swp;  /* total swapped shm */
+        unsigned long swap_attempts;
+        unsigned long swap_successes;
+};
+
 struct linux_ipc_perm {
     linux_key_t key;
@@ -183,4 +213,5 @@
 {
 	struct linux_semid_ds	linux_semid;
+	struct linux_seminfo linux_seminfo;
 	struct semid_ds	bsd_semid;
 	struct __semctl_args /* {
@@ -238,5 +269,9 @@
 		return __semctl(p, &bsd_args);
 	case LINUX_IPC_STAT:
-		bsd_args.cmd = IPC_STAT;
+	case LINUX_SEM_STAT:
+		if( args->arg3 == IPC_STAT )
+			bsd_args.cmd = IPC_STAT;
+		else
+			bsd_args.cmd = SEM_STAT;
 		unptr = stackgap_alloc(&sg, sizeof(union semun *));
 		dsp = stackgap_alloc(&sg, sizeof(struct semid_ds));
@@ -255,5 +290,24 @@
 		if (error)
 			return error;
+		p->p_retval[0] = IXSEQ_TO_IPCID(bsd_args.semid, bsd_semid.sem_perm);
 		return copyout((caddr_t)&linux_semid, ldsp, sizeof(linux_semid));
+	case LINUX_IPC_INFO:
+	case LINUX_SEM_INFO:
+		error = copyin(args->ptr, &ldsp, sizeof(ldsp));
+		if (error)
+			return error;
+		bcopy(&seminfo, &linux_seminfo, sizeof(linux_seminfo) );
+/* XXX 
+#define used_semids 10
+#define used_sems 10
+	        linux_seminfo.semusz = used_semids;
+   		    linux_seminfo.semaem = used_sems;
+		} */
+		error = copyout((caddr_t)&linux_seminfo, ldsp, 
+				sizeof(linux_seminfo) );
+		if (error)
+			return error;
+		p->p_retval[0] = seminfo.semmni;
+		return(0);
 	case LINUX_GETALL:
 		/* FALLTHROUGH */

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010813004824.L1212-200000>