4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-01 03:50:28 +08:00

* dcrt0.cc (set_os_type): Record OS name string.

(getprogname): Eliminate obsolete function.
(dll_crt0_1): Move initial strace initialization output to set_myself.
* exceptions.cc (interruptible): Add debugging output.
(interrupt_setup): New function.
(interrupt_now): Use interrupt_setup to set up common interrupt handler stuff.
(interrupt_on_return): Ditto.
(call_handler): Move signal_arrived arm and clear threads to region where
signalled thread is suspended or suffer races.
* pinfo.cc (set_myself): Output interesting information when strace is first
initialized.  Initialize progname here.
* sigproc.cc (sig_dispatch_pending): Modify to ensure that flush signal are
sent synchronously.
* strace.cc (strace_vsprintf): Move code into strace program.
* uname.cc (uname): Use 'osname' global to construct cygwin name + Windows type
+ version.
This commit is contained in:
Christopher Faylor 2000-02-28 05:05:33 +00:00
parent 1dc94f7370
commit d542443ea4
7 changed files with 110 additions and 153 deletions

View File

@ -1,3 +1,23 @@
Sun Feb 27 23:11:57 2000 Christopher Faylor <cgf@cygnus.com>
* dcrt0.cc (set_os_type): Record OS name string.
(getprogname): Eliminate obsolete function.
(dll_crt0_1): Move initial strace initialization output to set_myself.
* exceptions.cc (interruptible): Add debugging output.
(interrupt_setup): New function.
(interrupt_now): Use interrupt_setup to set up common interrupt handler
stuff.
(interrupt_on_return): Ditto.
(call_handler): Move signal_arrived arm and clear threads to region
where signalled thread is suspended or suffer races.
* pinfo.cc (set_myself): Output interesting information when strace is
first initialized. Initialize progname here.
* sigproc.cc (sig_dispatch_pending): Modify to ensure that flush signal
are sent synchronously.
* strace.cc (strace_vsprintf): Move code into strace program.
* uname.cc (uname): Use 'osname' global to construct cygwin name +
Windows type + version.
Fri Feb 25 19:26:42 2000 Christopher Faylor <cgf@cygnus.com> Fri Feb 25 19:26:42 2000 Christopher Faylor <cgf@cygnus.com>
* exceptions.cc (interruptible): Make a little more structured. * exceptions.cc (interruptible): Make a little more structured.

View File

