Re: 64-bit shm: abi problems

Manfred Spraul (manfreds@colorfullife.com)
Tue, 14 Dec 1999 00:10:23 +0100


This is a multi-part message in MIME format.
--------------32A3DE49A63C01CEE8FC0683
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Linus Torvalds wrote:
>
> On 13 Dec 1999, Christoph Rohland wrote:
> >
> > On many platforms you probably do not need a new syscall. They use the
> > sys_ipc demultiplexer and you can simply add a new sys_ipc command.
>
> I'd rather get rid of the demultiplexer than make it more complex..
>
> Linus

What do you think about the attached patch?
* add normal syscalls for i386
* rename sys_shmget(,int size,) to sys_shmget64(,size_t size,). The
current sys_shmget() is only visible on Alpha, all other architectures
use the sys_ipc demultiplexer.
* add a new wrapper for Alpha

The other 64-bit architectures must be updated as well, eg for sparc64
only a cast must be removed.

i386 compiles and links, everything else is untested,

Manfred
--------------32A3DE49A63C01CEE8FC0683
Content-Type: text/plain; charset=us-ascii;
name="patch-shm64"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="patch-shm64"

// $Header: /pub/cvs/ms/patches/patch-shm64,v 1.1 1999/12/13 23:01:55 manfreds Exp $
// Kernel Version:
// VERSION = 2
// PATCHLEVEL = 3
// SUBLEVEL = 31
// EXTRAVERSION =
diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/include/asm-alpha/unistd.h build-2.3/include/asm-alpha/unistd.h
--- 2.3/include/asm-alpha/unistd.h Wed Sep 1 18:22:46 1999
+++ build-2.3/include/asm-alpha/unistd.h Mon Dec 13 23:35:26 1999
@@ -310,6 +310,7 @@
#define __NR_sendfile 370
#define __NR_setresgid 371
#define __NR_getresgid 372
+#define __NR_shmget64 373

#if defined(__LIBRARY__) && defined(__GNUC__)

diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/include/asm-i386/unistd.h build-2.3/include/asm-i386/unistd.h
--- 2.3/include/asm-i386/unistd.h Wed Dec 8 23:17:19 1999
+++ build-2.3/include/asm-i386/unistd.h Mon Dec 13 23:34:32 1999
@@ -199,6 +199,18 @@
#define __NR_mmap2 192
#define __NR_truncate64 193
#define __NR_ftruncate64 194
+#define __NR_msgget 195
+#define __NR_msgctl 196
+#define __NR_msgsnd 197
+#define __NR_msgrcv 198
+#define __NR_semget 199
+#define __NR_semctl 200
+#define __NR_semop 201
+#define __NR_shmget64 202
+#define __NR_shmctl 203
+#define __NR_shmat 204
+#define __NR_shmdt 205
+

/* user-visible error numbers are in the range -1 - -124: see <asm-i386/errno.h> */

diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/include/linux/shm.h build-2.3/include/linux/shm.h
--- 2.3/include/linux/shm.h Sun Nov 7 10:20:50 1999
+++ build-2.3/include/linux/shm.h Mon Dec 13 23:34:12 1999
@@ -18,7 +18,7 @@

struct shmid_ds {
struct ipc_perm shm_perm; /* operation perms */
- size_t shm_segsz; /* size of segment (bytes) */
+ int shm_segsz; /* size of segment (bytes) */
__kernel_time_t shm_atime; /* last attach time */
__kernel_time_t shm_dtime; /* last detach time */
__kernel_time_t shm_ctime; /* last change time */
@@ -70,7 +70,7 @@
#define SHM_DEST 01000 /* segment will be destroyed on last detach */
#define SHM_LOCKED 02000 /* segment will not be swapped */

-asmlinkage long sys_shmget (key_t key, size_t size, int flag);
+asmlinkage long sys_shmget64 (key_t key, size_t size, int flag);
asmlinkage long sys_shmat (int shmid, char *shmaddr, int shmflg, unsigned long *addr);
asmlinkage long sys_shmdt (char *shmaddr);
asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds *buf);
diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/ipc/shm.c build-2.3/ipc/shm.c
--- 2.3/ipc/shm.c Wed Dec 8 23:17:05 1999
+++ build-2.3/ipc/shm.c Mon Dec 13 23:44:34 1999
@@ -32,6 +32,7 @@
struct shmid_kernel /* extend struct shmis_ds with private fields */
{
struct shmid_ds u;
+ size_t real_segsz;
unsigned long shm_npages; /* size of segment (pages) */
pte_t **shm_dir; /* ptr to array of ptrs to frames -> SHMMAX */
struct vm_area_struct *attaches; /* descriptors for attaches */
@@ -89,7 +90,6 @@
/* some statistics */
static ulong swap_attempts = 0;
static ulong swap_successes = 0;
-static ulong used_segs = 0;

void __init shm_init (void)
{
@@ -204,7 +204,11 @@
}
shp->u.shm_perm.key = key;
shp->u.shm_perm.mode = (shmflg & S_IRWXUGO);
- shp->u.shm_segsz = size;
+ shp->real_segsz = size;
+ if(size < INT_MAX)
+ shp->u.shm_segsz = size;
+ else
+ shp->u.shm_segsz = INT_MAX;
shp->u.shm_cpid = current->pid;
shp->attaches = NULL;
shp->u.shm_lpid = shp->u.shm_nattch = 0;
@@ -220,7 +224,7 @@
return shm_buildid(id,shp->u.shm_perm.seq);
}

