From 737a86d32fdaed1b8e29486d793a85896a5e0b95 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 5 Jul 2000 23:46:44 +0000 Subject: [PATCH] * dcrt0.cc (__cygwin_user_data): Initialize. (dll_crt0_1): Eliminate user_data initialization. (dll_crt0): Set up impure_ptr_ptr for older executables. (cygwin_dll_init): Eliminate user_data initializations. (__api_fatal): Don't check for user_data initialization. * dll_init.cc (struct dll): Store entire contents of per_process rather than just a pointer. (add): Ditto. (initOneDll): Don't check for user_data initialization. (DllList::recordDll): Store contents of per_process argument. (DllList::detachDll): Pass address of per_process field. (DllList::initAll): Ditto. (DllList::doGlobalDestructorsOfDlls): Ditto. (DllListIterator::operator *): Ditto. (dll_dllcrt0): Default to __cygwin_user_data if arg is NULL. * include/sys/cygwin.h: Reorganize per_process to eliminate obsolete fields and accomodate new way of initializing. * lib/_cygwin_crt0_common: Initialize _impure_ptr from __cygwin_user_data.impure_ptr. --- winsup/cygwin/ChangeLog | 22 +++++++ winsup/cygwin/dcrt0.cc | 75 +++++++++++++----------- winsup/cygwin/dll_init.cc | 34 +++++------ winsup/cygwin/include/sys/cygwin.h | 21 +++---- winsup/cygwin/lib/_cygwin_crt0_common.cc | 2 +- winsup/cygwin/signal.cc | 20 ------- 6 files changed, 85 insertions(+), 89 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 97d27b096..c6c77f987 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,25 @@ +Wed Jul 5 18:56:58 2000 Christopher Faylor + + * dcrt0.cc (__cygwin_user_data): Initialize. + (dll_crt0_1): Eliminate user_data initialization. + (dll_crt0): Set up impure_ptr_ptr for older executables. + (cygwin_dll_init): Eliminate user_data initializations. + (__api_fatal): Don't check for user_data initialization. + * dll_init.cc (struct dll): Store entire contents of per_process rather + than just a pointer. + (add): Ditto. + (initOneDll): Don't check for user_data initialization. + (DllList::recordDll): Store contents of per_process argument. + (DllList::detachDll): Pass address of per_process field. + (DllList::initAll): Ditto. + (DllList::doGlobalDestructorsOfDlls): Ditto. + (DllListIterator::operator *): Ditto. + (dll_dllcrt0): Default to __cygwin_user_data if arg is NULL. + * include/sys/cygwin.h: Reorganize per_process to eliminate obsolete + fields and accomodate new way of initializing. + * lib/_cygwin_crt0_common: Initialize _impure_ptr from + __cygwin_user_data.impure_ptr. + 2000-07-04 Vadim Egorov * exceptions.cc (try_to_debug): Prevent recursive spawning of JIT diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 9eee8861b..854739ebc 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -49,15 +49,46 @@ HANDLE NO_COPY parent_alive = NULL; measure to allow an orderly transfer to the new, correct sigmask method. */ unsigned int signal_shift_subtract = 1; +#ifdef _MT_SAFE +ResourceLocks _reslock NO_COPY; +MTinterface _mtinterf NO_COPY; +#endif + extern "C" { + void *export_malloc (unsigned int); + void export_free (void *); + void *export_realloc (void *, unsigned int); + void *export_calloc (unsigned int, unsigned int); + /* This is an exported copy of environ which can be used by DLLs which use cygwin.dll. */ char **__cygwin_environ; /* __progname used in getopt error message */ char *__progname = NULL; struct _reent reent_data; - struct per_process __cygwin_user_data; + struct per_process __cygwin_user_data = + {/* initial_sp */ 0, /* magic_biscuit */ 0, + /* dll_major */ CYGWIN_VERSION_DLL_MAJOR, + /* dll_major */ CYGWIN_VERSION_DLL_MINOR, + /* impure_ptr_ptr */ NULL, /*envptr */ NULL, + /* malloc */ export_malloc, /* free */ export_free, + /* realloc */ export_realloc, + /* fmode_ptr */ NULL, /* main */ NULL, /* ctors */ NULL, + /* dtors */ NULL, /* data_start */ NULL, /* data_end */ NULL, + /* bss_start */ NULL, /* bss_end */ NULL, + /* calloc */ export_calloc, + /* premain */ {NULL, NULL, NULL, NULL}, + /* run_ctors_p */ 0, + /* unused */ { 0, 0, 0}, + /* heapbase */ NULL, /* heapptr */ NULL, /* heaptop */ NULL, + /* unused1 */ 0, /* forkee */ 0, /* hmodule */ NULL, + /* api_major */ CYGWIN_VERSION_API_MAJOR, + /* api_minor */ CYGWIN_VERSION_API_MINOR, + /* unused2 */ {0, 0, 0, 0, 0}, + /* resourcelocks */ &_reslock, /* threadinterface */ &_mtinterf, + /* impure_ptr */ &reent_data, + }; }; char *old_title = NULL; @@ -550,11 +581,6 @@ static NO_COPY int mypid = 0; static int argc = 0; static char **argv = NULL; -#ifdef _MT_SAFE -ResourceLocks _reslock NO_COPY; -MTinterface _mtinterf NO_COPY; -#endif - void sigthread::init (const char *s) { @@ -599,14 +625,10 @@ dll_crt0_1 () fork copy code doesn't copy the data in libccrt0.cc (that's why we pass in the per_process struct into the .dll from libccrt0). */ - *(user_data->impure_ptr_ptr) = &reent_data; _impure_ptr = &reent_data; #ifdef _MT_SAFE - user_data->resourcelocks = &_reslock; user_data->resourcelocks->Init(); - - user_data->threadinterface = &_mtinterf; user_data->threadinterface->Init0(); #endif @@ -755,7 +777,7 @@ dll_crt0_1 () sig_send (NULL, __SIGFLUSH); /* also initializes uid, gid */ /* Execute any specified "premain" functions */ - if (user_data->premain[0]) + if (user_data->premain[PREMAIN_LEN / 2]) for (unsigned int i = PREMAIN_LEN / 2; i < PREMAIN_LEN; i++) user_data->premain[i] (argc, argv); @@ -853,21 +875,17 @@ dll_crt0 (per_process *uptr) { /* Set the local copy of the pointer into the user space. */ if (uptr) - *user_data = *uptr; + { + memcpy (user_data, uptr, per_process_overwrite); + *(user_data->impure_ptr_ptr) = &reent_data; + } _dll_crt0 (); } -extern "C" void *export_malloc (unsigned int); -extern "C" void export_free (void *); -extern "C" void *export_realloc (void *, unsigned int); -extern "C" void *export_calloc (unsigned int, unsigned int); - /* This must be called by anyone who uses LoadLibrary to load cygwin1.dll */ -extern "C" void cygwin_dll_init (); -void +extern "C" void cygwin_dll_init () { - static struct _reent *temp_impure; static char **envp; static int _fmode; user_data->heapbase = user_data->heapptr = user_data->heaptop = NULL; @@ -879,21 +897,11 @@ cygwin_dll_init () DuplicateHandle (hMainProc, GetCurrentThread (), hMainProc, &hMainThread, 0, FALSE, DUPLICATE_SAME_ACCESS); - user_data->dll_major = CYGWIN_VERSION_DLL_MAJOR; - user_data->dll_minor = CYGWIN_VERSION_DLL_MINOR; - user_data->api_major = CYGWIN_VERSION_API_MAJOR; - user_data->api_minor = CYGWIN_VERSION_API_MINOR; user_data->magic_biscuit = sizeof (per_process); - user_data->impure_ptr_ptr = &temp_impure; user_data->envptr = &envp; user_data->fmode_ptr = &_fmode; - user_data->malloc = &export_malloc; - user_data->free = &export_free; - user_data->realloc = &export_realloc; - user_data->calloc = &export_calloc; - dll_crt0_1 (); } @@ -1030,11 +1038,8 @@ __api_fatal (const char *fmt, ...) /* We are going down without mercy. Make sure we reset our process_state. */ - if (user_data != NULL) - { - sigproc_terminate (); - myself->record_death (FALSE); - } + sigproc_terminate (); + myself->record_death (FALSE); #ifdef DEBUGGING (void) try_to_debug (); #endif diff --git a/winsup/cygwin/dll_init.cc b/winsup/cygwin/dll_init.cc index a1d217576..38867e18a 100644 --- a/winsup/cygwin/dll_init.cc +++ b/winsup/cygwin/dll_init.cc @@ -29,7 +29,7 @@ typedef enum { NONE, LINK, LOAD } dllType; struct dll { - per_process *p; + per_process p; HMODULE handle; const char *name; dllType type; @@ -128,7 +128,7 @@ add (HMODULE h, char *name, per_process *p, dllType type) _list[_last].name = name && type == LOAD ? strdup (name) : NULL; _list[_last].handle = h; - _list[_last].p = p; + _list[_last].p = *p; _list[_last].type = type; ret = _last++; @@ -139,14 +139,6 @@ static int initOneDll (per_process *p) { /* global variable user_data must be initialized */ - if (user_data == NULL) - { - small_printf ("WARNING: process not inited while trying to init a DLL!\n"); - return 0; - } - - /* init impure_ptr */ - *(p->impure_ptr_ptr) = *(user_data->impure_ptr_ptr); /* FIXME: init environment (useful?) */ *(p->envptr) = *(user_data->envptr); @@ -220,7 +212,7 @@ DllList::recordDll (HMODULE h, per_process *p) if (_dlopenIndex != -1) { _list[_dlopenIndex].handle = h; - _list[_dlopenIndex].p = p; + _list[_dlopenIndex].p = *p; _list[_dlopenIndex].type = type; ret = _dlopenIndex; _dlopenIndex = -1; @@ -248,7 +240,7 @@ DllList::detachDll (int dll_index) if (dll_index != -1) { dll *aDll = &(_list[dll_index]); - doGlobalDTORS (aDll->p); + doGlobalDTORS (&aDll->p); if (aDll->type == LOAD) _numberOfOpenedDlls--; aDll->type = NONE; @@ -274,7 +266,7 @@ DllList::initAll () debug_printf ("call to DllList::initAll"); for (int i = 0; i < _last; i++) { - per_process *p = _list[i].p; + per_process *p = &_list[i].p; if (p) initOneDll (p); } @@ -290,7 +282,7 @@ DllList::doGlobalDestructorsOfDlls () { if (_list[i].type != NONE) { - per_process *p = _list[i].p; + per_process *p = &_list[i].p; if (p) doGlobalDTORS (p); } @@ -418,7 +410,7 @@ DllListIterator::~DllListIterator () DllListIterator::operator per_process* () { - return _list[index ()].p; + return &_list[index ()].p; } void @@ -462,11 +454,15 @@ extern "C" int dll_dllcrt0 (HMODULE h, per_process *p) { + struct _reent reent_data; + if (p == NULL) + p = &__cygwin_user_data; + else + *(p->impure_ptr_ptr) = &reent_data; + /* Partially initialize Cygwin guts for non-cygwin apps. */ - if (dynamically_loaded && (! user_data || user_data->magic_biscuit == 0)) - { - dll_crt0 (p); - } + if (dynamically_loaded && user_data->magic_biscuit == 0) + dll_crt0 (p); return _the.recordDll (h, p); } diff --git a/winsup/cygwin/include/sys/cygwin.h b/winsup/cygwin/include/sys/cygwin.h index ff7821299..7ba5cda24 100644 --- a/winsup/cygwin/include/sys/cygwin.h +++ b/winsup/cygwin/include/sys/cygwin.h @@ -53,9 +53,8 @@ extern void cygwin_premain3 (int argc, char **argv); SIZEOF_PER_PROCESS) to make sure you remember to make the adjustment. */ -class per_process +struct per_process { - public: char *initial_sp; /* The offset of these 3 values can never change. */ @@ -96,19 +95,14 @@ class per_process /* non-zero of ctors have been run. Inherited from parent. */ int run_ctors_p; - /* These will be non-zero if the above (malloc,free,realloc) have been - overridden. */ - /* FIXME: not currently used */ - int __imp_malloc; - int __imp_free; - int __imp_realloc; + DWORD unused[3]; /* Heap management. Inherited from parent. */ void *heapbase; /* bottom of the heap */ void *heapptr; /* current index into heap */ void *heaptop; /* current top of heap */ - HANDLE unused1; /* unused */ + DWORD unused1; /* unused */ /* Non-zero means the task was forked. The value is the pid. Inherited from parent. */ @@ -120,14 +114,13 @@ class per_process DWORD api_minor; /* linked with */ /* For future expansion, so apps won't have to be relinked if we add an item. */ -#ifdef _MT_SAFE + DWORD unused2[5]; + ResourceLocks *resourcelocks; MTinterface *threadinterface; - void *internal_reserved[6]; -#else - void *internal_reserved[8]; -#endif + struct _reent *impure_ptr; }; +#define per_process_overwrite ((unsigned) &(((struct per_process *) NULL)->resourcelocks)) #endif /* __cplusplus */ #ifdef _PATH_PASSWD diff --git a/winsup/cygwin/lib/_cygwin_crt0_common.cc b/winsup/cygwin/lib/_cygwin_crt0_common.cc index ca249c69b..676d46648 100644 --- a/winsup/cygwin/lib/_cygwin_crt0_common.cc +++ b/winsup/cygwin/lib/_cygwin_crt0_common.cc @@ -48,7 +48,7 @@ _cygwin_crt0_common (MainFunc f) __cygwin_user_data.ctors = &__CTOR_LIST__; __cygwin_user_data.dtors = &__DTOR_LIST__; __cygwin_user_data.envptr = &environ; - __cygwin_user_data.impure_ptr_ptr = &_impure_ptr; + _impure_ptr = __cygwin_user_data.impure_ptr; __cygwin_user_data.main = f; __cygwin_user_data.premain[0] = cygwin_premain0; __cygwin_user_data.premain[1] = cygwin_premain1; diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc index 5682b868b..8ca6b7b8f 100644 --- a/winsup/cygwin/signal.cc +++ b/winsup/cygwin/signal.cc @@ -76,11 +76,6 @@ sigprocmask (int sig, const sigset_t *set, sigset_t *oldset) return -1; } - /* gcc can call sigprocmask when a builtin contructor is activated. - This can happen prior to the setup of myself */ - if (!user_data) - return 0; - if (oldset) *oldset = myself->getsigmask (); if (set) @@ -109,21 +104,6 @@ sigprocmask (int sig, const sigset_t *set, sigset_t *oldset) return 0; } -#if 0 -/* This is called _raise because the real raise is in newlib. */ -int -_raise (int sig) -{ - if (!user_data) - { - set_errno (ESRCH); - return -1; - } - - return _kill (myself->pid, sig); -} -#endif - static int kill_worker (pid_t pid, int sig) { -- 2.43.5