@ -80,7 +80,7 @@ do_global_ctors (void (**in_pfunc)(), int force)
if (!force) if (!force)
{ {
if (user_data->forkee || user_data->run_ctors_p) if (user_data->forkee || user_data->run_ctors_p)
return; // inherit constructed stuff from parent pid return; // inherit constructed stuff from parent pid
user_data->run_ctors_p = 1; user_data->run_ctors_p = 1;
} }
@ -101,6 +101,8 @@ do_global_ctors (void (**in_pfunc)(), int force)
/* remember the type of Win32 OS being run for future use. */ /* remember the type of Win32 OS being run for future use. */
os_type NO_COPY os_being_run; os_type NO_COPY os_being_run;
char NO_COPY osname[40];
/* set_os_type: Set global variable os_being_run with type of Win32 /* set_os_type: Set global variable os_being_run with type of Win32
operating system being run. This information is used internally operating system being run. This information is used internally
to manage the inconsistency in Win32 API calls between Win32 OSes. */ to manage the inconsistency in Win32 API calls between Win32 OSes. */
@ -109,28 +111,37 @@ static void
set_os_type () set_os_type ()
{ {
OSVERSIONINFO os_version_info; OSVERSIONINFO os_version_info;
os_version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); const char *os;
memset (&os_version_info, 0, sizeof os_version_info);
os_version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
GetVersionEx (&os_version_info); GetVersionEx (&os_version_info);
switch (os_version_info.dwPlatformId) switch (os_version_info.dwPlatformId)
{ {
case VER_PLATFORM_WIN32_NT: case VER_PLATFORM_WIN32_NT:
os_being_run = winNT; os_being_run = winNT;
os = "NT";
break; break;
case VER_PLATFORM_WIN32_WINDOWS: case VER_PLATFORM_WIN32_WINDOWS:
if (os_version_info.dwMinorVersion == 0) if (os_version_info.dwMinorVersion == 0)
os_being_run = win95; {
os_being_run = win95;
os = "95";
}
else /* os_version_info.dwMinorVersion == 10 */ else /* os_version_info.dwMinorVersion == 10 */
os_being_run = win98; {
break; os_being_run = win98;
case VER_PLATFORM_WIN32s: os = "98";
os_being_run = win32s; }
break; break;
default: default:
os_being_run = unknown; os_being_run = unknown;
os = "??";
break; break;
} }
__small_sprintf (osname, "%s-%d.%d", os, os_version_info.dwMajorVersion,
os_version_info.dwMinorVersion);
} }
host_dependent_constants NO_COPY host_dependent; host_dependent_constants NO_COPY host_dependent;
@ -165,31 +176,6 @@ host_dependent_constants::init (void)
} }
} }
/* Save the program name. It's used in debugging messages and by
the fork code (forking spawns a copy of us). Copy it into a temp and
then into the final spot because debugging messages use
myself->progname. Try getting the absolute path from the
module handle, if this fails get the name from the path.
This call references $PATH so we can't do this until the environment
vars are set up. */
/* FIXME: What if argv[0] is relative, $PATH changes, and then the program
tries to do a fork? */
static void __stdcall
getprogname (char *argv0)
{
char tmp[MAX_PATH];
if (user_data->hmodule != 0)
{
if (GetModuleFileName (user_data->hmodule, tmp, MAX_PATH) == 0)
find_exec (argv0, tmp);
}
else
find_exec (argv0, tmp);
strcpy (myself->progname, tmp);
}
/* /*
* Replaces -@file in the command line with the contents of the file. * Replaces -@file in the command line with the contents of the file.
* There may be multiple -@file's in a single command line * There may be multiple -@file's in a single command line
@ -733,13 +719,6 @@ dll_crt0_1 ()
uinfo_init (); uinfo_init ();
#endif #endif
syscall_printf ("Application CYGWIN version: %d.%d, api: %d.%d",
user_data->dll_major, user_data->dll_minor,
user_data->api_major, user_data->api_minor);
syscall_printf ("CYGWIN DLL version: %d.%d, api: %d.%d",
cygwin_version.dll_major, cygwin_version.dll_minor,
cygwin_version.api_major, cygwin_version.api_minor);
/* Scan the command line and build argv. Expand wildcards if not /* Scan the command line and build argv. Expand wildcards if not
called from another cygwin process. */ called from another cygwin process. */
build_argv (line, argv, argc, build_argv (line, argv, argc,
@ -754,7 +733,6 @@ dll_crt0_1 ()
argv[0] = new_argv0; argv[0] = new_argv0;
} }
getprogname (argv[0]);
/* Set up __progname for getopt error call. */ /* Set up __progname for getopt error call. */
__progname = argv[0]; __progname = argv[0];
@ -819,11 +797,11 @@ dll_crt0 (per_process *uptr)
/* We don't want subprocesses to inherit this */ /* We don't want subprocesses to inherit this */
if (!dynamically_loaded) if (!dynamically_loaded)
{ {
if (!DuplicateHandle (me, child_proc_info->parent_alive, if (!DuplicateHandle (me, child_proc_info->parent_alive,
me, &parent_alive, 0, 0, me, &parent_alive, 0, 0,
DUPLICATE_SAME_ACCESS DUPLICATE_SAME_ACCESS
| DUPLICATE_CLOSE_SOURCE)) | DUPLICATE_CLOSE_SOURCE))
system_printf ("parent_alive DuplicateHandle failed, %E"); system_printf ("parent_alive DuplicateHandle failed, %E");
} }
else if (parent_alive) else if (parent_alive)

View File

