Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-10-15 11:03:45 +0400
committerChristopher Faylor <me@cgf.cx>2002-10-15 11:03:45 +0400
commitfdb28b5e5f813721add3ba2b261dfe78f3b895cb (patch)
tree8bf842ee31e89bf925b36aaa4c882d77cc3bb544
parent54030e2146f80ba055f4b7efa20467beab1487e9 (diff)
* 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.
-rw-r--r--winsup/cygwin/ChangeLog19
-rw-r--r--winsup/cygwin/child_info.h4
-rw-r--r--winsup/cygwin/dcrt0.cc13
-rw-r--r--winsup/cygwin/fhandler_console.cc11
-rw-r--r--winsup/cygwin/fork.cc2
-rw-r--r--winsup/cygwin/pinfo.cc14
-rw-r--r--winsup/cygwin/pinfo.h1
-rw-r--r--winsup/cygwin/shared.cc55
-rw-r--r--winsup/cygwin/shared_info.h20
9 files changed, 96 insertions, 43 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 80325cc37..bd35ed16e 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,22 @@
+2002-10-15 Christopher Faylor <cgf@redhat.com>
+
+ * 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.
+
2002-10-14 Christopher Faylor <cgf@redhat.com>
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset.
diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h
index 4cc09b74b..2ac015222 100644
--- a/winsup/cygwin/child_info.h
+++ b/winsup/cygwin/child_info.h
@@ -29,7 +29,7 @@ enum
#define EXEC_MAGIC_SIZE sizeof(child_info)
-#define CURR_CHILD_INFO_MAGIC 0x64848c11U
+#define CURR_CHILD_INFO_MAGIC 0x8e0899faU
/* NOTE: Do not make gratuitous changes to the names or organization of the
below class. The layout is checksummed to determine compatibility between
@@ -61,8 +61,6 @@ class child_info_fork: public child_info
public:
HANDLE forker_finished;// for synchronization with child
DWORD stacksize; // size of parent stack
- mount_info *mount_table;// location of mount table in parent
- _pinfo *myself_addr; // where myself shared memory lives in the parent
jmp_buf jmp; // where child will jump to
void *stacktop; // location of top of parent stack
void *stackbottom; // location of bottom of parent stack
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index e7babe08b..4270c58a4 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -572,7 +572,9 @@ dll_crt0_1 ()
int envc = 0;
char **envp = NULL;
- if (child_proc_info)
+ if (!child_proc_info)
+ memory_init ();
+ else
{
bool close_ppid_handle = false;
bool close_hexec_proc = false;
@@ -581,10 +583,9 @@ dll_crt0_1 ()
case _PROC_FORK:
cygheap_fixup_in_child (0);
alloc_stack (fork_info);
- mount_table = fork_info->mount_table;
- myself_addr = fork_info->myself_addr;
- set_myself (mypid);
close_ppid_handle = !!child_proc_info->pppid_handle;
+ memory_init ();
+ set_myself (mypid);
break;
case _PROC_SPAWN:
/* Have to delay closes until after cygheap is setup */
@@ -596,6 +597,7 @@ dll_crt0_1 ()
around:
HANDLE h;
cygheap_fixup_in_child (1);
+ memory_init ();
if (!spawn_info->moreinfo->myself_pinfo ||
!DuplicateHandle (hMainProc, spawn_info->moreinfo->myself_pinfo,
hMainProc, &h, 0, 0,
@@ -622,9 +624,6 @@ dll_crt0_1 ()
CloseHandle (child_proc_info->pppid_handle);
}
- /* Initialize the cygwin subsystem if this is the first process,
- or attach to shared data structures if it's already running. */
- memory_init ();
cygthread::init ();
ProtectHandle (hMainProc);
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index a43dad11f..5be009eb9 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -85,14 +85,7 @@ str_to_con (char *d, const char *s, DWORD sz)
const char * get_nonascii_key (INPUT_RECORD&, char *);
-struct console_state
-{
- tty_min tty_min_state;
- dev_console dev_state;
-};
-
static console_state NO_COPY *shared_console_info;
-static console_state *shared_console_info_save;
dev_console NO_COPY *fhandler_console::dev_state;
@@ -104,10 +97,10 @@ fhandler_console::get_tty_stuff (int flags = 0)
if (dev_state)
return &shared_console_info->tty_min_state;
- shared_console_info = shared_console_info_save =
+ shared_console_info =
(console_state *) open_shared (NULL, 0, cygheap->console_h,
sizeof (*shared_console_info),
- shared_console_info_save);
+ SH_SHARED_CONSOLE);
dev_state = &shared_console_info->dev_state;
ProtectHandleINH (cygheap->console_h);
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index f104e4196..c3045c4b9 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -422,8 +422,6 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
init_child_info (PROC_FORK, &ch, 1, subproc_ready);
ch.forker_finished = forker_finished;
- ch.mount_table = mount_table;
- ch.myself_addr = myself_addr;
stack_base (ch);
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 349545440..0ffd00edd 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -27,13 +27,13 @@ details. */
#include <ntdef.h>
#include "ntdll.h"
#include "cygthread.h"
+#include "shared_info.h"
static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0};
pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks
HANDLE hexec_proc;
-_pinfo NO_COPY *myself_addr;
void __stdcall
pinfo_fixup_after_fork ()
@@ -128,17 +128,13 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h)
}
void *mapaddr;
- bool itsme;
if (!(flag & PID_MYSELF))
- {
- mapaddr = NULL;
- itsme = false;
- }
+ mapaddr = NULL;
else
{
flag &= ~PID_MYSELF;
- mapaddr = myself_addr;
- itsme = true;
+ HANDLE hdummy;
+ mapaddr = open_shared (NULL, 0, hdummy, 0, SH_MYSELF);
}
int createit = flag & (PID_IN_USE | PID_EXECED);
@@ -182,8 +178,6 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h)
procinfo = (_pinfo *) MapViewOfFileEx (h, FILE_MAP_READ | FILE_MAP_WRITE,
0, 0, 0, mapaddr);
ProtectHandle1 (h, pinfo_shared_handle);
- if (itsme)
- myself_addr = procinfo;
if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR)
&& cygwin_pid (procinfo->dwProcessId) != procinfo->pid)
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index f99b6aa5e..dcb814bcc 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -202,7 +202,6 @@ cygwin_pid (pid_t pid)
void __stdcall pinfo_init (char **, int);
void __stdcall set_myself (pid_t pid, HANDLE h = NULL);
extern pinfo myself;
-extern _pinfo *myself_addr;
#define _P_VFORK 0
extern void __stdcall pinfo_fixup_after_fork ();
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);
diff --git a/winsup/cygwin/shared_info.h b/winsup/cygwin/shared_info.h
index 232575bc7..a39275e49 100644
--- a/winsup/cygwin/shared_info.h
+++ b/winsup/cygwin/shared_info.h
@@ -161,6 +161,14 @@ extern shared_info *cygwin_shared;
extern mount_info *mount_table;
extern HANDLE cygwin_mount_h;
+enum shared_locations
+{
+ SH_CYGWIN_SHARED,
+ SH_MOUNT_TABLE,
+ SH_SHARED_CONSOLE,
+ SH_MYSELF,
+ SH_TOTAL_SIZE
+};
void __stdcall memory_init ();
#define shared_align_past(p) \
@@ -169,8 +177,14 @@ void __stdcall memory_init ();
system_info.dwAllocationGranularity)))
#define cygwin_shared_address ((void *) 0xa000000)
-#define mount_table_address shared_align_past (cygwin_shared)
-#define cygheap_address shared_align_past ((mount_info *) shared_align_past (cygwin_shared))
+
+#ifdef FHDEVN
+struct console_state
+{
+ tty_min tty_min_state;
+ dev_console dev_state;
+};
+#endif
char *__stdcall shared_name (const char *, int);
-void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr);
+void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locations);