From: Jan Lentfer Date: Sat, 30 Apr 2011 10:24:35 +0000 (+0100) Subject: Adjust shared memory (shm) functions and headers to POSIX. X-Git-Url: https://gitweb.dragonflybsd.org/~lentferj/dragonfly.git/commitdiff_plain/fa192ede950cd73380c8a257eea983831d3b97fe Adjust shared memory (shm) functions and headers to POSIX. Change SYSV SHM to allow more than 2GB of memory allocation. * Basically this means a change from int to size_t in the appropriate places. * Tested on X86_64 using PostgreSQL configured with 2GB of shared_buffers and kern.ipc.shmmax set to 3GB. In-Colloboration-With (libc stuff): Sascha Wildner --- diff --git a/lib/libc/gen/shmat.c b/lib/libc/gen/shmat.c index ccd1b7617f..93dbe00afe 100644 --- a/lib/libc/gen/shmat.c +++ b/lib/libc/gen/shmat.c @@ -1,6 +1,5 @@ /* * $FreeBSD: src/lib/libc/gen/shmat.c,v 1.4 1999/08/27 23:58:56 peter Exp $ - * $DragonFly: src/lib/libc/gen/shmat.c,v 1.4 2005/11/19 22:32:53 swildner Exp $ */ #include @@ -8,7 +7,7 @@ #include void * -shmat(int shmid, void *shmaddr, int shmflg) +shmat(int shmid, const void *shmaddr, int shmflg) { return ((void *)shmsys(0, shmid, shmaddr, shmflg)); } diff --git a/lib/libc/gen/shmdt.c b/lib/libc/gen/shmdt.c index 827f909a10..1606bca6f5 100644 --- a/lib/libc/gen/shmdt.c +++ b/lib/libc/gen/shmdt.c @@ -1,13 +1,12 @@ /* * $FreeBSD: src/lib/libc/gen/shmdt.c,v 1.4 1999/08/27 23:58:57 peter Exp $ - * $DragonFly: src/lib/libc/gen/shmdt.c,v 1.3 2005/11/13 00:07:42 swildner Exp $ */ #include #include #include -int shmdt(void *shmaddr) +int shmdt(const void *shmaddr) { return (shmsys(2, shmaddr)); } diff --git a/lib/libc/gen/shmget.c b/lib/libc/gen/shmget.c index 099c34cbb4..9ba2bf4b27 100644 --- a/lib/libc/gen/shmget.c +++ b/lib/libc/gen/shmget.c @@ -1,13 +1,12 @@ /* * $FreeBSD: src/lib/libc/gen/shmget.c,v 1.4 1999/08/27 23:58:57 peter Exp $ - * $DragonFly: src/lib/libc/gen/shmget.c,v 1.3 2005/11/13 00:07:42 swildner Exp $ */ #include #include #include -int shmget(key_t key, int size, int shmflg) +int shmget(key_t key, size_t size, int shmflg) { return (shmsys(3, key, size, shmflg)); } diff --git a/lib/libc/sys/shmat.2 b/lib/libc/sys/shmat.2 index ea64294276..aa0ab9a84c 100644 --- a/lib/libc/sys/shmat.2 +++ b/lib/libc/sys/shmat.2 @@ -24,9 +24,8 @@ .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD: src/lib/libc/sys/shmat.2,v 1.8.2.6 2001/12/14 18:34:01 ru Exp $ -.\" $DragonFly: src/lib/libc/sys/shmat.2,v 1.2 2003/06/17 04:26:47 dillon Exp $ .\" -.Dd August 2, 1995 +.Dd January 17, 2010 .Dt SHMAT 2 .Os .Sh NAME @@ -41,9 +40,9 @@ .In sys/ipc.h .In sys/shm.h .Ft void * -.Fn shmat "int shmid" "void *addr" "int flag" +.Fn shmat "int shmid" "const void *addr" "int flag" .Ft int -.Fn shmdt "void *addr" +.Fn shmdt "const void *addr" .Sh DESCRIPTION .Fn Shmat attaches the shared memory segment identified by diff --git a/lib/libc/sys/shmctl.2 b/lib/libc/sys/shmctl.2 index fcabedcd0d..b87dc61814 100644 --- a/lib/libc/sys/shmctl.2 +++ b/lib/libc/sys/shmctl.2 @@ -24,9 +24,8 @@ .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD: src/lib/libc/sys/shmctl.2,v 1.9.2.4 2001/12/14 18:34:01 ru Exp $ -.\" $DragonFly: src/lib/libc/sys/shmctl.2,v 1.2 2003/06/17 04:26:47 dillon Exp $ .\" -.Dd July 17, 1995 +.Dd January 17, 2010 .Dt SHMCTL 2 .Os .Sh NAME @@ -97,12 +96,14 @@ struct is defined as follows: .\" with nroff, but otherwise it's straight from sys/shm.h .\" .Bd -literal +typedef unsigned int shmatt_t; + 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 */ + size_t shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* process ID of last shm operation */ pid_t shm_cpid; /* process ID of creator */ - short shm_nattch; /* number of current attaches */ + shmatt_t 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() */ diff --git a/lib/libc/sys/shmget.2 b/lib/libc/sys/shmget.2 index 5e9a0ba860..69e4394804 100644 --- a/lib/libc/sys/shmget.2 +++ b/lib/libc/sys/shmget.2 @@ -26,7 +26,7 @@ .\" $FreeBSD: src/lib/libc/sys/shmget.2,v 1.8.2.6 2001/12/14 18:34:01 ru Exp $ .\" $DragonFly: src/lib/libc/sys/shmget.2,v 1.2 2003/06/17 04:26:47 dillon Exp $ .\" -.Dd July 3, 1995 +.Dd January 17, 2010 .Dt SHMGET 2 .Os .Sh NAME @@ -40,7 +40,7 @@ .In sys/ipc.h .In sys/shm.h .Ft int -.Fn shmget "key_t key" "int size" "int flag" +.Fn shmget "key_t key" "size_t size" "int flag" .Sh DESCRIPTION Based on the values of .Fa key diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index f8dc2f2ef5..5379c02adf 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -361,11 +361,12 @@ int msgflg); } 227 STD BSD { int msgrcv(int msqid, void *msgp, size_t msgsz, \ long msgtyp, int msgflg); } -228 STD BSD { caddr_t shmat(int shmid, void *shmaddr, int shmflg); } +228 STD BSD { caddr_t shmat(int shmid, const void *shmaddr, \ + int shmflg); } 229 STD BSD { int shmctl(int shmid, int cmd, \ struct shmid_ds *buf); } -230 STD BSD { int shmdt(void *shmaddr); } -231 STD BSD { int shmget(key_t key, int size, int shmflg); } +230 STD BSD { int shmdt(const void *shmaddr); } +231 STD BSD { int shmget(key_t key, size_t size, int shmflg); } ; 232 STD POSIX { int clock_gettime(clockid_t clock_id, \ struct timespec *tp); } diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index 7c8f11757a..4e1bc9cf53 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -78,7 +78,8 @@ static sy_call_t *shmcalls[] = { #define SHMSEG_ALLOCATED 0x0800 #define SHMSEG_WANTED 0x1000 -static int shm_last_free, shm_committed, shmalloced; +static int shm_last_free, shmalloced; +size_t shm_committed; int shm_nused; static struct shmid_ds *shmsegs; @@ -131,21 +132,21 @@ struct shminfo shminfo = { static int shm_use_phys; -TUNABLE_INT("kern.ipc.shmmin", &shminfo.shmmin); -TUNABLE_INT("kern.ipc.shmmni", &shminfo.shmmni); -TUNABLE_INT("kern.ipc.shmseg", &shminfo.shmseg); -TUNABLE_INT("kern.ipc.shmmaxpgs", &shminfo.shmall); +TUNABLE_ULONG("kern.ipc.shmmin", &shminfo.shmmin); +TUNABLE_ULONG("kern.ipc.shmmni", &shminfo.shmmni); +TUNABLE_ULONG("kern.ipc.shmseg", &shminfo.shmseg); +TUNABLE_ULONG("kern.ipc.shmmaxpgs", &shminfo.shmall); TUNABLE_INT("kern.ipc.shm_use_phys", &shm_use_phys); -SYSCTL_INT(_kern_ipc, OID_AUTO, shmmax, CTLFLAG_RW, &shminfo.shmmax, 0, +SYSCTL_ULONG(_kern_ipc, OID_AUTO, shmmax, CTLFLAG_RW, &shminfo.shmmax, 0, "Max shared memory segment size"); -SYSCTL_INT(_kern_ipc, OID_AUTO, shmmin, CTLFLAG_RW, &shminfo.shmmin, 0, +SYSCTL_ULONG(_kern_ipc, OID_AUTO, shmmin, CTLFLAG_RW, &shminfo.shmmin, 0, "Min shared memory segment size"); -SYSCTL_INT(_kern_ipc, OID_AUTO, shmmni, CTLFLAG_RD, &shminfo.shmmni, 0, +SYSCTL_ULONG(_kern_ipc, OID_AUTO, shmmni, CTLFLAG_RD, &shminfo.shmmni, 0, "Max number of shared memory identifiers"); SYSCTL_INT(_kern_ipc, OID_AUTO, shmseg, CTLFLAG_RW, &shminfo.shmseg, 0, "Max shared memory segments per process"); -SYSCTL_INT(_kern_ipc, OID_AUTO, shmall, CTLFLAG_RW, &shminfo.shmall, 0, +SYSCTL_ULONG(_kern_ipc, OID_AUTO, shmall, CTLFLAG_RW, &shminfo.shmall, 0, "Max pages of shared memory"); SYSCTL_INT(_kern_ipc, OID_AUTO, shm_use_phys, CTLFLAG_RW, &shm_use_phys, 0, "Use phys pager allocation instead of swap pager allocation"); @@ -529,7 +530,8 @@ shmget_existing(struct proc *p, struct shmget_args *uap, int mode, int segnum) static int shmget_allocate_segment(struct proc *p, struct shmget_args *uap, int mode) { - int i, segnum, shmid, size; + int i, segnum, shmid; + size_t size; struct ucred *cred = p->p_ucred; struct shmid_ds *shmseg; struct shm_handle *shm_handle; diff --git a/sys/sys/shm.h b/sys/sys/shm.h index 178f097640..61153cfeb1 100644 --- a/sys/sys/shm.h +++ b/sys/sys/shm.h @@ -1,5 +1,4 @@ /* $FreeBSD: src/sys/sys/shm.h,v 1.14 1999/12/29 04:24:46 peter Exp $ */ -/* $DragonFly: src/sys/sys/shm.h,v 1.6 2006/09/30 20:03:44 swildner Exp $ */ /* $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $ */ /* @@ -51,13 +50,14 @@ #define SHM_R (IPC_R) #define SHM_W (IPC_W) +typedef unsigned int shmatt_t; 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 */ + size_t shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* process ID of last shm operation */ pid_t shm_cpid; /* process ID of creator */ - short shm_nattch; /* number of current attaches */ + shmatt_t 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() */ @@ -71,7 +71,7 @@ struct shmid_ds { * might be of interest to user programs. Do we really want/need this? */ struct shminfo { - int shmmax, /* max shared memory segment size (bytes) */ + u_long shmmax, /* max shared memory segment size (bytes) */ shmmin, /* min shared memory segment size (bytes) */ shmmni, /* max number of shared memory identifiers */ shmseg, /* max shared memory segments per process */ @@ -96,10 +96,10 @@ void shmfork (struct proc *, struct proc *); __BEGIN_DECLS int shmsys (int, ...); -void *shmat (int, void *, int); -int shmget (key_t, int, int); +void *shmat (int, const void *, int); +int shmget (key_t, size_t, int); int shmctl (int, int, struct shmid_ds *); -int shmdt (void *); +int shmdt (const void *); __END_DECLS #endif /* !_KERNEL */ diff --git a/sys/sys/sysproto.h b/sys/sys/sysproto.h index 28bf4fd33b..d2e1b3b628 100644 --- a/sys/sys/sysproto.h +++ b/sys/sys/sysproto.h @@ -1112,7 +1112,7 @@ struct shmat_args { struct sysmsg sysmsg; #endif int shmid; char shmid_[PAD_(int)]; - void * shmaddr; char shmaddr_[PAD_(void *)]; + const void * shmaddr; char shmaddr_[PAD_(const void *)]; int shmflg; char shmflg_[PAD_(int)]; }; struct shmctl_args { @@ -1127,14 +1127,14 @@ struct shmdt_args { #ifdef _KERNEL struct sysmsg sysmsg; #endif - void * shmaddr; char shmaddr_[PAD_(void *)]; + const void * shmaddr; char shmaddr_[PAD_(const void *)]; }; struct shmget_args { #ifdef _KERNEL struct sysmsg sysmsg; #endif key_t key; char key_[PAD_(key_t)]; - int size; char size_[PAD_(int)]; + size_t size; char size_[PAD_(size_t)]; int shmflg; char shmflg_[PAD_(int)]; }; struct clock_gettime_args {