diff options
author | Christopher Faylor <me@cgf.cx> | 2002-10-15 07:03:45 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2002-10-15 07:03:45 +0000 |
commit | fdb28b5e5f813721add3ba2b261dfe78f3b895cb (patch) | |
tree | 8bf842ee31e89bf925b36aaa4c882d77cc3bb544 /winsup/cygwin/shared.cc | |
parent | 54030e2146f80ba055f4b7efa20467beab1487e9 (diff) | |
download | cygnal-fdb28b5e5f813721add3ba2b261dfe78f3b895cb.tar.gz cygnal-fdb28b5e5f813721add3ba2b261dfe78f3b895cb.tar.bz2 cygnal-fdb28b5e5f813721add3ba2b261dfe78f3b895cb.zip |
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset.
(child_info_fork::mount_table): Remove.
(child_info_fork::myself_addr): Remove.
* fork.cc (fork_child): Don't set either of the above.
* dcrt0.cc (dll_crt0_1): Call memory_init as early as possible.
* fhandler_console.cc (console_state): Move to shared_info.h.
(fhandler_console::get_tty_stuff): Reflect open_shared arg change.
* pinfo.cc (myself_addr): Remove definition.
(pinfo::init): Get myself address from open_shared.
* pinfo.h (myself_addr): Remove declaration.
* shared.cc (open_shared): Rework so that known shared memory locations are
protected. Take shared memory type as fifth argument.
(memory_init): Reflect open_shared arg change.
* shared_info.h (shared_locations): New enum.
(console_state): Move here.
(open_shared): Reflect open_shared arg change in declaration.
Diffstat (limited to 'winsup/cygwin/shared.cc')
-rw-r--r-- | winsup/cygwin/shared.cc | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc index 61ec95e13..113e7f542 100644 --- a/winsup/cygwin/shared.cc +++ b/winsup/cygwin/shared.cc @@ -26,6 +26,7 @@ details. */ #include "shared_info_magic.h" #include "registry.h" #include "cygwin_version.h" +#include "child_info.h" shared_info NO_COPY *cygwin_shared; mount_info NO_COPY *mount_table; @@ -43,10 +44,48 @@ shared_name (const char *str, int num) return buf; } +#define page_const (65535) +#define pround(n) (((size_t) (n) + page_const) & ~page_const) + void * __stdcall -open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr) +open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locations m) { void *shared; + static char *offsets[] = + { + (char *) cygwin_shared_address, + (char *) cygwin_shared_address + + pround (sizeof (shared_info)), + (char *) cygwin_shared_address + + pround (sizeof (shared_info)) + + pround (sizeof (mount_info)), + (char *) cygwin_shared_address + + pround (sizeof (shared_info)) + + pround (sizeof (mount_info)) + + pround (sizeof (console_state)), + (char *) cygwin_shared_address + + pround (sizeof (shared_info)) + + pround (sizeof (mount_info)) + + pround (sizeof (console_state)) + + pround (sizeof (_pinfo)) + }; + + if (m == SH_CYGWIN_SHARED) + { + for (int i = SH_CYGWIN_SHARED; i < SH_TOTAL_SIZE; i++) + if (!VirtualAlloc (offsets[i], offsets[i + 1] - offsets[i], + MEM_RESERVE, PAGE_NOACCESS)) + continue; /* oh well */ + if (!child_proc_info) + for (DWORD s = 0x950000; s <= 0xa40000; s += 0x1000) + VirtualAlloc ((void *) s, 4, MEM_RESERVE, PAGE_NOACCESS); + } + + void *addr = offsets[m]; + (void) VirtualFree (addr, 0, MEM_RELEASE); + + if (!size) + return addr; if (!shared_h) { @@ -65,9 +104,8 @@ open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr) api_fatal ("CreateFileMapping, %E. Terminating."); } - shared = (shared_info *) MapViewOfFileEx (shared_h, - FILE_MAP_READ | FILE_MAP_WRITE, - 0, 0, 0, addr); + shared = (shared_info *) + MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, addr); if (!shared) { @@ -115,13 +153,14 @@ shared_info::initialize () void __stdcall memory_init () { + getpagesize (); /* Initialize general shared memory */ HANDLE shared_h = cygheap ? cygheap->shared_h : NULL; cygwin_shared = (shared_info *) open_shared ("shared", CYGWIN_VERSION_SHARED_DATA, shared_h, sizeof (*cygwin_shared), - cygwin_shared_address); + SH_CYGWIN_SHARED); cygwin_shared->initialize (); @@ -142,13 +181,13 @@ memory_init () cygheap->shared_h = shared_h; ProtectHandleINH (cygheap->shared_h); - getpagesize (); heap_init (); + mount_table = (mount_info *) open_shared (user_name, MOUNT_VERSION, cygwin_mount_h, sizeof (mount_info), - mount_table); + SH_MOUNT_TABLE); debug_printf ("opening mount table for '%s' at %p", cygheap->user.name (), - mount_table_address); + mount_table); ProtectHandleINH (cygwin_mount_h); debug_printf ("mount table version %x at %p", mount_table->version, mount_table); |