aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/shared.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2005-04-28 23:59:44 +0000
committerChristopher Faylor <me@cgf.cx>2005-04-28 23:59:44 +0000
commitc4ffa3c427f77224e8a2d58219c9de25666b0b69 (patch)
tree628c949a7dca65aea4684a1a97207f47cf9bdbd5 /winsup/cygwin/shared.cc
parente525f6d51a38d6648ebba2a2c2b25f31d7bfe5ce (diff)
downloadnewlib-c4ffa3c427f77224e8a2d58219c9de25666b0b69.zip
newlib-c4ffa3c427f77224e8a2d58219c9de25666b0b69.tar.gz
newlib-c4ffa3c427f77224e8a2d58219c9de25666b0b69.tar.bz2
* shared_info.h (cygwin_shared_address): Bump to a higher value to avoid
collision with large data areas. * fhandler_console.cc (fhandler_console::get_tty_stuff): Accommodate changes to open_shared arguments. * fhandler_tape.cc (mtinfo_init): Ditto. * pinfo.cc (pinfo::init): Use open_shared rather than win32 mmap calls. * shared.cc (user_shared_initialize): Ditto. (memory_init): Ditto. (open_shared): Change to allow use a smore general mmap handler. * shared_info.h (shared_locations): Add SH_JUSTCREATE, SH_JUSTOPEN. (open_shared): Change declaration to match new usage. * autoload.cc (LoadDLLfuncEx2): Define in terms of LoadDLLfuncEx3. (LoadDLLfuncEx3): New macro.
Diffstat (limited to 'winsup/cygwin/shared.cc')
-rw-r--r--winsup/cygwin/shared.cc45
1 files changed, 28 insertions, 17 deletions
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index 8798b2c..f0daccb 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -75,23 +75,20 @@ static char *offsets[] =
void * __stdcall
open_shared (const char *name, int n, HANDLE& shared_h, DWORD size,
- shared_locations m, PSECURITY_ATTRIBUTES psa)
+ shared_locations& m, PSECURITY_ATTRIBUTES psa, DWORD access)
{
void *shared;
void *addr;
- if (!wincap.needs_memory_protection () && offsets[0])
+ if ((m == SH_JUSTCREATE || m == SH_JUSTOPEN)
+ || !wincap.needs_memory_protection () && offsets[0])
addr = NULL;
else
- {
- addr = offsets[m];
- (void) VirtualFree (addr, 0, MEM_RELEASE);
- }
-
- if (!size)
- return addr;
+ addr = offsets[m];
- if (!shared_h)
+ if (shared_h)
+ m = SH_JUSTOPEN;
+ else
{
char *mapname;
char map_buf[CYG_MAX_PATH];
@@ -99,20 +96,32 @@ open_shared (const char *name, int n, HANDLE& shared_h, DWORD size,
mapname = NULL;
else
mapname = shared_name (map_buf, name, n);
- if (!(shared_h = CreateFileMapping (INVALID_HANDLE_VALUE, psa,
- PAGE_READWRITE, 0, size, mapname)))
+ if (m == SH_JUSTOPEN)
+ shared_h = OpenFileMapping (access, FALSE, mapname);
+ else
+ {
+ shared_h = CreateFileMapping (INVALID_HANDLE_VALUE, psa, PAGE_READWRITE,
+ 0, size, mapname);
+ if (GetLastError () == ERROR_ALREADY_EXISTS)
+ m = SH_JUSTOPEN;
+ }
+ if (shared_h)
+ /* ok! */;
+ else if (m != SH_JUSTOPEN)
api_fatal ("CreateFileMapping %s, %E. Terminating.", mapname);
+ else
+ return NULL;
}
shared = (shared_info *)
- MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, addr);
+ MapViewOfFileEx (shared_h, access, 0, 0, 0, addr);
- if (!shared)
+ if (!shared && addr)
{
/* Probably win95, so try without specifying the address. */
shared = (shared_info *) MapViewOfFileEx (shared_h,
FILE_MAP_READ|FILE_MAP_WRITE,
- 0, 0, 0, 0);
+ 0, 0, 0, NULL);
#ifdef DEBUGGING
if (wincap.is_winnt ())
system_printf ("relocating shared object %s(%d) from %p to %p on Windows NT", name, n, addr, shared);
@@ -165,9 +174,10 @@ user_shared_initialize (bool reinit)
if (!cygwin_user_h)
cygheap->user.get_windows_id (name);
+ shared_locations sh_user_shared = SH_USER_SHARED;
user_shared = (user_info *) open_shared (name, USER_VERSION,
cygwin_user_h, sizeof (user_info),
- SH_USER_SHARED, &sec_none);
+ sh_user_shared, &sec_none);
debug_printf ("opening user shared for '%s' at %p", name, user_shared);
ProtectHandleINH (cygwin_user_h);
debug_printf ("user shared version %x", user_shared->version);
@@ -236,11 +246,12 @@ memory_init ()
}
/* Initialize general shared memory */
+ shared_locations sh_cygwin_shared = SH_CYGWIN_SHARED;
cygwin_shared = (shared_info *) open_shared ("shared",
CYGWIN_VERSION_SHARED_DATA,
cygheap->shared_h,
sizeof (*cygwin_shared),
- SH_CYGWIN_SHARED);
+ sh_cygwin_shared);
cygwin_shared->initialize ();
ProtectHandleINH (cygheap->shared_h);