* child_info.h (child_proc_info): Declare as base class.

(spawn_info): Declare as alias of child_proc_info to aid debugging.
(fork_info): Ditto.
* cygheap.cc (cygheap_fixup_in_child): Use child_proc_info global rather than
parameter.
* cygheap.h (cygheap_fixup_in_child): Reflect above change in declaration.
* dcrt0.cc (_dll_crt0): Move 'si' definition here.  Assign child_proc_info.
(dll_crt0_1): Accommodate cygheap_fixup_in_child and *_info changes.
* environ.cc (spenv::retrieve): Make regparm.
* environ.h (environ_init): Ditto.
(win_env::add_cache): Ditto.
(build_env): Ditto.
(getwinenv): Ditto.
* fork.cc (sync_with_parent): Use fork_info global.
(fork_child): Ditto.
This commit is contained in:
Christopher Faylor 2002-06-15 21:59:32 +00:00
parent 5ae611458b
commit 6ea3e429df
8 changed files with 71 additions and 46 deletions

View File

@ -1,3 +1,23 @@
2002-06-15 Christopher Faylor <cgf@redhat.com>
* child_info.h (child_proc_info): Declare as base class.
(spawn_info): Declare as alias of child_proc_info to aid debugging.
(fork_info): Ditto.
* cygheap.cc (cygheap_fixup_in_child): Use child_proc_info global
rather than parameter.
* cygheap.h (cygheap_fixup_in_child): Reflect above change in
declaration.
* dcrt0.cc (_dll_crt0): Move 'si' definition here. Assign
child_proc_info.
(dll_crt0_1): Accommodate cygheap_fixup_in_child and *_info changes.
* environ.cc (spenv::retrieve): Make regparm.
* environ.h (environ_init): Ditto.
(win_env::add_cache): Ditto.
(build_env): Ditto.
(getwinenv): Ditto.
* fork.cc (sync_with_parent): Use fork_info global.
(fork_child): Ditto.
2002-06-14 Christopher Faylor <cgf@redhat.com> 2002-06-14 Christopher Faylor <cgf@redhat.com>
* uinfo.cc (cygheap_user::ontherange): Don't set HOMEDRIVE or HOMEPATH * uinfo.cc (cygheap_user::ontherange): Don't set HOMEDRIVE or HOMEPATH

View File

@ -108,4 +108,6 @@ public:
void __stdcall init_child_info (DWORD, child_info *, int, HANDLE); void __stdcall init_child_info (DWORD, child_info *, int, HANDLE);
extern child_info_fork *child_proc_info; extern child_info *child_proc_info;
extern child_info_spawn *spawn_info __attribute__ ((alias ("child_proc_info")));
extern child_info_fork *fork_info __attribute__ ((alias ("child_proc_info")));

View File

