* shm.cc (struct shm_attached_list): Convert access type to ULONG.

(fixup_shms_after_fork): Fix comment.  Use NtMapViewOfSection rather
	than MapViewOfFileEx to recreate shared memory regions.  Add function
	name to api_fatal output.
	(shmat): Use NtMapViewOfSection to create shared memory region
	top-down.
This commit is contained in:
Corinna Vinschen 2009-03-31 14:58:14 +00:00
parent 83fb2c849c
commit 1e4e6ee8f4
2 changed files with 30 additions and 13 deletions

View File

@ -1,3 +1,12 @@
2009-03-31 Corinna Vinschen <corinna@vinschen.de>
* shm.cc (struct shm_attached_list): Convert access type to ULONG.
(fixup_shms_after_fork): Fix comment. Use NtMapViewOfSection rather
than MapViewOfFileEx to recreate shared memory regions. Add function
name to api_fatal output.
(shmat): Use NtMapViewOfSection to create shared memory region
top-down.
2009-03-31 Corinna Vinschen <corinna@vinschen.de> 2009-03-31 Corinna Vinschen <corinna@vinschen.de>
* ctype.cc: Remove implementation of ctype functions in favor of * ctype.cc: Remove implementation of ctype functions in favor of

View File

@ -18,6 +18,7 @@ details. */
#include "cygserver_shm.h" #include "cygserver_shm.h"
#include "cygtls.h" #include "cygtls.h"
#include "sync.h" #include "sync.h"
#include "ntdll.h"
/* /*
* client_request_shm Constructors * client_request_shm Constructors
@ -104,7 +105,7 @@ struct shm_attached_list {
SLIST_ENTRY (shm_attached_list) sph_next; SLIST_ENTRY (shm_attached_list) sph_next;
vm_object_t ptr; vm_object_t ptr;
shm_shmid_list *parent; shm_shmid_list *parent;
int access; ULONG access;
}; };
static SLIST_HEAD (, shm_attached_list) sph_list; static SLIST_HEAD (, shm_attached_list) sph_list;
@ -129,15 +130,18 @@ fixup_shms_after_fork ()
return 0; return 0;
} }
shm_attached_list *sph_entry; shm_attached_list *sph_entry;
/* Remove map from list... */ /* Reconstruct map from list... */
SLIST_FOREACH (sph_entry, &sph_list, sph_next) SLIST_FOREACH (sph_entry, &sph_list, sph_next)
{ {
vm_object_t ptr = MapViewOfFileEx (sph_entry->parent->hdl, NTSTATUS status;
sph_entry->access, 0, 0, vm_object_t ptr = sph_entry->ptr;
sph_entry->parent->size, ULONG viewsize = sph_entry->parent->size;
sph_entry->ptr); status = NtMapViewOfSection (sph_entry->parent->hdl, GetCurrentProcess (),
if (ptr != sph_entry->ptr) &ptr, 0, sph_entry->parent->size, NULL,
api_fatal ("MapViewOfFileEx (%p), %E. Terminating.", sph_entry->ptr); &viewsize, ViewShare, 0, sph_entry->access);
if (!NT_SUCCESS (status) || ptr != sph_entry->ptr)
api_fatal ("fixup_shms_after_fork: NtMapViewOfSection (%p), status %p. Terminating.",
sph_entry->ptr, status);
} }
return 0; return 0;
} }
@ -213,12 +217,16 @@ shmat (int shmid, const void *shmaddr, int shmflg)
--ssh_entry->ref_count; --ssh_entry->ref_count;
return (void *) -1; return (void *) -1;
} }
DWORD access = (shmflg & SHM_RDONLY) ? FILE_MAP_READ : FILE_MAP_WRITE; NTSTATUS status;
vm_object_t ptr = MapViewOfFileEx (ssh_entry->hdl, access, 0, 0, vm_object_t ptr = NULL;
ssh_entry->size, attach_va); ULONG viewsize = ssh_entry->size;
if (!ptr) ULONG access = (shmflg & SHM_RDONLY) ? PAGE_READONLY : PAGE_READWRITE;
status = NtMapViewOfSection (ssh_entry->hdl, GetCurrentProcess (), &ptr, 0,
ssh_entry->size, NULL, &viewsize, ViewShare,
MEM_TOP_DOWN, access);
if (!NT_SUCCESS (status))
{ {
__seterrno (); __seterrno_from_nt_status (status);
delete sph_entry; delete sph_entry;
--ssh_entry->ref_count; --ssh_entry->ref_count;
return (void *) -1; return (void *) -1;