From 1fc7f43ffa9c1b3a547938ffeed88c6953e021aa Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 26 Jul 2016 17:23:49 +0000 Subject: [PATCH] Add shmatt_t. It looks like our "struct shmid_ds::shm_nattch" deviates from the standard in the sense that it is a signed integer, whereas POSIX requires that it is unsigned, having a special type shmatt_t. Patch up our native and 32-bit copies to use a new shmatt_t that is an unsigned integer. As it's unsigned, we can relax the comparisons that are performed on it. Leave the Linux, iBCS2, etc. copies of the structure alone. Reviewed by: ngie Differential Revision: https://reviews.freebsd.org/D6655 --- sys/compat/freebsd32/freebsd32_ipc.h | 2 +- sys/kern/sysv_shm.c | 4 ++-- sys/sys/shm.h | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/compat/freebsd32/freebsd32_ipc.h b/sys/compat/freebsd32/freebsd32_ipc.h index 320a63f0c2dd..1f457f8f678f 100644 --- a/sys/compat/freebsd32/freebsd32_ipc.h +++ b/sys/compat/freebsd32/freebsd32_ipc.h @@ -72,7 +72,7 @@ struct shmid_ds32 { int32_t shm_segsz; pid_t shm_lpid; pid_t shm_cpid; - int shm_nattch; + unsigned int shm_nattch; int32_t shm_atime; int32_t shm_dtime; int32_t shm_ctime; diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index 4232a7f95234..24ece36e7f02 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -275,7 +275,7 @@ shm_delete_mapping(struct vmspace *vm, struct shmmap_state *shmmap_s) return (EINVAL); shmmap_s->shmid = -1; shmseg->u.shm_dtime = time_second; - if ((--shmseg->u.shm_nattch <= 0) && + if (--shmseg->u.shm_nattch == 0 && (shmseg->u.shm_perm.mode & SHMSEG_REMOVED)) { shm_deallocate_segment(shmseg); shm_last_free = segnum; @@ -289,7 +289,7 @@ shm_remove(struct shmid_kernel *shmseg, int segnum) shmseg->u.shm_perm.key = IPC_PRIVATE; shmseg->u.shm_perm.mode |= SHMSEG_REMOVED; - if (shmseg->u.shm_nattch <= 0) { + if (shmseg->u.shm_nattch == 0) { shm_deallocate_segment(shmseg); shm_last_free = segnum; } diff --git a/sys/sys/shm.h b/sys/sys/shm.h index abf5a85b0d84..218be51a397a 100644 --- a/sys/sys/shm.h +++ b/sys/sys/shm.h @@ -92,12 +92,14 @@ struct shmid_ds_old { }; #endif +typedef unsigned int shmatt_t; + struct shmid_ds { struct ipc_perm shm_perm; /* operation permission structure */ 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 */ - int 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() */