From 2bd22312df4fd5be14d8833a22ed7abbdcc35559 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sun, 17 Feb 2002 04:59:55 +0000 Subject: [PATCH] * times.cc (hires::prime): Restore thread priority on failure condition. * uinfo.cc (uinfo_init): Use more robust method for determining if process was invoked from a non-cygwin process. * sync.h (muto::init): Eliminate "inheritance" parameter. (new_muto): Reflect removal of parameter. * sync.cc (muto::init): Ditto. * cygheap.cc (cygheap_init): Ditto. * debug.cc (threadname_init): Ditto. * exceptions.cc (events_init): Ditto. * malloc.cc (malloc_init): Ditto. * path.cc (cwdstuff::init): Ditto. * sigproc.cc (sigproc_init): Ditto. * grp.cc (group_lock): Use different method for locking with static member. (read_etc_group): REALLY ensure that read lock mutex is released. * passwd.cc (passwd_lock): Use different method for locking with static member. (read_etc_passwd): REALLY ensure that read lock mutex is released. * shared.cc (sec_user): Correct reversed inheritance test. --- winsup/cygwin/ChangeLog | 25 +++++++++++++++++++++++++ winsup/cygwin/cygheap.cc | 2 +- winsup/cygwin/debug.cc | 4 ++-- winsup/cygwin/exceptions.cc | 2 +- winsup/cygwin/grp.cc | 20 ++++++++++++-------- winsup/cygwin/malloc_wrapper.cc | 2 +- winsup/cygwin/passwd.cc | 20 ++++++++++++-------- winsup/cygwin/path.cc | 2 +- winsup/cygwin/shared.cc | 4 ++-- winsup/cygwin/sigproc.cc | 2 +- winsup/cygwin/sync.cc | 4 ++-- winsup/cygwin/sync.h | 8 ++++---- winsup/cygwin/times.cc | 1 + winsup/cygwin/uinfo.cc | 4 ++-- 14 files changed, 67 insertions(+), 33 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index a880f3e8d..4a4de7c38 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,28 @@ +2002-02-16 Christopher Faylor + + * times.cc (hires::prime): Restore thread priority on failure + condition. + + * uinfo.cc (uinfo_init): Use more robust method for determining if + process was invoked from a non-cygwin process. + + * sync.h (muto::init): Eliminate "inheritance" parameter. + (new_muto): Reflect removal of parameter. + * sync.cc (muto::init): Ditto. + * cygheap.cc (cygheap_init): Ditto. + * debug.cc (threadname_init): Ditto. + * exceptions.cc (events_init): Ditto. + * malloc.cc (malloc_init): Ditto. + * path.cc (cwdstuff::init): Ditto. + * sigproc.cc (sigproc_init): Ditto. + + * grp.cc (group_lock): Use different method for locking with static member. + (read_etc_group): REALLY ensure that read lock mutex is released. + * passwd.cc (passwd_lock): Use different method for locking with static member. + (read_etc_passwd): REALLY ensure that read lock mutex is released. + + * shared.cc (sec_user): Correct reversed inheritance test. + 2002-02-15 Christopher Faylor * hires.h (hires::usecs): Rename from utime. Accept an argument. diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 79fb48410..d0634e6d5 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -197,7 +197,7 @@ _csbrk (int sbs) extern "C" void __stdcall cygheap_init () { - cygheap_protect = new_muto (FALSE, "cygheap_protect"); + cygheap_protect = new_muto ("cygheap_protect"); _csbrk (0); if (!cygheap->fdtab) cygheap->fdtab.init (); diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc index 76cce92ff..731c389cc 100644 --- a/winsup/cygwin/debug.cc +++ b/winsup/cygwin/debug.cc @@ -37,7 +37,7 @@ static NO_COPY thread_info threads[32] = {{0, NULL}}; // increase as necessary void threadname_init () { - threadname_lock = new_muto (FALSE, "threadname_lock"); + threadname_lock = new_muto ("threadname_lock"); } void __stdcall @@ -195,7 +195,7 @@ static bool __stdcall mark_closed (const char *, int, HANDLE, const char *, BOOL void debug_init () { - debug_lock = new_muto (FALSE, "debug_lock"); + debug_lock = new_muto ("debug_lock"); } /* Find a registered handle in the linked list of handles. */ diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 123571618..18c9c2600 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -1112,7 +1112,7 @@ events_init (void) api_fatal ("can't create title mutex, %E"); ProtectHandle (title_mutex); - mask_sync = new_muto (FALSE, "mask_sync"); + mask_sync = new_muto ("mask_sync"); windows_system_directory[0] = '\0'; (void) GetSystemDirectory (windows_system_directory, sizeof (windows_system_directory) - 2); char *end = strchr (windows_system_directory, '\0'); diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index c5804b70b..d88deb994 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -31,7 +31,7 @@ details. */ /* Read /etc/group only once for better performance. This is done on the first call that needs information from it. */ -static NO_COPY const char *etc_group = "/etc/group"; +static const char *etc_group NO_COPY = "/etc/group"; static struct __group16 *group_buf; /* group contents in memory */ static int curr_lines; static int max_lines; @@ -119,17 +119,23 @@ add_grp_line (const char *line) class group_lock { - pthread_mutex_t mutex; + bool armed; + static NO_COPY pthread_mutex_t mutex; public: - group_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {} - void arm () {pthread_mutex_lock (&mutex); } + group_lock (bool doit) + { + if (armed = doit) + pthread_mutex_lock (&mutex); + } ~group_lock () { - if (mutex != (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) + if (armed) pthread_mutex_unlock (&mutex); } }; +pthread_mutex_t NO_COPY group_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER; + /* Cygwin internal */ /* Read in /etc/group and save contents in the group cache */ /* This sets group_in_memory_p to 1 so functions in this file can @@ -145,9 +151,7 @@ read_etc_group () strncpy (group_name, "Administrators", sizeof (group_name)); - static NO_COPY group_lock here = group_lock(); - if (cygwin_finished_initializing) - here.arm (); + group_lock here (cygwin_finished_initializing); /* if we got blocked by the mutex, then etc_group may have been processed */ if (group_state != uninitialized) diff --git a/winsup/cygwin/malloc_wrapper.cc b/winsup/cygwin/malloc_wrapper.cc index 60c67aca8..a571d684b 100644 --- a/winsup/cygwin/malloc_wrapper.cc +++ b/winsup/cygwin/malloc_wrapper.cc @@ -216,7 +216,7 @@ static NO_COPY muto *mprotect = NULL; void malloc_init () { - mprotect = new_muto (FALSE, "mprotect"); + mprotect = new_muto ("mprotect"); /* Check if mallock is provided by application. If so, redirect all calls to export_malloc/free/realloc to application provided. This may happen if some other dll calls cygwin's malloc, but main code provides diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index 52c04a947..dfabd1b7f 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -111,17 +111,24 @@ add_pwd_line (char *line) class passwd_lock { - pthread_mutex_t mutex; + bool armed; + static NO_COPY pthread_mutex_t mutex; public: - passwd_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {} - void arm () {pthread_mutex_lock (&mutex); } + passwd_lock (bool doit) + { + if (doit) + pthread_mutex_lock (&mutex); + armed = doit; + } ~passwd_lock () { - if (mutex != (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) + if (armed) pthread_mutex_unlock (&mutex); } }; +pthread_mutex_t NO_COPY passwd_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER; + /* Read in /etc/passwd and save contents in the password cache. This sets passwd_state to loaded or emulated so functions in this file can tell that /etc/passwd has been read in or will be emulated. */ @@ -133,10 +140,7 @@ read_etc_passwd () * for non-shared mutexs in the future. Also, this function will at most be called * once from each thread, after that the passwd_state test will succeed */ - static NO_COPY passwd_lock here; - - if (cygwin_finished_initializing) - here.arm (); + passwd_lock here (cygwin_finished_initializing); /* if we got blocked by the mutex, then etc_passwd may have been processed */ if (passwd_state != uninitialized) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index d237a5d8b..e9f5a176f 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -3546,7 +3546,7 @@ cwdstuff::get_hash () void cwdstuff::init () { - lock = new_muto (false, "cwd"); + lock = new_muto ("cwd"); } /* Get initial cwd. Should only be called once in a diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc index 117f1db36..7b21e1387 100644 --- a/winsup/cygwin/shared.cc +++ b/winsup/cygwin/shared.cc @@ -240,7 +240,7 @@ PSECURITY_ATTRIBUTES __stdcall sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) { if (!sa_buf) - return inherit ? &sec_none_nih : &sec_none; + return inherit ? &sec_none : &sec_none_nih; PSECURITY_ATTRIBUTES psa = (PSECURITY_ATTRIBUTES) sa_buf; PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) @@ -252,7 +252,7 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) if (cygheap->user.sid ()) sid = cygheap->user.sid (); else if (!lookup_name (getlogin (), cygheap->user.logsrv (), sid)) - return inherit ? &sec_none_nih : &sec_none; + return inherit ? &sec_none : &sec_none_nih; size_t acl_len = sizeof (ACL) + 4 * (sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD)) diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 19ac8701b..f0a31131c 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -587,7 +587,7 @@ sigproc_init () /* sync_proc_subproc is used by proc_subproc. It serialises * access to the children and zombie arrays. */ - sync_proc_subproc = new_muto (FALSE, "sync_proc_subproc"); + sync_proc_subproc = new_muto ("sync_proc_subproc"); /* Initialize waitq structure for main thread. A waitq structure is * allocated for each thread that executes a wait to allow multiple threads diff --git a/winsup/cygwin/sync.cc b/winsup/cygwin/sync.cc index 1b5145aa4..333ec193c 100644 --- a/winsup/cygwin/sync.cc +++ b/winsup/cygwin/sync.cc @@ -29,11 +29,11 @@ muto NO_COPY muto_start; /* Constructor */ muto * -muto::init (int inh, const char *s) +muto::init (const char *s) { waiters = -1; /* Create event which is used in the fallback case when blocking is necessary */ - if (!(bruteforce = CreateEvent (inh ? &sec_all_nih : &sec_none_nih, FALSE, FALSE, NULL))) + if (!(bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL))) { DWORD oerr = GetLastError (); SetLastError (oerr); diff --git a/winsup/cygwin/sync.h b/winsup/cygwin/sync.h index c710f8901..24c37dbfb 100644 --- a/winsup/cygwin/sync.h +++ b/winsup/cygwin/sync.h @@ -24,7 +24,7 @@ public: const char *name; /* The real constructor. */ - muto *init(int inh, const char *name) __attribute__ ((regparm (3))); + muto *init(const char *name) __attribute__ ((regparm (3))); #if 0 /* FIXME: See comment in sync.cc */ ~muto () @@ -42,8 +42,8 @@ public: extern muto muto_start; /* Use a statically allocated buffer as the storage for a muto */ -#define new_muto(__inh, __name) \ +#define new_muto(__name) \ ({ \ - static muto __mbuf NO_COPY; \ - __mbuf.init (__inh, __name); \ + static muto __mbuf __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))); \ + __mbuf.init (__name); \ }) diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index 032e32fb5..9674d1031 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -573,6 +573,7 @@ hires::prime () SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL); if (!QueryPerformanceCounter (&primed_pc)) { + SetThreadPriority (GetCurrentThread (), priority); inited = -1; return; } diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index 1ee6143c8..3e3513a16 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -257,7 +257,7 @@ uinfo_init () myself->uid = p->pw_uid; /* Set primary group only if process has been started from a non cygwin process. */ - if (myself->ppid == 1) + if (!myself->ppid_handle) myself->gid = p->pw_gid; } else @@ -277,7 +277,7 @@ getlogin (void) #ifdef _MT_SAFE char *this_username=_reent_winsup ()->_username; #else - static NO_COPY char this_username[UNLEN + 1]; + static char this_username[UNLEN + 1] NO_COPY; #endif return strcpy (this_username, cygheap->user.name ());