@ -643,38 +643,33 @@ interruptible (DWORD pc)
windows_system_directory_length); windows_system_directory_length);
} }
sigproc_printf ("interruptible %d", res);
return res; return res;
# undef h # undef h
#endif #endif
} }
void static void __stdcall
interrupt_setup (int sig, struct sigaction& siga, void *handler, DWORD retaddr)
{
sigsave.retaddr = retaddr;
sigsave.oldmask = myself->getsigmask (); // Remember for restoration
/* FIXME: Not multi-thread aware */
set_process_mask (myself->getsigmask () | siga.sa_mask | SIGTOMASK (sig));
sigsave.func = (void (*)(int)) handler;
sigsave.sig = sig;
sigsave.saved_errno = -1; // Flag: no errno to save
}
static void
interrupt_now (CONTEXT *ctx, int sig, struct sigaction& siga, void *handler) interrupt_now (CONTEXT *ctx, int sig, struct sigaction& siga, void *handler)
{ {
DWORD oldmask = myself->getsigmask (); interrupt_setup (sig, siga, handler, ctx->Eip);
set_process_mask (myself->getsigmask () | siga.sa_mask | SIGTOMASK (sig)); ctx->Eip = (DWORD) sigdelayed;
DWORD *sp = (DWORD *) ctx->Esp;
*(--sp) = ctx->Eip; /* ctxinal IP where program was suspended */
*(--sp) = ctx->EFlags;
*(--sp) = ctx->Esi;
*(--sp) = ctx->Edi;
*(--sp) = ctx->Edx;
*(--sp) = ctx->Ecx;
*(--sp) = ctx->Ebx;
*(--sp) = ctx->Eax;
*(--sp) = (DWORD)-1; /* no saved errno. */
*(--sp) = oldmask;
*(--sp) = sig;
*(--sp) = (DWORD) sigreturn;
ctx->Esp = (DWORD) sp;
ctx->Eip = (DWORD) handler;
SetThreadContext (myself->getthread2signal(), ctx); /* Restart the thread */ SetThreadContext (myself->getthread2signal(), ctx); /* Restart the thread */
} }
int static int
interrupt_on_return (CONTEXT *ctx, int sig, struct sigaction& siga, void *handler) interrupt_on_return (CONTEXT *ctx, int sig, struct sigaction& siga, void *handler)
{ {
int i; int i;
@ -692,15 +687,11 @@ interrupt_on_return (CONTEXT *ctx, int sig, struct sigaction& siga, void *handle
if (interruptible (thestack->sf.AddrReturn.Offset)) if (interruptible (thestack->sf.AddrReturn.Offset))
{ {
DWORD *addr_retaddr = ((DWORD *)thestack->sf.AddrFrame.Offset) + 1; DWORD *addr_retaddr = ((DWORD *)thestack->sf.AddrFrame.Offset) + 1;
if (*addr_retaddr != thestack->sf.AddrReturn.Offset) if (*addr_retaddr == thestack->sf.AddrReturn.Offset)
break; {
sigsave.retaddr = *addr_retaddr; interrupt_setup (sig, siga, handler, *addr_retaddr);
*addr_retaddr = (DWORD) sigdelayed; *addr_retaddr = (DWORD) sigdelayed;
sigsave.oldmask = myself->getsigmask (); // Remember for restoration }
set_process_mask (myself->getsigmask () | siga.sa_mask | SIGTOMASK (sig));
sigsave.func = (void (*)(int)) handler;
sigsave.sig = sig;
sigsave.saved_errno = -1; // Flag: no errno to save
break; break;
} }
@ -720,6 +711,7 @@ call_handler (int sig, struct sigaction& siga, void *handler)
{ {
CONTEXT *cx, orig; CONTEXT *cx, orig;
int interrupted = 1; int interrupted = 1;
HANDLE hth;
int res; int res;
if (hExeced != NULL && hExeced != INVALID_HANDLE_VALUE) if (hExeced != NULL && hExeced != INVALID_HANDLE_VALUE)
@ -727,15 +719,10 @@ call_handler (int sig, struct sigaction& siga, void *handler)
SetEvent (signal_arrived); // For an EINTR case SetEvent (signal_arrived); // For an EINTR case
sigproc_printf ("armed signal_arrived"); sigproc_printf ("armed signal_arrived");
exec_exit = sig; // Maybe we'll exit with this value exec_exit = sig; // Maybe we'll exit with this value
return 1; goto out;
} }
hth = myself->getthread2signal ();
/* Suspend the running thread, grab its context somewhere safe
and run the exception handler in the context of the thread -
we have to do that since sometimes they don't return - and if
this thread doesn't return, you won't ever get another exception. */
HANDLE hth = myself->getthread2signal ();
/* Suspend the thread which will receive the signal. But first ensure that /* Suspend the thread which will receive the signal. But first ensure that
this thread doesn't have the sync_proc_subproc and mask_sync mutos, since this thread doesn't have the sync_proc_subproc and mask_sync mutos, since
we need those (hack alert). If the thread-to-be-suspended has either of we need those (hack alert). If the thread-to-be-suspended has either of
@ -792,20 +779,18 @@ call_handler (int sig, struct sigaction& siga, void *handler)
interrupted = 0; interrupted = 0;
} }
(void) ResumeThread (hth);
if (interrupted) if (interrupted)
{ {
/* Apparently we have to set signal_arrived after resuming the thread or it
is possible that the event will be ignored. */
(void) SetEvent (signal_arrived); // For an EINTR case (void) SetEvent (signal_arrived); // For an EINTR case
sigproc_printf ("armed signal_arrived %p, res %d", signal_arrived, res);
/* Clear any waiting threads prior to dispatching to handler function */ /* Clear any waiting threads prior to dispatching to handler function */
proc_subproc(PROC_CLEARWAIT, 1); proc_subproc(PROC_CLEARWAIT, 1);
} }
sigproc_printf ("armed signal_arrived %p, res %d", signal_arrived, res);
(void) ResumeThread (hth);
out: out:
sigproc_printf ("returning"); sigproc_printf ("returning %d", interrupted);
return interrupted; return interrupted;
} }
#endif /* i386 */ #endif /* i386 */

