Index: sys/kern/sysv_shm.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sysv_shm.c,v retrieving revision 1.112 diff -u -r1.112 sysv_shm.c --- sys/kern/sysv_shm.c 24 Oct 2007 19:03:55 -0000 1.112 +++ sys/kern/sysv_shm.c 18 Jan 2008 07:28:13 -0000 @@ -149,7 +149,7 @@ #define SHMMAXPGS 8192 /* Note: sysv shared memory is swap backed. */ #endif #ifndef SHMMAX -#define SHMMAX (SHMMAXPGS*PAGE_SIZE) +#define SHMMAX ((u_long)(SHMMAXPGS) * PAGE_SIZE) #endif #ifndef SHMMIN #define SHMMIN 1 @@ -630,15 +630,82 @@ return (error); } +#if !defined(__i386__) && \ + (defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD6) || \ + defined(COMPAT_FREEBSD7)) +struct oshmid_ds { + struct ipc_perm shm_perm; + int shm_segsz; + pid_t shm_lpid; + pid_t shm_cpid; + short shm_nattch; + time_t shm_atime; + time_t shm_dtime; + time_t shm_ctime; + void *shm_internal; +}; +#endif + int shmctl(td, uap) struct thread *td; struct shmctl_args *uap; { - int error = 0; struct shmid_ds buf; size_t bufsz; + int error = 0; + +#if !defined(__i386__) && \ + (defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD6) || \ + defined(COMPAT_FREEBSD7)) + if (sizeof(size_t) != sizeof(int) && td->td_proc->p_osrel <= 800013) { + struct oshmid_ds obuf; + + if (uap->cmd == IPC_SET) { + if ((error = copyin(uap->buf, &obuf, sizeof(obuf)))) + goto done; + memcpy(&buf.shm_perm, &obuf.shm_perm, + sizeof(buf.shm_perm)); + buf.shm_segsz = obuf.shm_segsz; + buf.shm_lpid = obuf.shm_lpid; + buf.shm_cpid = obuf.shm_cpid; + buf.shm_nattch = obuf.shm_nattch; + buf.shm_atime = obuf.shm_atime; + buf.shm_dtime = obuf.shm_dtime; + buf.shm_ctime = obuf.shm_ctime; + buf.shm_internal = obuf.shm_internal; + } + + error = kern_shmctl(td, uap->shmid, uap->cmd, (void *)&buf, + &bufsz); + if (error) + goto done; + /* Cases in which we need to copyout */ + switch (uap->cmd) { + case SHM_STAT: + case IPC_STAT: + memcpy(&obuf.shm_perm, &buf.shm_perm, + sizeof(obuf.shm_perm)); + obuf.shm_segsz = buf.shm_segsz; + obuf.shm_lpid = buf.shm_lpid; + obuf.shm_cpid = buf.shm_cpid; + obuf.shm_nattch = buf.shm_nattch; + obuf.shm_atime = buf.shm_atime; + obuf.shm_dtime = buf.shm_dtime; + obuf.shm_ctime = buf.shm_ctime; + obuf.shm_internal = buf.shm_internal; + error = copyout(&obuf, uap->buf, sizeof(obuf)); + break; + case IPC_INFO: + case SHM_INFO: + error = copyout(&buf, uap->buf, bufsz); + break; + } + + goto done; + } +#endif /* IPC_SET needs to copyin the buffer before calling kern_shmctl */ if (uap->cmd == IPC_SET) { if ((error = copyin(uap->buf, &buf, sizeof(struct shmid_ds)))) @@ -717,10 +784,11 @@ struct shmget_args *uap; int mode; { - int i, segnum, shmid, size; struct ucred *cred = td->td_ucred; struct shmid_kernel *shmseg; vm_object_t shm_object; + size_t size; + int i, segnum, shmid; GIANT_REQUIRED; @@ -977,6 +1045,36 @@ sysctl_shmsegs(SYSCTL_HANDLER_ARGS) { +#if !defined(__i386__) && \ + (defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD6) || \ + defined(COMPAT_FREEBSD7)) + if (sizeof(size_t) != sizeof(int) && shmalloced > 0 && + curproc->p_osrel <= 800011) { + struct { + struct oshmid_ds u; + struct label *label; + } *osegs; + int error, i; + + osegs = malloc(shmalloced * sizeof(osegs[0]), M_SHM, M_WAITOK); + for (i = 0; i < shmalloced; i++) { + memcpy(&osegs[i].u.shm_perm, &shmsegs[i].u.shm_perm, + sizeof(osegs[0].u.shm_perm)); + osegs[i].u.shm_segsz = shmsegs[i].u.shm_segsz; + osegs[i].u.shm_lpid = shmsegs[i].u.shm_lpid; + osegs[i].u.shm_cpid = shmsegs[i].u.shm_cpid; + osegs[i].u.shm_nattch = shmsegs[i].u.shm_nattch; + osegs[i].u.shm_atime = shmsegs[i].u.shm_atime; + osegs[i].u.shm_dtime = shmsegs[i].u.shm_dtime; + osegs[i].u.shm_ctime = shmsegs[i].u.shm_ctime; + osegs[i].u.shm_internal = shmsegs[i].u.shm_internal; + osegs[i].label = shmsegs[i].label; + } + error = SYSCTL_OUT(req, osegs, shmalloced * sizeof(osegs[0])); + free(osegs, M_SHM); + return (error); + } +#endif return (SYSCTL_OUT(req, shmsegs, shmalloced * sizeof(shmsegs[0]))); } Index: sys/sys/param.h =================================================================== RCS file: /home/ncvs/src/sys/sys/param.h,v retrieving revision 1.325 diff -u -r1.325 param.h --- sys/sys/param.h 13 Jan 2008 14:48:51 -0000 1.325 +++ sys/sys/param.h 18 Jan 2008 07:28:13 -0000 @@ -57,7 +57,7 @@ * is created, otherwise 1. */ #undef __FreeBSD_version -#define __FreeBSD_version 800013 /* Master, propagated to newvers */ +#define __FreeBSD_version 800014 /* Master, propagated to newvers */ #ifndef LOCORE #include Index: sys/sys/shm.h =================================================================== RCS file: /home/ncvs/src/sys/sys/shm.h,v retrieving revision 1.24 diff -u -r1.24 shm.h --- sys/sys/shm.h 6 Aug 2005 07:20:17 -0000 1.24 +++ sys/sys/shm.h 18 Jan 2008 07:28:13 -0000 @@ -77,14 +77,14 @@ struct shmid_ds { struct ipc_perm shm_perm; /* operation permission structure */ - int shm_segsz; /* size of segment in bytes */ - pid_t shm_lpid; /* process ID of last shared memory op */ - pid_t shm_cpid; /* process ID of creator */ + size_t shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* process ID of last shared memory op */ + pid_t shm_cpid; /* process ID of creator */ short shm_nattch; /* number of current attaches */ - time_t shm_atime; /* time of last shmat() */ - time_t shm_dtime; /* time of last shmdt() */ - time_t shm_ctime; /* time of last change by shmctl() */ - void *shm_internal; /* sysv stupidity */ + time_t shm_atime; /* time of last shmat() */ + time_t shm_dtime; /* time of last shmdt() */ + time_t shm_ctime; /* time of last change by shmctl() */ + void *shm_internal; /* sysv stupidity */ }; #ifdef _KERNEL