4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-22 00:38:06 +08:00

* 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.
This commit is contained in:
Christopher Faylor 2002-10-15 07:03:45 +00:00
parent 54030e2146
commit fdb28b5e5f
9 changed files with 96 additions and 43 deletions

View File

@ -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> 2002-10-14 Christopher Faylor <cgf@redhat.com>
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset. * child_info.h (CURR_CHILD_INFO_MAGIC): Reset.

View File

@ -29,7 +29,7 @@ enum
#define EXEC_MAGIC_SIZE sizeof(child_info) #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 /* NOTE: Do not make gratuitous changes to the names or organization of the
below class. The layout is checksummed to determine compatibility between below class. The layout is checksummed to determine compatibility between
@ -61,8 +61,6 @@ class child_info_fork: public child_info
public: public:
HANDLE forker_finished;// for synchronization with child HANDLE forker_finished;// for synchronization with child
DWORD stacksize; // size of parent stack 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 jmp_buf jmp; // where child will jump to
void *stacktop; // location of top of parent stack void *stacktop; // location of top of parent stack
void *stackbottom; // location of bottom of parent stack void *stackbottom; // location of bottom of parent stack

View File

@ -572,7 +572,9 @@ dll_crt0_1 ()
int envc = 0; int envc = 0;
char **envp = NULL; char **envp = NULL;
if (child_proc_info) if (!child_proc_info)
memory_init ();
else
{ {
bool close_ppid_handle = false; bool close_ppid_handle = false;
bool close_hexec_proc = false; bool close_hexec_proc = false;
@ -581,10 +583,9 @@ dll_crt0_1 ()
case _PROC_FORK: case _PROC_FORK:
cygheap_fixup_in_child (0); cygheap_fixup_in_child (0);
alloc_stack (fork_info); 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; close_ppid_handle = !!child_proc_info->pppid_handle;
memory_init ();
set_myself (mypid);
break; break;
case _PROC_SPAWN: case _PROC_SPAWN:
/* Have to delay closes until after cygheap is setup */ /* Have to delay closes until after cygheap is setup */
@ -596,6 +597,7 @@ dll_crt0_1 ()
around: around:
HANDLE h; HANDLE h;
cygheap_fixup_in_child (1); cygheap_fixup_in_child (1);
memory_init ();
if (!spawn_info->moreinfo->myself_pinfo || if (!spawn_info->moreinfo->myself_pinfo ||
!DuplicateHandle (hMainProc, spawn_info->moreinfo->myself_pinfo, !DuplicateHandle (hMainProc, spawn_info->moreinfo->myself_pinfo,
hMainProc, &h, 0, 0, hMainProc, &h, 0, 0,
@ -622,9 +624,6 @@ dll_crt0_1 ()
CloseHandle (child_proc_info->pppid_handle); 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 (); cygthread::init ();
ProtectHandle (hMainProc); ProtectHandle (hMainProc);

View File

@ -85,14 +85,7 @@ str_to_con (char *d, const char *s, DWORD sz)
const char * get_nonascii_key (INPUT_RECORD&, char *); 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 NO_COPY *shared_console_info;
static console_state *shared_console_info_save;
dev_console NO_COPY *fhandler_console::dev_state; dev_console NO_COPY *fhandler_console::dev_state;
@ -104,10 +97,10 @@ fhandler_console::get_tty_stuff (int flags = 0)
if (dev_state) if (dev_state)
return &shared_console_info->tty_min_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, (console_state *) open_shared (NULL, 0, cygheap->console_h,
sizeof (*shared_console_info), sizeof (*shared_console_info),
shared_console_info_save); SH_SHARED_CONSOLE);
dev_state = &shared_console_info->dev_state; dev_state = &shared_console_info->dev_state;
ProtectHandleINH (cygheap->console_h); ProtectHandleINH (cygheap->console_h);

View File

@ -422,8 +422,6 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
init_child_info (PROC_FORK, &ch, 1, subproc_ready); init_child_info (PROC_FORK, &ch, 1, subproc_ready);
ch.forker_finished = forker_finished; ch.forker_finished = forker_finished;
ch.mount_table = mount_table;
ch.myself_addr = myself_addr;
stack_base (ch); stack_base (ch);

View File

@ -27,13 +27,13 @@ details. */
#include <ntdef.h> #include <ntdef.h>
#include "ntdll.h" #include "ntdll.h"
#include "cygthread.h" #include "cygthread.h"
#include "shared_info.h"
static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0}; static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0};
pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks
HANDLE hexec_proc; HANDLE hexec_proc;
_pinfo NO_COPY *myself_addr;
void __stdcall void __stdcall
pinfo_fixup_after_fork () pinfo_fixup_after_fork ()
@ -128,17 +128,13 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h)
} }
void *mapaddr; void *mapaddr;
bool itsme;
if (!(flag & PID_MYSELF)) if (!(flag & PID_MYSELF))
{ mapaddr = NULL;
mapaddr = NULL;
itsme = false;
}
else else
{ {
flag &= ~PID_MYSELF; flag &= ~PID_MYSELF;
mapaddr = myself_addr; HANDLE hdummy;
itsme = true; mapaddr = open_shared (NULL, 0, hdummy, 0, SH_MYSELF);
} }
int createit = flag & (PID_IN_USE | PID_EXECED); 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, procinfo = (_pinfo *) MapViewOfFileEx (h, FILE_MAP_READ | FILE_MAP_WRITE,
0, 0, 0, mapaddr); 0, 0, 0, mapaddr);
ProtectHandle1 (h, pinfo_shared_handle); ProtectHandle1 (h, pinfo_shared_handle);
if (itsme)
myself_addr = procinfo;
if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR) if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR)
&& cygwin_pid (procinfo->dwProcessId) != procinfo->pid) && cygwin_pid (procinfo->dwProcessId) != procinfo->pid)