View File

@ -46,6 +46,24 @@ set_myself (pinfo *p)
__small_sprintf (buf, "cYg%8x %x %x", _STRACE_INTERFACE_ACTIVATE_ADDR, __small_sprintf (buf, "cYg%8x %x %x", _STRACE_INTERFACE_ACTIVATE_ADDR,
&strace_active); &strace_active);
OutputDebugString (buf); OutputDebugString (buf);
(void) GetModuleFileName (NULL, myself->progname,
sizeof(myself->progname));
if (strace_active)
{
extern char osname[];
strace_printf (1, "**********************************************");
strace_printf (1, "Program name: %s", myself->progname);
strace_printf (1, "App version: %d.%d, api: %d.%d",
user_data->dll_major, user_data->dll_minor,
user_data->api_major, user_data->api_minor);
strace_printf (1, "DLL version: %d.%d, api: %d.%d",
cygwin_version.dll_major, cygwin_version.dll_minor,
cygwin_version.api_major, cygwin_version.api_minor);
strace_printf (1, "OS version: Windows %s", osname);
strace_printf (1, "**********************************************");
}
return myself; return myself;
} }
@ -77,9 +95,6 @@ pinfo_init (LPBYTE info)
if (!set_myself (cygwin_shared->p.allocate_pid ())) if (!set_myself (cygwin_shared->p.allocate_pid ()))
api_fatal ("No more processes"); api_fatal ("No more processes");
(void) GetModuleFileName (NULL, myself->progname,
sizeof(myself->progname));
myself->ppid = myself->pgid = myself->sid = myself->pid; myself->ppid = myself->pgid = myself->sid = myself->pid;
myself->ctty = -1; myself->ctty = -1;
myself->uid = USHRT_MAX; myself->uid = USHRT_MAX;

View File

@ -550,7 +550,7 @@ sig_clear (int sig)
/* Force the wait_sig thread to wake up and scan the sigtodo array. /* Force the wait_sig thread to wake up and scan the sigtodo array.
*/ */
extern "C" int __stdcall extern "C" int __stdcall
sig_dispatch_pending (int force) sig_dispatch_pending (int justwake)
{ {
if (!hwait_sig) if (!hwait_sig)
return 0; return 0;
@ -559,7 +559,7 @@ sig_dispatch_pending (int force)
#ifdef DEBUGGING #ifdef DEBUGGING
sip_printf ("pending_signals %d", was_pending); sip_printf ("pending_signals %d", was_pending);
#endif #endif
if (!was_pending && !force) if (!was_pending && !justwake)
#ifdef DEBUGGING #ifdef DEBUGGING
sip_printf ("no need to wake anything up"); sip_printf ("no need to wake anything up");
#else #else
@ -568,7 +568,9 @@ sig_dispatch_pending (int force)
else else
{ {
wait_for_me (); wait_for_me ();
if (ReleaseSemaphore (sigcatch_nosync, 1, NULL)) if (!justwake)
(void) sig_send (myself, __SIGFLUSH);
else if (ReleaseSemaphore (sigcatch_nosync, 1, NULL))
#ifdef DEBUGGING #ifdef DEBUGGING
sip_printf ("woke up wait_sig"); sip_printf ("woke up wait_sig");
#else #else
@ -578,6 +580,7 @@ sig_dispatch_pending (int force)
/*sip_printf ("I'm going away now")*/; /*sip_printf ("I'm going away now")*/;
else else
system_printf ("%E releasing sigcatch_nosync(%p)", sigcatch_nosync); system_printf ("%E releasing sigcatch_nosync(%p)", sigcatch_nosync);
} }
return was_pending; return was_pending;
} }
@ -958,7 +961,7 @@ getsem (pinfo *p, const char *str, int init, int max)
DWORD winpid = GetCurrentProcessId (); DWORD winpid = GetCurrentProcessId ();
h = CreateSemaphore (allow_ntsec ? sec_user (sa_buf) : &sec_none_nih, h = CreateSemaphore (allow_ntsec ? sec_user (sa_buf) : &sec_none_nih,
init, max, str = shared_name (str, winpid)); init, max, str = shared_name (str, winpid));
p = myself; p = myself;
} }
else else

