From 4ce15a498010f678c71cefdf2a2ac0db58f4fa93 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 6 Sep 2001 03:39:18 +0000 Subject: [PATCH] * cygheap.h (init_cygheap): Move bucket array here from cygheap.cc. * cygheap.cc: Throughout use bucket array from cygheap. * sigproc.cc (proc_subproc): Dynamically allocate zombie buffer to save DLL space. (sigproc_fixup_after_fork): Free zombie array after a fork. * sigproc.h (sigproc_fixup_after_fork): Declare. * dir.cc (mkdir): Expand buffer for security descriptor to 4K to avoid stack corruption. * fhandler.cc (fhandler_base::open): Ditto. * path.cc (symlink): Ditto. --- winsup/cygwin/ChangeLog | 17 +++++++++++++++++ winsup/cygwin/cygheap.cc | 14 ++++++-------- winsup/cygwin/cygheap.h | 1 + winsup/cygwin/dir.cc | 2 +- winsup/cygwin/fhandler.cc | 2 +- winsup/cygwin/fork.cc | 1 + winsup/cygwin/passwd.cc | 6 +++--- winsup/cygwin/path.cc | 2 +- winsup/cygwin/security.cc | 2 +- winsup/cygwin/sigproc.cc | 19 ++++++++++++++++--- winsup/cygwin/sigproc.h | 1 + 11 files changed, 49 insertions(+), 18 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 43e9ff462..d256cc263 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,20 @@ +Wed Sep 5 23:36:03 2001 Christopher Faylor + + * cygheap.h (init_cygheap): Move bucket array here from cygheap.cc. + * cygheap.cc: Throughout use bucket array from cygheap. + + * sigproc.cc (proc_subproc): Dynamically allocate zombie buffer to save + DLL space. + (sigproc_fixup_after_fork): Free zombie array after a fork. + * sigproc.h (sigproc_fixup_after_fork): Declare. + +2001-09-06 Egor Duda + + * dir.cc (mkdir): Expand buffer for security descriptor to 4K to avoid + stack corruption. + * fhandler.cc (fhandler_base::open): Ditto. + * path.cc (symlink): Ditto. + Wed Sep 5 21:35:00 2001 Corinna Vinschen * winver.rc: Change copyright to include 2001. diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 94d0dc0bd..8c45b1bce 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -35,9 +35,7 @@ struct cygheap_entry char data[0]; }; -#define NBUCKETS 32 -static char *buckets[NBUCKETS] = {0}; - +#define NBUCKETS (sizeof (cygheap->buckets) / sizeof (cygheap->buckets[0])) #define N0 ((_cmalloc_entry *) NULL) #define to_cmalloc(s) ((_cmalloc_entry *) (((char *) (s)) - (int) (N0->data))) @@ -202,10 +200,10 @@ _cmalloc (int size) continue; cygheap_protect->acquire (); - if (buckets[b]) + if (cygheap->buckets[b]) { - rvc = (_cmalloc_entry *) buckets[b]; - buckets[b] = rvc->ptr; + rvc = (_cmalloc_entry *) cygheap->buckets[b]; + cygheap->buckets[b] = rvc->ptr; rvc->b = b; } else @@ -227,8 +225,8 @@ _cfree (void *ptr) cygheap_protect->acquire (); _cmalloc_entry *rvc = to_cmalloc (ptr); DWORD b = rvc->b; - rvc->ptr = buckets[b]; - buckets[b] = (char *) rvc; + rvc->ptr = cygheap->buckets[b]; + cygheap->buckets[b] = (char *) rvc; cygheap_protect->release (); } diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index 5a3aeac37..5b385f5c1 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -152,6 +152,7 @@ struct cwdstuff struct init_cygheap { _cmalloc_entry *chain; + char *buckets[32]; cygheap_root root; cygheap_user user; mode_t umask; diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc index 9d21cdc19..f716f23ba 100644 --- a/winsup/cygwin/dir.cc +++ b/winsup/cygwin/dir.cc @@ -339,7 +339,7 @@ mkdir (const char *dir, mode_t mode) if (allow_ntsec && real_dir.has_acls ()) set_security_attribute (S_IFDIR | ((mode & 07777) & ~cygheap->umask), - &sa, alloca (256), 256); + &sa, alloca (4096), 4096); if (CreateDirectoryA (real_dir.get_win32 (), &sa)) { diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 4060a3819..115a4c796 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -387,7 +387,7 @@ fhandler_base::open (int flags, mode_t mode) /* If the file should actually be created and ntsec is on, set files attributes. */ if (flags & O_CREAT && get_device () == FH_DISK && allow_ntsec && has_acls ()) - set_security_attribute (mode, &sa, alloca (256), 256); + set_security_attribute (mode, &sa, alloca (4096), 4096); x = CreateFileA (get_win32_name (), access, shared, &sa, creation_distribution, diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index 834c356d7..173c02b1b 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -279,6 +279,7 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls) debug_fixup_after_fork (); pinfo_fixup_after_fork (); cygheap->fdtab.fixup_after_fork (hParent); + sigproc_fixup_after_fork (); signal_fixup_after_fork (); MALLOC_CHECK; diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index f7b0853ad..4fe7166aa 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -27,9 +27,9 @@ details. */ /* Read /etc/passwd only once for better performance. This is done on the first call that needs information from it. */ -static struct passwd *passwd_buf = NULL; /* passwd contents in memory */ -static int curr_lines = 0; -static int max_lines = 0; +static struct passwd *passwd_buf; /* passwd contents in memory */ +static int curr_lines; +static int max_lines; /* Set to loaded when /etc/passwd has been read in by read_etc_passwd (). Set to emulated if passwd is emulated. */ diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 25d2174bd..7e32ae8ec 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2461,7 +2461,7 @@ symlink (const char *topath, const char *frompath) if (allow_ntsec && win32_path.has_acls ()) set_security_attribute (S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO, - &sa, alloca (256), 256); + &sa, alloca (4096), 4096); h = CreateFileA(win32_path, GENERIC_WRITE, 0, &sa, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 24501fa7b..f208ebeec 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -44,7 +44,7 @@ details. */ extern BOOL allow_ntea; -BOOL allow_ntsec = FALSE; +BOOL allow_ntsec; /* allow_smbntsec is handled exclusively in path.cc (path_conv::check). It's defined here because of it's strong relationship to allow_ntsec. The default is TRUE to reflect the old behaviour. */ diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 768d6f1fd..b3c69ffd5 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -46,7 +46,7 @@ details. */ #define no_signals_available() (!hwait_sig || !sig_loop_wait) -#define ZOMBIEMAX ((int) (sizeof (zombies) / sizeof (zombies[0])) - 1) +#define ZOMBIEMAX 4096 /* * Global variables @@ -102,9 +102,9 @@ Static HANDLE wait_sig_inited = NULL; // Control synchronization of Static HANDLE events[PSIZE + 1] = {0}; // All my children's handles++ #define hchildren (events + 1) // Where the children handles begin Static pinfo pchildren[PSIZE]; // All my children info -Static pinfo zombies[16384]; // All my deceased children info Static int nchildren = 0; // Number of active children -Static int nzombies = 0; // Number of deceased children +static pinfo *zombies; // All my deceased children info +static int nzombies; // Number of deceased children Static waitq waitq_head = {0, 0, 0, 0, 0, 0, 0};// Start of queue for wait'ing threads Static waitq waitq_main; // Storage for main thread @@ -303,6 +303,8 @@ proc_subproc (DWORD what, DWORD val) int thiszombie; thiszombie = nzombies; + if (!zombies) + zombies = (pinfo *) malloc (sizeof (pinfo) * ZOMBIEMAX); zombies[nzombies] = pchildren[val]; // Add to zombie array zombies[nzombies++]->process_state = PID_ZOMBIE;// Walking dead @@ -1302,6 +1304,17 @@ wait_subproc (VOID *) return 0; } +void __stdcall +sigproc_fixup_after_fork () +{ + if (zombies) + { + free (zombies); + nzombies = 0; + zombies = NULL; + } +} + extern "C" { /* Provide a stack frame when calling WaitFor* functions */ diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h index 5726a4519..c9b5cad3e 100644 --- a/winsup/cygwin/sigproc.h +++ b/winsup/cygwin/sigproc.h @@ -115,6 +115,7 @@ int __stdcall sig_send (_pinfo *, int, DWORD ebp = (DWORD) __builtin_frame_addre bool exception = 0) __attribute__ ((regparm(3))); void __stdcall signal_fixup_after_fork (); void __stdcall signal_fixup_after_exec (bool); +void __stdcall sigproc_fixup_after_fork (); extern char myself_nowait_dummy[]; extern char myself_nowait_nonmain_dummy[];