(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-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.
#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
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
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;
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 */
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,
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);
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;
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);
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);
#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 ()
}
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);
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)
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 ();
#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;
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)
{
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)
{
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 ();
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);
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) \
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);