-asmlinkage long sys_shmget (key_t key, size_t size, int shmflg)
+asmlinkage long sys_shmget64 (key_t key, size_t size, int shmflg)
{
struct shmid_kernel *shp;
int err, id = 0;
@@ -337,7 +341,7 @@

memset(&shm_info,0,sizeof(shm_info));
shm_lockall();
- shm_info.used_ids = used_segs;
+ shm_info.used_ids = shm_ids.in_use;
shm_info.shm_rss = shm_rss;
shm_info.shm_tot = shm_tot;
shm_info.shm_swp = shm_swp;
@@ -566,7 +570,7 @@
err = -ENOMEM;
addr = 0;
again:
- if (!(addr = get_unmapped_area(addr, (unsigned long)shp->u.shm_segsz)))
+ if (!(addr = get_unmapped_area(addr, (unsigned long)shp->real_segsz)))
goto out_unlock_up;
if(addr & (SHMLBA - 1)) {
addr = (addr + (SHMLBA - 1)) & ~(SHMLBA - 1);
@@ -593,7 +597,7 @@
if (addr < current->mm->start_stack &&
addr > current->mm->start_stack - PAGE_SIZE*(shp->shm_npages + 4))
goto out_unlock_up;
- if (!(shmflg & SHM_REMAP) && find_vma_intersection(current->mm, addr, addr + (unsigned long)shp->u.shm_segsz))
+ if (!(shmflg & SHM_REMAP) && find_vma_intersection(current->mm, addr, addr + (unsigned long)shp->real_segsz))
goto out_unlock_up;

shm_unlock(shmid);
@@ -957,7 +961,7 @@
shp->u.shm_perm.key,
shm_buildid(i, shp->u.shm_perm.seq),
shp->u.shm_perm.mode,
- shp->u.shm_segsz,
+ shp->real_segsz,
shp->u.shm_cpid,
shp->u.shm_lpid,
shp->u.shm_nattch,
diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/arch/i386/kernel/entry.S build-2.3/arch/i386/kernel/entry.S
--- 2.3/arch/i386/kernel/entry.S Wed Dec 8 23:17:11 1999
+++ build-2.3/arch/i386/kernel/entry.S Mon Dec 13 23:45:24 1999
@@ -595,7 +595,18 @@
.long SYMBOL_NAME(sys_mmap2)
.long SYMBOL_NAME(sys_truncate64)
.long SYMBOL_NAME(sys_ftruncate64)
- /* 195 */
+ .long SYMBOL_NAME(sys_msgget)
+ .long SYMBOL_NAME(sys_msgctl)
+ .long SYMBOL_NAME(sys_msgsnd)
+ .long SYMBOL_NAME(sys_msgrcv)
+ .long SYMBOL_NAME(sys_semget)
+ .long SYMBOL_NAME(sys_semctl) /* 200 */
+ .long SYMBOL_NAME(sys_semop)
+ .long SYMBOL_NAME(sys_shmget64)
+ .long SYMBOL_NAME(sys_shmctl)
+ .long SYMBOL_NAME(sys_shmat)
+ .long SYMBOL_NAME(sys_shmdt)
+ /* 206 */

/*
* NOTE!! This doesn't have to be exact - we just have
@@ -603,6 +614,6 @@
* entries. Don't panic if you notice that this hasn't
* been shrunk every time we add a new system call.
*/
- .rept NR_syscalls-194
+ .rept NR_syscalls-205
.long SYMBOL_NAME(sys_ni_syscall)
.endr
diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/arch/i386/kernel/sys_i386.c build-2.3/arch/i386/kernel/sys_i386.c
--- 2.3/arch/i386/kernel/sys_i386.c Wed Dec 8 23:17:11 1999
+++ build-2.3/arch/i386/kernel/sys_i386.c Mon Dec 13 23:47:09 1999
@@ -201,7 +201,7 @@
case SHMDT:
return sys_shmdt ((char *)ptr);
case SHMGET:
- return sys_shmget (first, second, third);
+ return sys_shmget64 (first, second, third);
case SHMCTL:
return sys_shmctl (first, second,
(struct shmid_ds *) ptr);
diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/arch/alpha/kernel/entry.S build-2.3/arch/alpha/kernel/entry.S
--- 2.3/arch/alpha/kernel/entry.S Wed Sep 1 18:22:16 1999
+++ build-2.3/arch/alpha/kernel/entry.S Mon Dec 13 23:40:03 1999
@@ -1149,3 +1149,4 @@
.quad sys_sendfile /* 370 */
.quad sys_setresgid
.quad sys_getresgid
+ .quad sys_shmget64
diff -ur --exclude ptrace.h --exclude Makefile --exclude i386-stubs.c --exclude traps.c --exclude fault.c --exclude ioctls.h 2.3/arch/alpha/kernel/osf_sys.c build-2.3/arch/alpha/kernel/osf_sys.c
--- 2.3/arch/alpha/kernel/osf_sys.c Tue Aug 10 09:53:54 1999
+++ build-2.3/arch/alpha/kernel/osf_sys.c Mon Dec 13 23:44:01 1999
@@ -31,6 +31,7 @@
#include <linux/shm.h>
#include <linux/poll.h>
#include <linux/file.h>
+#include <linux/shm.h>

#include <asm/fpu.h>
#include <asm/io.h>
@@ -1442,3 +1443,9 @@

return ret;
}
+
+asmlinkage long sys_shmget (key_t key, int size, int flag)
+{
+ return sys_shmget64(key,size,flag)
+}
+

--------------32A3DE49A63C01CEE8FC0683--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/