View File

@ -202,7 +202,6 @@ cygwin_pid (pid_t pid)
void __stdcall pinfo_init (char **, int); void __stdcall pinfo_init (char **, int);
void __stdcall set_myself (pid_t pid, HANDLE h = NULL); void __stdcall set_myself (pid_t pid, HANDLE h = NULL);
extern pinfo myself; extern pinfo myself;
extern _pinfo *myself_addr;
#define _P_VFORK 0 #define _P_VFORK 0
extern void __stdcall pinfo_fixup_after_fork (); extern void __stdcall pinfo_fixup_after_fork ();

View File

@ -26,6 +26,7 @@ details. */
#include "shared_info_magic.h" #include "shared_info_magic.h"
#include "registry.h" #include "registry.h"
#include "cygwin_version.h" #include "cygwin_version.h"
#include "child_info.h"
shared_info NO_COPY *cygwin_shared; shared_info NO_COPY *cygwin_shared;
mount_info NO_COPY *mount_table; mount_info NO_COPY *mount_table;
@ -43,10 +44,48 @@ shared_name (const char *str, int num)
return buf; return buf;
} }
#define page_const (65535)
#define pround(n) (((size_t) (n) + page_const) & ~page_const)
void * __stdcall 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; 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) 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."); api_fatal ("CreateFileMapping, %E. Terminating.");
} }
shared = (shared_info *) MapViewOfFileEx (shared_h, shared = (shared_info *)
FILE_MAP_READ | FILE_MAP_WRITE, MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, addr);
0, 0, 0, addr);
if (!shared) if (!shared)
{ {
@ -115,13 +153,14 @@ shared_info::initialize ()
void __stdcall void __stdcall
memory_init () memory_init ()
{ {
getpagesize ();
/* Initialize general shared memory */ /* Initialize general shared memory */
HANDLE shared_h = cygheap ? cygheap->shared_h : NULL; HANDLE shared_h = cygheap ? cygheap->shared_h : NULL;
cygwin_shared = (shared_info *) open_shared ("shared", cygwin_shared = (shared_info *) open_shared ("shared",
CYGWIN_VERSION_SHARED_DATA, CYGWIN_VERSION_SHARED_DATA,
shared_h, shared_h,
sizeof (*cygwin_shared), sizeof (*cygwin_shared),
cygwin_shared_address); SH_CYGWIN_SHARED);
cygwin_shared->initialize (); cygwin_shared->initialize ();
@ -142,13 +181,13 @@ memory_init ()
cygheap->shared_h = shared_h; cygheap->shared_h = shared_h;
ProtectHandleINH (cygheap->shared_h); ProtectHandleINH (cygheap->shared_h);
getpagesize ();
heap_init (); heap_init ();
mount_table = (mount_info *) open_shared (user_name, MOUNT_VERSION, mount_table = (mount_info *) open_shared (user_name, MOUNT_VERSION,
cygwin_mount_h, sizeof (mount_info), cygwin_mount_h, sizeof (mount_info),
mount_table); SH_MOUNT_TABLE);
debug_printf ("opening mount table for '%s' at %p", cygheap->user.name (), debug_printf ("opening mount table for '%s' at %p", cygheap->user.name (),
mount_table_address); mount_table);
ProtectHandleINH (cygwin_mount_h); ProtectHandleINH (cygwin_mount_h);
debug_printf ("mount table version %x at %p", mount_table->version, mount_table); debug_printf ("mount table version %x at %p", mount_table->version, mount_table);

View File

@ -161,6 +161,14 @@ extern shared_info *cygwin_shared;
extern mount_info *mount_table; extern mount_info *mount_table;
extern HANDLE cygwin_mount_h; 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 (); void __stdcall memory_init ();
#define shared_align_past(p) \ #define shared_align_past(p) \
@ -169,8 +177,14 @@ void __stdcall memory_init ();
system_info.dwAllocationGranularity))) system_info.dwAllocationGranularity)))
#define cygwin_shared_address ((void *) 0xa000000) #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); 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);