View File

@ -63,30 +63,16 @@ static int
strace_vsprintf (char *buf, const char *infmt, va_list ap) strace_vsprintf (char *buf, const char *infmt, va_list ap)
{ {
int count; int count;
char fmt[80], unkfmt[80]; char fmt[80];
static int nonewline = FALSE; static int nonewline = FALSE;
DWORD err = GetLastError (); DWORD err = GetLastError ();
const char *tn = threadname (0);
#ifndef STRACE_HHMMSS
static int lmicrosec = 0; static int lmicrosec = 0;
int microsec = strace_microseconds (); int microsec = strace_microseconds ();
int dmicrosec = lmicrosec ? microsec - lmicrosec : 0;
lmicrosec = microsec; lmicrosec = microsec;
__small_sprintf (fmt, "%5d %7d [%s] %s ", __small_sprintf (fmt, "%7d [%s] %s ", microsec, tn, "%s %d%s");
dmicrosec, microsec, threadname (0), "%s %d%s");
__small_sprintf (unkfmt, "%6d %7d [%s] %s ",
dmicrosec, microsec, threadname (0),
"(unknown)");
#else
SYSTEMTIME st;
GetLocalTime (&st);
const char *tn = threadname (0);
__small_sprintf (fmt, "%02d:%02d:%02d [%s] %s ",
st.wHour, st.wMinute, st.wSecond, tn, "%s %d%s");
__small_sprintf (unkfmt, "%02d:%02d:%02d [%s] %s ",
st.wHour, st.wMinute, st.wSecond, tn, "***");
#endif
SetLastError (err); SetLastError (err);
if (nonewline) if (nonewline)
@ -101,21 +87,15 @@ strace_vsprintf (char *buf, const char *infmt, va_list ap)
else else
{ {
char *p, progname[sizeof (myself->progname)]; char *p, progname[sizeof (myself->progname)];
static BOOL NO_COPY output_path_once = FALSE; if ((p = strrchr (myself->progname, '\\')) != NULL)
if (!output_path_once) p++;
output_path_once = !!(p = myself->progname);
else else
{ p = myself->progname;
if ((p = strrchr (myself->progname, '\\')) != NULL) strcpy (progname, p);
p++; if ((p = strrchr (progname, '.')) != NULL)
else *p = '\000';
p = myself->progname; p = progname;
strcpy (progname, p); count = __small_sprintf (buf, fmt, p && *p ? p : "?",
if ((p = strrchr (progname, '.')) != NULL)
*p = '\000';
p = progname;
}
count = __small_sprintf (buf, fmt, p && *p ? p : "(unknown)",
myself->pid, hExeced ? "!" : ""); myself->pid, hExeced ? "!" : "");
} }

View File

@ -15,16 +15,14 @@ details. */
#include "winsup.h" #include "winsup.h"
/* uname: POSIX 4.4.1.1 */ /* uname: POSIX 4.4.1.1 */
extern "C" extern "C" int
int
uname (struct utsname *name) uname (struct utsname *name)
{ {
DWORD len; DWORD len;
SYSTEM_INFO sysinfo; SYSTEM_INFO sysinfo;
OSVERSIONINFO os_version_info; extern char osname[];
os_version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); __small_sprintf (name->sysname, "CYGWIN_%s", osname);
GetVersionEx (&os_version_info);
GetSystemInfo (&sysinfo); GetSystemInfo (&sysinfo);
@ -33,28 +31,6 @@ uname (struct utsname *name)
len = sizeof (name->nodename) - 1; len = sizeof (name->nodename) - 1;
GetComputerNameA (name->nodename, &len); GetComputerNameA (name->nodename, &len);
/* Operating system type */
switch (os_being_run)
{
case winNT:
strcpy (name->sysname, "CYGWIN_NT");
break;
case win98:
strcpy (name->sysname, "CYGWIN_98");
break;
case win95:
strcpy (name->sysname, "CYGWIN_95");
break;
default:
strcpy (name->sysname, "CYGWIN_??");
break;
}
__small_sprintf (strchr (name->sysname, '\0'), "-%d.%d",
os_version_info.dwMajorVersion,
os_version_info.dwMinorVersion);
/* Cygwin dll release */ /* Cygwin dll release */
__small_sprintf (name->release, "%d.%d.%d(%d.%d/%d/%d)", __small_sprintf (name->release, "%d.%d.%d(%d.%d/%d/%d)",
cygwin_version.dll_major / 1000, cygwin_version.dll_major / 1000,