@ -110,18 +110,18 @@ cygheap_setup_for_child_cleanup (void *newcygheap, child_info *ci,
/* Called by fork or spawn to reallocate cygwin heap */ /* Called by fork or spawn to reallocate cygwin heap */
void __stdcall void __stdcall
cygheap_fixup_in_child (child_info *ci, bool execed) cygheap_fixup_in_child (bool execed)
{ {
cygheap = ci->cygheap; cygheap = child_proc_info->cygheap;
cygheap_max = ci->cygheap_max; cygheap_max = child_proc_info->cygheap_max;
void *addr = !wincap.map_view_of_file_ex_sucks () ? cygheap : NULL; void *addr = !wincap.map_view_of_file_ex_sucks () ? cygheap : NULL;
void *newaddr; void *newaddr;
newaddr = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, addr); newaddr = MapViewOfFileEx (child_proc_info->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, addr);
if (newaddr != cygheap) if (newaddr != cygheap)
{ {
if (!newaddr) if (!newaddr)
newaddr = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); newaddr = MapViewOfFileEx (child_proc_info->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
DWORD n = (DWORD) cygheap_max - (DWORD) cygheap; DWORD n = (DWORD) cygheap_max - (DWORD) cygheap;
/* Reserve cygwin heap in same spot as parent */ /* Reserve cygwin heap in same spot as parent */
if (!VirtualAlloc (cygheap, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS)) if (!VirtualAlloc (cygheap, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS))
@ -144,7 +144,7 @@ cygheap_fixup_in_child (child_info *ci, bool execed)
UnmapViewOfFile (newaddr); UnmapViewOfFile (newaddr);
} }
ForceCloseHandle1 (ci->cygheap_h, passed_cygheap_h); ForceCloseHandle1 (child_proc_info->cygheap_h, passed_cygheap_h);
cygheap_init (); cygheap_init ();

View File

@ -276,7 +276,7 @@ class cygheap_fdget : public cygheap_fdmanip
class child_info; class child_info;
void *__stdcall cygheap_setup_for_child (child_info *ci, bool dup_later) __attribute__ ((regparm(2))); void *__stdcall cygheap_setup_for_child (child_info *ci, bool dup_later) __attribute__ ((regparm(2)));
void __stdcall cygheap_setup_for_child_cleanup (void *, child_info *, bool) __attribute__ ((regparm(3))); void __stdcall cygheap_setup_for_child_cleanup (void *, child_info *, bool) __attribute__ ((regparm(3)));
void __stdcall cygheap_fixup_in_child (child_info *, bool); void __stdcall cygheap_fixup_in_child (bool);
extern "C" { extern "C" {
void __stdcall cfree (void *) __attribute__ ((regparm(1))); void __stdcall cfree (void *) __attribute__ ((regparm(1)));
void *__stdcall cmalloc (cygheap_types, DWORD) __attribute__ ((regparm(2))); void *__stdcall cmalloc (cygheap_types, DWORD) __attribute__ ((regparm(2)));

View File

@ -451,10 +451,7 @@ check_sanity_and_sync (per_process *p)
signal_shift_subtract = 0; signal_shift_subtract = 0;
} }
static NO_COPY STARTUPINFO si; child_info NO_COPY *child_proc_info = NULL;
# define fork_info ((struct child_info_fork *)(si.lpReserved2))
# define spawn_info ((struct child_info_spawn *)(si.lpReserved2))
child_info_fork NO_COPY *child_proc_info = NULL;
static MEMORY_BASIC_INFORMATION sm; static MEMORY_BASIC_INFORMATION sm;
#define CYGWIN_GUARD ((wincap.has_page_guard ()) ? PAGE_GUARD : PAGE_NOACCESS) #define CYGWIN_GUARD ((wincap.has_page_guard ()) ? PAGE_GUARD : PAGE_NOACCESS)
@ -588,10 +585,10 @@ dll_crt0_1 ()
switch (child_proc_info->type) switch (child_proc_info->type)
{ {
case _PROC_FORK: case _PROC_FORK:
cygheap_fixup_in_child (child_proc_info, 0); cygheap_fixup_in_child (0);
alloc_stack (fork_info); alloc_stack (fork_info);
set_myself (mypid); set_myself (mypid);
ProtectHandle (child_proc_info->forker_finished); ProtectHandle (fork_info->forker_finished);
break; break;
case _PROC_SPAWN: case _PROC_SPAWN:
if (spawn_info->hexec_proc) if (spawn_info->hexec_proc)
@ -601,7 +598,7 @@ dll_crt0_1 ()
hexec_proc = spawn_info->hexec_proc; hexec_proc = spawn_info->hexec_proc;
around: around:
HANDLE h; HANDLE h;
cygheap_fixup_in_child (spawn_info, 1); cygheap_fixup_in_child (1);
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,
@ -805,6 +802,7 @@ _dll_crt0 ()
DECLARE_TLS_STORAGE; DECLARE_TLS_STORAGE;
initial_env (); initial_env ();
char zeros[sizeof (fork_info->zero)] = {0}; char zeros[sizeof (fork_info->zero)] = {0};
static NO_COPY STARTUPINFO si;
#ifdef DEBUGGING #ifdef DEBUGGING
strace.microseconds (); strace.microseconds ();
#endif #endif
@ -822,42 +820,42 @@ _dll_crt0 ()
&hMainThread, 0, false, DUPLICATE_SAME_ACCESS); &hMainThread, 0, false, DUPLICATE_SAME_ACCESS);
GetStartupInfo (&si); GetStartupInfo (&si);
child_proc_info = (child_info *) si.lpReserved2;
if (si.cbReserved2 >= EXEC_MAGIC_SIZE && if (si.cbReserved2 >= EXEC_MAGIC_SIZE &&
memcmp (fork_info->zero, zeros, sizeof (zeros)) == 0) memcmp (child_proc_info->zero, zeros, sizeof (zeros)) == 0)
{ {
if ((fork_info->intro & OPROC_MAGIC_MASK) == OPROC_MAGIC_GENERIC) if ((child_proc_info->intro & OPROC_MAGIC_MASK) == OPROC_MAGIC_GENERIC)
multiple_cygwin_problem ("proc", fork_info->intro, 0); multiple_cygwin_problem ("proc", child_proc_info->intro, 0);
else if (fork_info->intro == PROC_MAGIC_GENERIC else if (child_proc_info->intro == PROC_MAGIC_GENERIC
&& fork_info->magic != CHILD_INFO_MAGIC) && child_proc_info->magic != CHILD_INFO_MAGIC)
multiple_cygwin_problem ("proc", fork_info->magic, CHILD_INFO_MAGIC); multiple_cygwin_problem ("proc", child_proc_info->magic, CHILD_INFO_MAGIC);
unsigned should_be_cb = 0; unsigned should_be_cb = 0;
switch (fork_info->type) switch (child_proc_info->type)
{ {
case _PROC_FORK: case _PROC_FORK:
user_data->forkee = fork_info->cygpid; user_data->forkee = child_proc_info->cygpid;
should_be_cb = sizeof (child_info_fork); should_be_cb = sizeof (child_info_fork);
/* fall through */; /* fall through */;
case _PROC_SPAWN: case _PROC_SPAWN:
if (fork_info->pppid_handle) if (child_proc_info->pppid_handle)
CloseHandle (fork_info->pppid_handle); CloseHandle (child_proc_info->pppid_handle);
/* fall through */; /* fall through */;
case _PROC_EXEC: case _PROC_EXEC:
if (!should_be_cb) if (!should_be_cb)
should_be_cb = sizeof (child_info); should_be_cb = sizeof (child_info);
if (should_be_cb != fork_info->cb) if (should_be_cb != child_proc_info->cb)
multiple_cygwin_problem ("proc size", fork_info->cb, should_be_cb); multiple_cygwin_problem ("proc size", child_proc_info->cb, should_be_cb);
else if (sizeof (fhandler_union) != fork_info->fhandler_union_cb) else if (sizeof (fhandler_union) != child_proc_info->fhandler_union_cb)
multiple_cygwin_problem ("fhandler size", fork_info->fhandler_union_cb, sizeof (fhandler_union)); multiple_cygwin_problem ("fhandler size", child_proc_info->fhandler_union_cb, sizeof (fhandler_union));
else else
{ {
child_proc_info = fork_info;
cygwin_mount_h = child_proc_info->mount_h; cygwin_mount_h = child_proc_info->mount_h;
mypid = child_proc_info->cygpid; mypid = child_proc_info->cygpid;
break; break;
} }
default: default:
system_printf ("unknown exec type %d", fork_info->type); system_printf ("unknown exec type %d", child_proc_info->type);
fork_info = NULL; child_proc_info = NULL;
break; break;
} }
} }

View File

@ -754,7 +754,8 @@ struct spenv
{ {
const char *name; const char *name;
const char * (cygheap_user::*from_cygheap) (); const char * (cygheap_user::*from_cygheap) ();
char *retrieve (bool, const char * const = NULL, int = 0); char *retrieve (bool, const char * const = NULL, int = 0)
__attribute__ ((regparm (3)));
}; };
/* Keep this list in upper case and sorted */ /* Keep this list in upper case and sorted */

View File

@ -9,7 +9,8 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */ details. */
/* Initialize the environment */ /* Initialize the environment */
void environ_init (char **, int); void environ_init (char **, int)
__attribute__ ((regparm (2)));
/* The structure below is used to control conversion to/from posix-style /* The structure below is used to control conversion to/from posix-style
file specs. Currently, only PATH and HOME are converted, but PATH file specs. Currently, only PATH and HOME are converted, but PATH
@ -26,15 +27,18 @@ struct win_env
int (*towin32) (const char *, char *); int (*towin32) (const char *, char *);
int (*posix_len) (const char *); int (*posix_len) (const char *);
int (*win32_len) (const char *); int (*win32_len) (const char *);
void add_cache (const char *in_posix, const char *in_native = NULL); void add_cache (const char *in_posix, const char *in_native = NULL)
__attribute__ ((regparm (3)));
const char * get_native () const {return native ? native + namelen : NULL;} const char * get_native () const {return native ? native + namelen : NULL;}
const char * get_posix () const {return posix ? posix : NULL;} const char * get_posix () const {return posix ? posix : NULL;}
}; };
win_env * __stdcall getwinenv (const char *name, const char *posix = NULL); win_env * __stdcall getwinenv (const char *name, const char *posix = NULL)
__attribute__ ((regparm (3)));
void __stdcall update_envptrs (); void __stdcall update_envptrs ();
extern char **__cygwin_environ, ***main_environ; extern char **__cygwin_environ, ***main_environ;
extern "C" char __stdcall **cur_environ (); extern "C" char __stdcall **cur_environ ();
char ** __stdcall build_env (const char * const *envp, char *&envblock, char ** __stdcall build_env (const char * const *envp, char *&envblock,
int &envc, bool need_envblock); int &envc, bool need_envblock)
__attribute__ ((regparm (3)));

View File

@ -196,11 +196,11 @@ sync_with_parent(const char *s, bool hang_self)
{ {
debug_printf ("signalling parent: %s", s); debug_printf ("signalling parent: %s", s);
/* Tell our parent we're waiting. */ /* Tell our parent we're waiting. */
if (!SetEvent (child_proc_info->subproc_ready)) if (!SetEvent (fork_info->subproc_ready))
api_fatal ("fork child - SetEvent for %s failed, %E", s); api_fatal ("fork child - SetEvent for %s failed, %E", s);
if (hang_self) if (hang_self)
{ {
HANDLE h = child_proc_info->forker_finished; HANDLE h = fork_info->forker_finished;
/* Wait for the parent to fill in our stack and heap. /* Wait for the parent to fill in our stack and heap.
Don't wait forever here. If our parent dies we don't want to clog Don't wait forever here. If our parent dies we don't want to clog
the system. If the wait fails, we really can't continue so exit. */ the system. If the wait fails, we really can't continue so exit. */
@ -213,10 +213,10 @@ sync_with_parent(const char *s, bool hang_self)
break; break;
case WAIT_FAILED: case WAIT_FAILED:
if (GetLastError () == ERROR_INVALID_HANDLE && if (GetLastError () == ERROR_INVALID_HANDLE &&
WaitForSingleObject (child_proc_info->forker_finished, 1) != WAIT_FAILED) WaitForSingleObject (fork_info->forker_finished, 1) != WAIT_FAILED)
break; break;
api_fatal ("WFSO failed for %s, fork_finished %p, %E", s, api_fatal ("WFSO failed for %s, fork_finished %p, %E", s,
child_proc_info->forker_finished); fork_info->forker_finished);
break; break;
default: default:
debug_printf ("no problems"); debug_printf ("no problems");
@ -265,10 +265,10 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
fork() was invoked from other than the main thread. Make sure that fork() was invoked from other than the main thread. Make sure that
when the "main" thread exits it calls do_exit, like a normal process. when the "main" thread exits it calls do_exit, like a normal process.
Exit with a status code of 0. */ Exit with a status code of 0. */
if (child_proc_info->stacksize) if (fork_info->stacksize)
{ {
((DWORD *)child_proc_info->stackbottom)[-17] = (DWORD)do_exit; ((DWORD *)fork_info->stackbottom)[-17] = (DWORD)do_exit;
((DWORD *)child_proc_info->stackbottom)[-15] = (DWORD)0; ((DWORD *)fork_info->stackbottom)[-15] = (DWORD)0;
} }
set_file_api_mode (current_codepage); set_file_api_mode (current_codepage);
@ -298,8 +298,8 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
} }
ForceCloseHandle (hParent); ForceCloseHandle (hParent);
(void) ForceCloseHandle (child_proc_info->subproc_ready); (void) ForceCloseHandle (fork_info->subproc_ready);
(void) ForceCloseHandle (child_proc_info->forker_finished); (void) ForceCloseHandle (fork_info->forker_finished);
if (fixup_shms_after_fork ()) if (fixup_shms_after_fork ())
api_fatal ("recreate_shm areas after fork failed"); api_fatal ("recreate_shm areas after fork failed");