aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-11-18 00:48:41 +0000
committerChristopher Faylor <me@cgf.cx>2004-11-18 00:48:41 +0000
commit75faeb397425f73ca193aba96c61c4e8fc3e3506 (patch)
tree8b7b6118db0acb69e7a2c7c2cc219fd7ff8059e0 /winsup
parent6b82a1611b920461f612aece24d77fd8c1b6c281 (diff)
downloadnewlib-75faeb397425f73ca193aba96c61c4e8fc3e3506.zip
newlib-75faeb397425f73ca193aba96c61c4e8fc3e3506.tar.gz
newlib-75faeb397425f73ca193aba96c61c4e8fc3e3506.tar.bz2
checkpoint
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/cygthread.cc2
-rw-r--r--winsup/cygwin/dcrt0.cc12
-rw-r--r--winsup/cygwin/debug.cc1
-rw-r--r--winsup/cygwin/exceptions.cc4
-rw-r--r--winsup/cygwin/fhandler_tty.cc5
-rw-r--r--winsup/cygwin/fork.cc21
-rw-r--r--winsup/cygwin/perthread.h86
-rw-r--r--winsup/cygwin/pinfo.cc43
-rw-r--r--winsup/cygwin/pinfo.h2
-rw-r--r--winsup/cygwin/select.cc1
-rw-r--r--winsup/cygwin/sigproc.cc23
-rw-r--r--winsup/cygwin/spawn.cc89
-rw-r--r--winsup/cygwin/syscalls.cc2
-rw-r--r--winsup/cygwin/wait.cc1
14 files changed, 48 insertions, 244 deletions
diff --git a/winsup/cygwin/cygthread.cc b/winsup/cygwin/cygthread.cc
index 1c7fc5c..1f071b8 100644
--- a/winsup/cygwin/cygthread.cc
+++ b/winsup/cygwin/cygthread.cc
@@ -19,7 +19,7 @@ details. */
#undef CloseHandle
-static cygthread NO_COPY threads[128];
+static cygthread NO_COPY threads[32];
#define NTHREADS (sizeof (threads) / sizeof (threads[0]))
DWORD NO_COPY cygthread::main_thread_id;
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 4f2381c..41bd7d6 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -29,7 +29,7 @@ details. */
#include "dtable.h"
#include "cygheap.h"
#include "child_info_magic.h"
-#include "perthread.h"
+#include "cygtls.h"
#include "shared_info.h"
#include "cygwin_version.h"
#include "dll_init.h"
@@ -43,16 +43,6 @@ details. */
HANDLE NO_COPY hMainProc = (HANDLE) -1;
HANDLE NO_COPY hMainThread;
-#ifdef NEWVFORK
-per_thread_vfork NO_COPY vfork_storage;
-#endif
-
-per_thread NO_COPY *threadstuff[] = {
-#ifdef NEWVFORK
- &vfork_storage,
-#endif
- NULL};
-
bool display_title;
bool strip_title_path;
bool allow_glob = true;
diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc
index db5da1a..7411a5d 100644
--- a/winsup/cygwin/debug.cc
+++ b/winsup/cygwin/debug.cc
@@ -11,7 +11,6 @@ details. */
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
-#include "perthread.h"
#include "perprocess.h"
#include "security.h"
#include "cygerrno.h"
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index f3207c6..8fdecba 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -20,8 +20,6 @@ details. */
#include "cygtls.h"
#include "sigproc.h"
#include "cygerrno.h"
-#define NEED_VFORK
-#include "perthread.h"
#include "shared_info.h"
#include "perprocess.h"
#include "security.h"
@@ -989,7 +987,7 @@ sigpacket::process ()
bool special_case;
bool insigwait_mask;
insigwait_mask = masked = false;
- if (special_case = (VFORKPID || ISSTATE (myself, PID_STOPPED)))
+ if (special_case = (/*VFORKPID || */ISSTATE (myself, PID_STOPPED)))
/* nothing to do */;
else if (tls && sigismember (&tls->sigwait_mask, si.si_signo))
insigwait_mask = true;
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index c64aac7..642f5ca 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -771,7 +771,10 @@ fhandler_tty_slave::read (void *ptr, size_t& len)
rc = WaitForMultipleObjects (2, w4, FALSE, waiter);
if (rc == WAIT_TIMEOUT)
- break;
+ {
+ termios_printf ("wait timed out, waiter %u", waiter);
+ break;
+ }
if (rc == WAIT_FAILED)
{
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 52a5b5e..8bcf5b0 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -22,8 +22,7 @@ details. */
#include "pinfo.h"
#include "cygheap.h"
#include "child_info.h"
-#define NEED_VFORK
-#include "perthread.h"
+#include "cygtls.h"
#include "perprocess.h"
#include "dll_init.h"
#include "sync.h"
@@ -42,17 +41,6 @@ details. */
#define dll_bss_start &_bss_start__
#define dll_bss_end &_bss_end__
-void
-per_thread::set (void *s)
-{
- if (s == PER_THREAD_FORK_CLEAR)
- {
- tls = TlsAlloc ();
- s = NULL;
- }
- TlsSetValue (get_tls (), s);
-}
-
static void
stack_base (child_info_fork &ch)
{
@@ -305,13 +293,6 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
api_fatal ("recreate_shm areas after fork failed");
#endif
- /* Set thread local stuff to zero. Under Windows 95/98 this is sometimes
- non-zero, for some reason.
- FIXME: There is a memory leak here after a fork. */
- for (per_thread **t = threadstuff; *t; t++)
- if ((*t)->clear_on_fork ())
- (*t)->set ();
-
pthread::atforkchild ();
fixup_timers_after_fork ();
cygbench ("fork-child");
diff --git a/winsup/cygwin/perthread.h b/winsup/cygwin/perthread.h
deleted file mode 100644
index e10a624..0000000
--- a/winsup/cygwin/perthread.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/* perthread.h: Header file for cygwin thread-local storage.
-
- Copyright 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
-
- Written by Christopher Faylor <cgf@cygnus.com>
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-#define PTMAGIC 0x77366377
-
-#define PER_THREAD_FORK_CLEAR ((void *)UINT32_MAX)
-class per_thread
-{
- DWORD tls;
- int clear_on_fork_p;
-public:
- per_thread (int forkval = 1) {tls = TlsAlloc (); clear_on_fork_p = forkval;}
- DWORD get_tls () {return tls;}
- int clear_on_fork () {return clear_on_fork_p;}
-
- virtual void *get () {return TlsGetValue (get_tls ());}
- virtual size_t size () {return 0;}
- virtual void set (void *s = NULL);
- virtual void set (int n) {TlsSetValue (get_tls (), (void *)n);}
- virtual void *create ()
- {
- void *s = calloc (1, size ());
- set (s);
- return s;
- }
-};
-
-#ifdef NEED_VFORK
-#include "cygtls.h"
-#endif
-
-#ifndef NEWVFORK
-#define VFORKPID 0
-#else
-#if defined (NEED_VFORK)
-class vfork_save
-{
- jmp_buf j;
- int exitval;
- public:
- int pid;
- DWORD frame[100];
- _cygtls tls;
- char **vfork_ebp;
- char **vfork_esp;
- int ctty;
- pid_t sid;
- pid_t pgid;
- int open_fhs;
- int is_active () { return pid < 0; }
- void restore_pid (int val)
- {
- pid = val;
- longjmp (j, 1);
- }
- void restore_exit (int val)
- {
- exitval = val;
- longjmp (j, 1);
- }
- friend int vfork ();
-};
-
-class per_thread_vfork : public per_thread
-{
-public:
- vfork_save *val () { return (vfork_save *) per_thread::get (); }
- vfork_save *create () {return (vfork_save *) per_thread::create ();}
- size_t size () {return sizeof (vfork_save);}
-};
-extern per_thread_vfork vfork_storage;
-extern vfork_save *main_vfork;
-#define VFORKPID main_vfork->pid
-#endif
-#endif /*NEWVFORK*/
-
-extern per_thread *threadstuff[];
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index ef8bab2..7f5b404 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -39,21 +39,6 @@ pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks
HANDLE hexec_proc;
-void __stdcall
-pinfo_fixup_after_fork ()
-{
- if (hexec_proc)
- CloseHandle (hexec_proc);
- /* Keeps the cygpid from being reused. No rights required */
- if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &hexec_proc, 0,
- TRUE, 0))
- {
- system_printf ("couldn't save current process handle %p, %E", hMainProc);
- hexec_proc = NULL;
- }
- VerifyHandle (hexec_proc);
-}
-
/* Initialize the process table.
This is done once when the dll is first loaded. */
@@ -71,7 +56,13 @@ set_myself (HANDLE h)
strace.hello ();
debug_printf ("myself->dwProcessId %u", myself->dwProcessId);
InitializeCriticalSection (&myself.lock);
- if (!h && myself->ppid)
+ myself->dwProcessId = GetCurrentProcessId ();
+ if (h)
+ {
+ static pinfo NO_COPY myself_identity;
+ myself_identity.init (cygwin_pid (myself->dwProcessId), PID_EXECED);
+ }
+ else if (myself->ppid)
{
pinfo parent (myself->ppid);
if (parent && parent->wr_proc_pipe)
@@ -107,6 +98,21 @@ pinfo_init (char **envp, int envc)
debug_printf ("pid %d, pgid %d", myself->pid, myself->pgid);
}
+void __stdcall
+pinfo_fixup_after_fork ()
+{
+ if (hexec_proc)
+ CloseHandle (hexec_proc);
+ /* Keeps the cygpid from being reused. No rights required */
+ if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &hexec_proc, 0,
+ TRUE, 0))
+ {
+ system_printf ("couldn't save current process handle %p, %E", hMainProc);
+ hexec_proc = NULL;
+ }
+ VerifyHandle (hexec_proc);
+}
+
void
_pinfo::exit (UINT n, bool norecord)
{
@@ -655,7 +661,6 @@ static DWORD WINAPI
proc_waiter (void *arg)
{
pinfo vchild = *(pinfo *) arg;
- vchild.preserve ();
siginfo_t si;
si.si_signo = SIGCHLD;
@@ -696,7 +701,6 @@ proc_waiter (void *arg)
CloseHandle (vchild.rd_proc_pipe);
vchild.rd_proc_pipe = NULL;
si.si_status = vchild->exitcode;
- // proc_todo = PROC_CHILDTERMINATED;
vchild->process_state = PID_ZOMBIE;
break;
case SIGTTIN:
@@ -704,10 +708,8 @@ proc_waiter (void *arg)
case SIGTSTP:
case SIGSTOP:
si.si_sigval.sival_int = CLD_STOPPED;
- // proc_todo = PROC_CHILDSTOPPED;
break;
case SIGCONT:
- // proc_todo = PROC_CHILDCONTINUED;
continue;
default:
system_printf ("unknown value %d on proc pipe", buf);
@@ -752,6 +754,7 @@ pinfo::wait ()
}
CloseHandle (out);
+ preserve ();
#if 0
DWORD tid;
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index 89e4a6c..2fddc32 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -136,7 +136,7 @@ public:
pinfo (pid_t n) {init (n, 0);}
pinfo (pid_t n, DWORD flag) {init (n, flag);}
void release ();
- int wait ();
+ int wait () __attribute__ ((regparm (1)));
~pinfo ()
{
if (destroy && procinfo)
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 7117ccd..f145e08 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -36,7 +36,6 @@ details. */
#include "dtable.h"
#include "cygheap.h"
#include "sigproc.h"
-#include "perthread.h"
#include "tty.h"
#include "ntdll.h"
#include "cygtls.h"
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index fe2b8bf..8ac611c 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -30,7 +30,6 @@ details. */
#include "shared_info.h"
#include "cygtls.h"
#include "sigproc.h"
-#include "perthread.h"
#include "exceptions.h"
/*
@@ -361,7 +360,6 @@ proc_subproc (DWORD what, DWORD val)
sigproc_printf ("finished clearing");
}
- // FIXMENOW: What is supposed to happen here?
if (global_sigs[SIGCHLD].sa_handler == (void *) SIG_IGN)
for (int i = 0; i < nprocs; i += remove_proc (i))
continue;
@@ -526,7 +524,7 @@ sigproc_terminate (void)
CloseHandle (sendsig);
}
}
- proc_terminate (); // Terminate process handling thread
+ proc_terminate (); // clean up process stuff
return;
}
@@ -904,29 +902,10 @@ wait_sig (VOID *self)
signals. Prior to this, dwProcessId was set to the windows pid of
of the original windows process which spawned us unless this was a
"toplevel" process. */
- myself->dwProcessId = GetCurrentProcessId ();
myself->process_state |= PID_ACTIVE;
myself->process_state &= ~PID_INITIALIZING;
sigproc_printf ("myself->dwProcessId %u", myself->dwProcessId);
-#if 0
- /* If we've been execed, then there is still a stub left in the previous
- windows process waiting to see if it's started a cygwin process or not.
- Signalling subproc_ready indicates that we are a cygwin process. */
- if (child_proc_info && child_proc_info->type == PROC_EXEC)
- {
- debug_printf ("subproc_ready %p", child_proc_info->subproc_ready);
- if (!SetEvent (child_proc_info->subproc_ready))
- system_printf ("SetEvent (subproc_ready) failed, %E");
- ForceCloseHandle1 (child_proc_info->subproc_ready, subproc_ready);
- /* Initialize an "indirect" pid block so that if someone looks up this
- process via its Windows PID it will be redirected to the appropriate
- Cygwin PID shared memory block. */
- static pinfo NO_COPY myself_identity;
- myself_identity.init (cygwin_pid (myself->dwProcessId), PID_EXECED);
- }
-#endif
-
SetEvent (wait_sig_inited);
sigtid = GetCurrentThreadId ();
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 43bd148..8788e92 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -29,8 +29,6 @@ details. */
#include "child_info.h"
#include "shared_info.h"
#include "pinfo.h"
-#define NEED_VFORK
-#include "perthread.h"
#include "registry.h"
#include "environ.h"
#include "cygthread.h"
@@ -384,16 +382,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
else
chtype = PROC_EXEC;
- HANDLE subproc_ready;
- if (1 || chtype != PROC_EXEC)
- subproc_ready = NULL;
- else
- {
- subproc_ready = CreateEvent (&sec_all, TRUE, FALSE, NULL);
- ProtectHandleINH (subproc_ready);
- }
-
- init_child_info (chtype, &ciresrv, subproc_ready);
+ init_child_info (chtype, &ciresrv, NULL);
ciresrv.moreinfo = (cygheap_exec_info *) ccalloc (HEAP_1_EXEC, 1, sizeof (cygheap_exec_info));
ciresrv.moreinfo->old_title = NULL;
@@ -627,12 +616,18 @@ spawn_guts (const char * prog_arg, const char *const *argv,
if (mode == _P_DETACH || !set_console_state_for_spawn ())
flags |= DETACHED_PROCESS;
- if (mode != _P_OVERLAY)
- flags |= CREATE_SUSPENDED;
-#if 0 //someday
+
+ HANDLE saved_sendsig;
+ if (mode == _P_OVERLAY)
+ {
+ saved_sendsig = myself->sendsig;
+ myself->sendsig = INVALID_HANDLE_VALUE;
+ }
else
- myself->dwProcessId = 0;
-#endif
+ {
+ flags |= CREATE_SUSPENDED;
+ saved_sendsig = NULL;
+ }
/* Some file types (currently only sockets) need extra effort in the
parent after CreateProcess and before copying the datastructures
@@ -718,7 +713,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
/* Restore impersonation. In case of _P_OVERLAY this isn't
allowed since it would overwrite child data. */
if (mode != _P_OVERLAY || !rc)
- cygheap->user.reimpersonate ();
+ cygheap->user.reimpersonate ();
MALLOC_CHECK;
if (envblock)
@@ -732,12 +727,8 @@ spawn_guts (const char * prog_arg, const char *const *argv,
{
__seterrno ();
syscall_printf ("CreateProcess failed, %E");
-#if 0 // someday
- if (mode == _P_OVERLAY)
- myself->dwProcessId = GetCurrentProcessId ();
-#endif
- if (subproc_ready)
- ForceCloseHandle (subproc_ready);
+ if (saved_sendsig)
+ myself->sendsig = saved_sendsig;
cygheap_setup_for_child_cleanup (newheap, &ciresrv, 0);
return -1;
}
@@ -837,56 +828,6 @@ spawn_guts (const char * prog_arg, const char *const *argv,
res = 0;
exited = false;
-#if 0
- if (mode == _P_OVERLAY)
- {
- int nwait = 3;
- HANDLE waitbuf[3] = {pi.hProcess, signal_arrived, subproc_ready};
- for (int i = 0; i < 100; i++)
- {
- switch (WaitForMultipleObjects (nwait, waitbuf, FALSE, INFINITE))
- {
- case WAIT_OBJECT_0:
- sigproc_printf ("subprocess exited");
- DWORD exitcode;
- if (!GetExitCodeProcess (pi.hProcess, &exitcode))
- exitcode = 1;
- res |= exitcode;
- exited = true;
- break;
- case WAIT_OBJECT_0 + 1:
- sigproc_printf ("signal arrived");
- reset_signal_arrived ();
- continue;
- case WAIT_OBJECT_0 + 2:
- if (!myself->cygstarted)
- {
- nwait = 2;
- sigproc_terminate ();
- continue;
- }
- break;
- case WAIT_FAILED:
- system_printf ("wait failed: nwait %d, pid %d, winpid %d, %E",
- nwait, myself->pid, myself->dwProcessId);
- system_printf ("waitbuf[0] %p %d", waitbuf[0],
- WaitForSingleObject (waitbuf[0], 0));
- system_printf ("waitbuf[1] %p %d", waitbuf[1],
- WaitForSingleObject (waitbuf[1], 0));
- system_printf ("waitbuf[w] %p %d", waitbuf[2],
- WaitForSingleObject (waitbuf[2], 0));
- set_errno (ECHILD);
- try_to_debug ();
- return -1;
- }
- break;
- }
-
- ForceCloseHandle (subproc_ready);
- sigproc_printf ("P_OVERLAY res %p", res);
- }
-#endif
-
ForceCloseHandle1 (pi.hProcess, childhProc);
switch (mode)
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 619eda3..e151a60 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -56,8 +56,6 @@ details. */
#include "pinfo.h"
#include "shared_info.h"
#include "cygheap.h"
-#define NEED_VFORK
-#include "perthread.h"
#include "pwdgrp.h"
#include "cpuid.h"
#include "registry.h"
diff --git a/winsup/cygwin/wait.cc b/winsup/cygwin/wait.cc
index 7d1f13a..70febf0 100644
--- a/winsup/cygwin/wait.cc
+++ b/winsup/cygwin/wait.cc
@@ -13,7 +13,6 @@ details. */
#include <stdlib.h>
#include "cygerrno.h"
#include "sigproc.h"
-#include "perthread.h"
#include "thread.h"
#include "cygtls.h"