#define __FBSDID(s) const char version[] = (s)
#endif
__FBSDID("$FreeBSD: /repoman/r/ncvs/src/sys/kern/sysv_shm.c,v 1.89 2003/11/07 04:47:14 rwatson Exp $");
+/* CV, 2006-01-09: Inspected upstream up to version 1.104. */
#define _KERNEL 1
#define __BSD_VISIBLE 1
#define btoc(b) (((b) + PAGE_MASK) / PAGE_SIZE)
#define round_page(p) ((((unsigned long)(p)) + PAGE_MASK) & ~(PAGE_MASK))
#define ACCESSPERMS (0777)
+#ifdef __CYGWIN__
+#define GIANT_REQUIRED
+#else
#define GIANT_REQUIRED mtx_assert(&Giant, MA_OWNED)
+#endif
#define KERN_SUCCESS 0
#define VM_PROT_READ PROT_READ
#define VM_PROT_WRITE PROT_WRITE
#define vm_object_clear_flag(a,b)
#define vm_object_set_flag(a,b)
#define VM_OBJECT_UNLOCK(a)
-#define vm_object_reference(a)
#define vm_map_remove(a,b,c) KERN_SUCCESS
-#define vm_map_find(a,b,c,d,e,f,g,h,i) KERN_SUCCESS
-#define vm_map_inherit(a,b,c,d)
typedef int vm_prot_t;
#endif /* __CYGWIN__ */
int i, flags;
struct shmid_ds *shmseg;
struct shmmap_state *shmmap_s = NULL;
+#ifndef __CYGWIN__
struct shm_handle *shm_handle;
+#endif
vm_offset_t attach_va;
vm_prot_t prot;
vm_size_t size;
+#ifndef __CYGWIN__
int rv;
+#endif
int error = 0;
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
if ((shmflg & SHM_RDONLY) == 0)
prot |= VM_PROT_WRITE;
flags = MAP_ANON | MAP_SHARED;
+ debug_printf ("shmaddr: %x, shmflg: %x", shmaddr, shmflg);
+#ifdef __CYGWIN__
+ /* The alignment checks have already been made in the Cygwin DLL
+ and shmat's only job is to keep record of the attached mem.
+ These checks break shm on 9x since MapViewOfFileEx apparently
+ returns memory which isn't aligned to SHMLBA. Go figure! */
+ attach_va = (vm_offset_t)shmaddr;
+#else
if (shmaddr) {
flags |= MAP_FIXED;
if (shmflg & SHM_RND) {
* This is just a hint to vm_map_find() about where to
* put it.
*/
-#ifdef __CYGWIN__
- attach_va = 0;
-#else
attach_va = round_page((vm_offset_t)p->p_vmspace->vm_taddr
+ maxtsiz + maxdsiz);
-#endif
}
shm_handle = shmseg->shm_internal;
}
vm_map_inherit(&p->p_vmspace->vm_map,
attach_va, attach_va + size, VM_INHERIT_SHARE);
+#endif
shmmap_s->va = attach_va;
shmmap_s->shmid = shmid;
if (shm_nused >= shminfo.shmmni) /* Any shmids left? */
return (ENOSPC);
size = round_page(uap->size);
- if (shm_committed + btoc(size) > (unsigned long) shminfo.shmall)
+ if (shm_committed + btoc(size) > shminfo.shmall)
return (ENOMEM);
if (shm_last_free < 0) {
shmrealloc(); /* Maybe expand the shmsegs[] array. */
mode = uap->shmflg & ACCESSPERMS;
if (uap->key != IPC_PRIVATE) {
again:
+#ifdef __CYGWIN__
+ if (uap->shmflg & IPC_KEY_IS_SHMID)
+ segnum = shm_find_segment_by_shmid ((int) uap->key) ?
+ IPCID_TO_IX((int) uap->key) : -1;
+ else
+#endif
segnum = shm_find_segment_by_key(uap->key);
if (segnum >= 0) {
error = shmget_existing(td, uap, mode, segnum);
#ifdef __CYGWIN__
if (!error)
ipcexit_creat_hookthread (td);
+ else
+ td->td_retval[0] = -1;
#endif
mtx_unlock(&Giant);
return (error);
shminit(void)
{
int i;
+ tun_bool_t shm_ar;
TUNABLE_INT_FETCH("kern.ipc.shmmaxpgs", &shminfo.shmall);
for (i = PAGE_SIZE; i > 0; i--) {
- shminfo.shmmax = shminfo.shmall * PAGE_SIZE;
+ shminfo.shmmax = shminfo.shmall * i;
if (shminfo.shmmax >= shminfo.shmall)
break;
}
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);
-
+ TUNABLE_BOOL_FETCH("kern.ipc.shm_allow_removed", &shm_ar);
+ if (shm_ar == TUN_TRUE)
+ shm_allow_removed = 1;
shmalloced = shminfo.shmmni;
shmsegs = (struct shmid_ds *) sys_malloc(shmalloced * sizeof(shmsegs[0]), M_SHM, M_WAITOK);
if (shmsegs == NULL)