2000-02-17 20:38:33 +01:00
|
|
|
/* exceptions.cc
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|
|
|
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2009-01-03 06:12:22 +01:00
|
|
|
#define CYGTLS_HANDLE
|
2000-08-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2008-04-07 18:15:45 +02:00
|
|
|
#include "miscfuncs.h"
|
* wininfo.h (wininfo::timer_active): Delete.
(wininfo::itv): Ditto.
(wininfo::start_time): Ditto.
(wininfo::window_started): Ditto.
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(wininfo::wininfo): Ditto.
(wininfo::lock): New method.
(wininfo::release): Ditto.
* window.cc: Use new lock/acquire wininfo methods throughout.
(wininfo::wininfo): Delete
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(getitimer): Ditto.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
(wininfo::lock): Define new function.
(wininfo::release): Ditto.
(wininfo::process): Delete WM_TIMER handling.
* timer.cc (struct timetracker): Delete it, flags. Add it_interval,
interval_us, sleepto_us, running, init_muto(), syncthread, and gettime().
(ttstart): Make NO_COPY.
(lock_timer_tracker): New class.
(timer_tracker::timer_tracker): Distinguish ttstart case.
(timer_tracker::~timer_tracker): New destructor. Clean out events, and reset
magic.
(timer_tracker::init_muto): New method.
(to_us): Round up as per POSIX.
(timer_thread): Reorganize to match timer_tracker::settime and
timer_tracker::gettime. Call sig_send without wait. Call auto_release.
(timer_tracker::settime): Reorganize logic to avoid race. Call gettime to
recover old value.
(timer_tracker::gettime): New method.
(timer_create): Properly set errno on invalid timerid. Use new
lock_timer_tracker method.
(timer_delete): Ditto. Simplify code slightly.
(timer_gettime): New function.
(fixup_timers_after_fork): Reinit ttstart.
(getitimer): New implementation.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
* cygwin.din: Export timer_gettime.
* winsup.h: Remove has has_visible_window_station declaration.
* Makefile.in (DLL_OFILES): Add lsearch.o.
* cygthread.h (cygthread::notify_detached): New element.
(cygthread::cygthread): Take optional fourth argument signifying event to
signal on thread completion.
* cygthread.cc (cygthread::stub): Signal notify_detached event, if it exists.
(cygthread::cygthread): Initialize notify_detached from fourth argument.
(cygthread::detach): Wait for notify_detached field is present.
* lsearch.cc: New file.
* search.h: Ditto.
* include/cygwin/version.h: Bump API minor number to 126.
* cygwin.din: Export lsearch, lfind.
2005-03-27 03:57:38 +02:00
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
2000-08-22 07:10:20 +02:00
|
|
|
#include <imagehlp.h>
|
2001-11-15 04:25:52 +01:00
|
|
|
#include <stdlib.h>
|
2005-12-27 21:07:59 +01:00
|
|
|
#include <syslog.h>
|
2008-04-03 17:28:03 +02:00
|
|
|
#include <wchar.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
#include "cygtls.h"
|
2012-07-22 00:58:20 +02:00
|
|
|
#include "pinfo.h"
|
2003-11-28 21:55:59 +01:00
|
|
|
#include "sigproc.h"
|
2000-09-07 18:23:51 +02:00
|
|
|
#include "shared_info.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "perprocess.h"
|
2005-10-03 19:23:54 +02:00
|
|
|
#include "path.h"
|
|
|
|
#include "fhandler.h"
|
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2006-05-22 06:50:54 +02:00
|
|
|
#include "child_info.h"
|
2008-02-28 16:50:51 +01:00
|
|
|
#include "ntdll.h"
|
2010-02-28 16:54:25 +01:00
|
|
|
#include "exception.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
/* Definitions for code simplification */
|
|
|
|
#ifdef __x86_64__
|
|
|
|
# define _GR(reg) R ## reg
|
|
|
|
# define _AFMT "%011X"
|
|
|
|
# define _ADDR DWORD64
|
|
|
|
#else
|
|
|
|
# define _GR(reg) E ## reg
|
|
|
|
# define _AFMT "%08x"
|
|
|
|
# define _ADDR DWORD
|
|
|
|
#endif
|
|
|
|
|
2011-07-06 18:33:30 +02:00
|
|
|
#define CALL_HANDLER_RETRY_OUTER 10
|
|
|
|
#define CALL_HANDLER_RETRY_INNER 10
|
2000-11-07 00:12:05 +01:00
|
|
|
|
2008-02-14 17:47:11 +01:00
|
|
|
char debugger_command[2 * NT_MAX_PATH + 20];
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
static BOOL WINAPI ctrl_c_handler (DWORD);
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static const struct
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2013-01-21 05:34:52 +01:00
|
|
|
NTSTATUS code;
|
2000-02-17 20:38:33 +01:00
|
|
|
const char *name;
|
2001-10-13 03:35:15 +02:00
|
|
|
} status_info[] =
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
#define X(s) s, #s
|
|
|
|
{ X (STATUS_ABANDONED_WAIT_0) },
|
|
|
|
{ X (STATUS_ACCESS_VIOLATION) },
|
|
|
|
{ X (STATUS_ARRAY_BOUNDS_EXCEEDED) },
|
|
|
|
{ X (STATUS_BREAKPOINT) },
|
|
|
|
{ X (STATUS_CONTROL_C_EXIT) },
|
|
|
|
{ X (STATUS_DATATYPE_MISALIGNMENT) },
|
|
|
|
{ X (STATUS_FLOAT_DENORMAL_OPERAND) },
|
|
|
|
{ X (STATUS_FLOAT_DIVIDE_BY_ZERO) },
|
|
|
|
{ X (STATUS_FLOAT_INEXACT_RESULT) },
|
|
|
|
{ X (STATUS_FLOAT_INVALID_OPERATION) },
|
|
|
|
{ X (STATUS_FLOAT_OVERFLOW) },
|
|
|
|
{ X (STATUS_FLOAT_STACK_CHECK) },
|
|
|
|
{ X (STATUS_FLOAT_UNDERFLOW) },
|
|
|
|
{ X (STATUS_GUARD_PAGE_VIOLATION) },
|
|
|
|
{ X (STATUS_ILLEGAL_INSTRUCTION) },
|
|
|
|
{ X (STATUS_INTEGER_DIVIDE_BY_ZERO) },
|
|
|
|
{ X (STATUS_INTEGER_OVERFLOW) },
|
|
|
|
{ X (STATUS_INVALID_DISPOSITION) },
|
|
|
|
{ X (STATUS_IN_PAGE_ERROR) },
|
|
|
|
{ X (STATUS_NONCONTINUABLE_EXCEPTION) },
|
|
|
|
{ X (STATUS_NO_MEMORY) },
|
|
|
|
{ X (STATUS_PENDING) },
|
|
|
|
{ X (STATUS_PRIVILEGED_INSTRUCTION) },
|
|
|
|
{ X (STATUS_SINGLE_STEP) },
|
|
|
|
{ X (STATUS_STACK_OVERFLOW) },
|
|
|
|
{ X (STATUS_TIMEOUT) },
|
|
|
|
{ X (STATUS_USER_APC) },
|
|
|
|
{ X (STATUS_WAIT_0) },
|
|
|
|
{ 0, 0 }
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization code. */
|
|
|
|
|
|
|
|
void
|
2006-03-16 03:57:37 +01:00
|
|
|
init_console_handler (bool install_handler)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-06-30 04:52:14 +02:00
|
|
|
BOOL res;
|
2006-03-18 20:17:21 +01:00
|
|
|
|
2006-03-22 04:20:28 +01:00
|
|
|
SetConsoleCtrlHandler (ctrl_c_handler, FALSE);
|
2007-02-23 11:51:59 +01:00
|
|
|
SetConsoleCtrlHandler (NULL, FALSE);
|
2005-06-30 04:52:14 +02:00
|
|
|
if (install_handler)
|
|
|
|
res = SetConsoleCtrlHandler (ctrl_c_handler, TRUE);
|
|
|
|
else
|
2007-02-23 11:51:59 +01:00
|
|
|
res = SetConsoleCtrlHandler (NULL, TRUE);
|
2005-06-30 04:52:14 +02:00
|
|
|
if (!res)
|
2002-01-10 04:21:27 +01:00
|
|
|
system_printf ("SetConsoleCtrlHandler failed, %E");
|
2003-09-12 08:41:53 +02:00
|
|
|
}
|
2002-01-10 04:21:27 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
extern "C" void
|
|
|
|
error_start_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
{
|
|
|
|
debugger_command[0] = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-14 17:47:11 +01:00
|
|
|
char pgm[NT_MAX_PATH];
|
|
|
|
if (!GetModuleFileName (NULL, pgm, NT_MAX_PATH))
|
2002-07-15 05:48:52 +02:00
|
|
|
strcpy (pgm, "cygwin1.dll");
|
|
|
|
for (char *p = strchr (pgm, '\\'); p; p = strchr (p, '\\'))
|
|
|
|
*p = '/';
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-06-09 15:29:12 +02:00
|
|
|
__small_sprintf (debugger_command, "%s \"%s\"", buf, pgm);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2001-04-30 05:09:19 +02:00
|
|
|
static void
|
|
|
|
open_stackdumpfile ()
|
|
|
|
{
|
2010-08-18 16:22:07 +02:00
|
|
|
/* If we have no executable name, or if the CWD handle is NULL,
|
|
|
|
which means, the CWD is a virtual path, don't even try to open
|
|
|
|
a stackdump file. */
|
|
|
|
if (myself->progname[0] && cygheap->cwd.get_handle ())
|
2001-04-30 05:09:19 +02:00
|
|
|
{
|
2010-05-18 16:30:51 +02:00
|
|
|
const WCHAR *p;
|
2001-04-30 05:09:19 +02:00
|
|
|
/* write to progname.stackdump if possible */
|
2001-09-06 20:06:27 +02:00
|
|
|
if (!myself->progname[0])
|
2010-05-18 16:30:51 +02:00
|
|
|
p = L"unknown";
|
|
|
|
else if ((p = wcsrchr (myself->progname, L'\\')))
|
2001-04-30 05:09:19 +02:00
|
|
|
p++;
|
|
|
|
else
|
|
|
|
p = myself->progname;
|
2008-02-28 16:50:51 +01:00
|
|
|
|
2010-05-18 16:30:51 +02:00
|
|
|
WCHAR corefile[wcslen (p) + sizeof (".stackdump")];
|
2010-06-01 16:51:47 +02:00
|
|
|
wcpcpy (wcpcpy(corefile, p), L".stackdump");
|
2008-02-28 16:50:51 +01:00
|
|
|
UNICODE_STRING ucore;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2008-02-28 18:09:34 +01:00
|
|
|
/* Create the UNICODE variation of <progname>.stackdump. */
|
2010-05-18 16:30:51 +02:00
|
|
|
RtlInitUnicodeString (&ucore, corefile);
|
2008-02-28 18:09:34 +01:00
|
|
|
/* Create an object attribute which refers to <progname>.stackdump
|
2008-07-16 22:20:45 +02:00
|
|
|
in Cygwin's cwd. Stick to caseinsensitivity. */
|
2008-02-28 16:50:51 +01:00
|
|
|
InitializeObjectAttributes (&attr, &ucore, OBJ_CASE_INSENSITIVE,
|
|
|
|
cygheap->cwd.get_handle (), NULL);
|
|
|
|
HANDLE h;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
2008-02-28 18:09:34 +01:00
|
|
|
/* Try to open it to dump the stack in it. */
|
2008-02-28 16:50:51 +01:00
|
|
|
status = NtCreateFile (&h, GENERIC_WRITE | SYNCHRONIZE, &attr, &io,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT
|
2009-05-04 11:16:42 +02:00
|
|
|
| FILE_OPEN_FOR_BACKUP_INTENT, NULL, 0);
|
2008-02-28 16:50:51 +01:00
|
|
|
if (NT_SUCCESS (status))
|
2001-04-30 05:09:19 +02:00
|
|
|
{
|
2004-11-26 05:15:10 +01:00
|
|
|
if (!myself->cygstarted)
|
2008-03-02 23:51:19 +01:00
|
|
|
system_printf ("Dumping stack trace to %S", &ucore);
|
2001-10-03 05:49:26 +02:00
|
|
|
else
|
2008-03-02 23:51:19 +01:00
|
|
|
debug_printf ("Dumping stack trace to %S", &ucore);
|
2001-04-30 05:09:19 +02:00
|
|
|
SetStdHandle (STD_ERROR_HANDLE, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Utilities for dumping the stack, etc. */
|
|
|
|
|
2013-01-02 19:34:06 +01:00
|
|
|
void
|
|
|
|
cygwin_exception::dump_exception ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-08-02 21:26:01 +02:00
|
|
|
const char *exception_name = NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (e)
|
|
|
|
{
|
|
|
|
for (int i = 0; status_info[i].name; i++)
|
|
|
|
{
|
2013-01-21 05:34:52 +01:00
|
|
|
if (status_info[i].code == (NTSTATUS) e->ExceptionCode)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
exception_name = status_info[i].name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
if (exception_name)
|
|
|
|
small_printf ("Exception: %s at rip=%011X\r\n", exception_name, ctx->Rip);
|
|
|
|
else
|
|
|
|
small_printf ("Signal %d at rip=%011X\r\n", e->ExceptionCode, ctx->Rip);
|
|
|
|
small_printf ("rax=%016X rbx=%016X rcx=%016X\r\n", ctx->Rax, ctx->Rbx, ctx->Rcx);
|
|
|
|
small_printf ("rdx=%016X rsi=%016X rdi=%016X\r\n", ctx->Rdx, ctx->Rsi, ctx->Rdi);
|
|
|
|
small_printf ("r8 =%016X r9 =%016X r10=%016X\r\n", ctx->R8, ctx->R9, ctx->R10);
|
|
|
|
small_printf ("r11=%016X r12=%016X r13=%016X\r\n", ctx->R11, ctx->R12, ctx->R13);
|
|
|
|
small_printf ("r14=%016X r15=%016X\r\n", ctx->R14, ctx->R15);
|
|
|
|
small_printf ("rbp=%016X rsp=%016X\r\n", ctx->Rbp, ctx->Rsp);
|
|
|
|
small_printf ("program=%W, pid %u, thread %s\r\n",
|
|
|
|
myself->progname, myself->pid, cygthread::name ());
|
|
|
|
#else
|
2000-02-17 20:38:33 +01:00
|
|
|
if (exception_name)
|
2013-01-02 19:34:06 +01:00
|
|
|
small_printf ("Exception: %s at eip=%08x\r\n", exception_name, ctx->Eip);
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
2013-01-02 19:34:06 +01:00
|
|
|
small_printf ("Signal %d at eip=%08x\r\n", e->ExceptionCode, ctx->Eip);
|
2000-02-17 20:38:33 +01:00
|
|
|
small_printf ("eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\r\n",
|
2013-01-02 19:34:06 +01:00
|
|
|
ctx->Eax, ctx->Ebx, ctx->Ecx, ctx->Edx, ctx->Esi, ctx->Edi);
|
2010-06-29 12:28:40 +02:00
|
|
|
small_printf ("ebp=%08x esp=%08x program=%W, pid %u, thread %s\r\n",
|
2013-04-23 11:44:36 +02:00
|
|
|
ctx->Ebp, ctx->Esp, myself->progname, myself->pid,
|
|
|
|
cygthread::name ());
|
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
small_printf ("cs=%04x ds=%04x es=%04x fs=%04x gs=%04x ss=%04x\r\n",
|
2013-01-02 19:34:06 +01:00
|
|
|
ctx->SegCs, ctx->SegDs, ctx->SegEs, ctx->SegFs, ctx->SegGs, ctx->SegSs);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* A class for manipulating the stack. */
|
|
|
|
class stack_info
|
|
|
|
{
|
2000-07-04 21:07:35 +02:00
|
|
|
int walk (); /* Uses the "old" method */
|
2000-07-03 22:14:06 +02:00
|
|
|
char *next_offset () {return *((char **) sf.AddrFrame.Offset);}
|
2001-05-05 04:44:36 +02:00
|
|
|
bool needargs;
|
2013-04-23 11:44:36 +02:00
|
|
|
PUINT_PTR dummy_frame;
|
|
|
|
#ifdef __x86_64__
|
|
|
|
CONTEXT c;
|
|
|
|
UNWIND_HISTORY_TABLE hist;
|
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
public:
|
2001-05-05 04:44:36 +02:00
|
|
|
STACKFRAME sf; /* For storing the stack information */
|
2013-04-23 11:44:36 +02:00
|
|
|
void init (PUINT_PTR, bool, PCONTEXT); /* Called the first time that stack info is needed */
|
2000-03-09 22:04:05 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Postfix ++ iterates over the stack, returning zero when nothing is left. */
|
2003-02-04 04:01:17 +01:00
|
|
|
int operator ++(int) { return walk (); }
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The number of parameters used in STACKFRAME */
|
2000-07-04 21:07:35 +02:00
|
|
|
#define NPARAMS (sizeof (thestack.sf.Params) / sizeof (thestack.sf.Params[0]))
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* This is the main stack frame info for this process. */
|
2000-03-09 22:04:05 +01:00
|
|
|
static NO_COPY stack_info thestack;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Initialize everything needed to start iterating. */
|
|
|
|
void
|
2013-04-23 11:44:36 +02:00
|
|
|
stack_info::init (PUINT_PTR framep, bool wantargs, PCONTEXT ctx)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
memset (&hist, 0, sizeof hist);
|
|
|
|
if (ctx)
|
|
|
|
memcpy (&c, ctx, sizeof c);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset (&c, 0, sizeof c);
|
|
|
|
c.ContextFlags = CONTEXT_ALL;
|
|
|
|
}
|
|
|
|
#endif
|
2000-07-04 21:07:35 +02:00
|
|
|
memset (&sf, 0, sizeof (sf));
|
2013-04-23 11:44:36 +02:00
|
|
|
if (ctx)
|
|
|
|
sf.AddrFrame.Offset = (UINT_PTR) framep;
|
2001-05-05 04:44:36 +02:00
|
|
|
else
|
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
dummy_frame = framep;
|
|
|
|
sf.AddrFrame.Offset = (UINT_PTR) &dummy_frame;
|
2001-05-05 04:44:36 +02:00
|
|
|
}
|
2013-04-23 11:44:36 +02:00
|
|
|
if (framep)
|
|
|
|
sf.AddrReturn.Offset = framep[1];
|
2000-02-17 20:38:33 +01:00
|
|
|
sf.AddrFrame.Mode = AddrModeFlat;
|
2001-05-05 04:44:36 +02:00
|
|
|
needargs = wantargs;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2008-08-01 21:12:49 +02:00
|
|
|
extern "C" void _cygwin_exit_return ();
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Walk the stack by looking at successive stored 'bp' frames.
|
|
|
|
This is not foolproof. */
|
|
|
|
int
|
2000-03-09 22:04:05 +01:00
|
|
|
stack_info::walk ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
PRUNTIME_FUNCTION f;
|
|
|
|
ULONG64 imagebase;
|
|
|
|
DWORD64 establisher;
|
|
|
|
PVOID hdl;
|
|
|
|
|
|
|
|
if (!c.Rip)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sf.AddrPC.Offset = c.Rip;
|
|
|
|
sf.AddrStack.Offset = c.Rsp;
|
|
|
|
sf.AddrFrame.Offset = c.Rbp;
|
|
|
|
|
|
|
|
f = RtlLookupFunctionEntry (c.Rip, &imagebase, &hist);
|
|
|
|
if (f)
|
|
|
|
RtlVirtualUnwind (0, imagebase, c.Rip, f, &c, &hdl, &establisher, NULL);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c.Rip = *(ULONG_PTR *) c.Rsp;
|
|
|
|
c.Rsp += 8;
|
|
|
|
}
|
|
|
|
if (needargs && c.Rip)
|
|
|
|
{
|
|
|
|
PULONG_PTR p = (PULONG_PTR) c.Rsp;
|
|
|
|
for (unsigned i = 0; i < NPARAMS; ++i)
|
|
|
|
sf.Params[i] = p[i + 1];
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
char **framep;
|
2008-08-01 21:12:49 +02:00
|
|
|
|
|
|
|
if ((void (*) ()) sf.AddrPC.Offset == _cygwin_exit_return)
|
|
|
|
return 0; /* stack frames are exhausted */
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
if (((framep = (char **) next_offset ()) == NULL)
|
|
|
|
|| (framep >= (char **) cygwin_hmodule))
|
2000-02-17 20:38:33 +01:00
|
|
|
return 0;
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
sf.AddrFrame.Offset = (_ADDR) framep;
|
2001-05-05 04:44:36 +02:00
|
|
|
sf.AddrPC.Offset = sf.AddrReturn.Offset;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* The return address always follows the stack pointer */
|
2013-04-23 11:44:36 +02:00
|
|
|
sf.AddrReturn.Offset = (_ADDR) *++framep;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-05-05 04:44:36 +02:00
|
|
|
if (needargs)
|
2008-02-13 10:42:22 +01:00
|
|
|
{
|
|
|
|
unsigned nparams = NPARAMS;
|
|
|
|
|
|
|
|
/* The arguments follow the return address */
|
2013-04-23 11:44:36 +02:00
|
|
|
sf.Params[0] = (_ADDR) *++framep;
|
2008-02-13 10:42:22 +01:00
|
|
|
/* Hack for XP/2K3 WOW64. If the first stack param points to the
|
|
|
|
application entry point, we can only fetch one additional
|
|
|
|
parameter. Accessing anything beyond this address results in
|
|
|
|
a SEGV. This is fixed in Vista/2K8 WOW64. */
|
|
|
|
if (wincap.has_restricted_stack_args () && sf.Params[0] == 0x401000)
|
|
|
|
nparams = 2;
|
2008-02-27 19:08:52 +01:00
|
|
|
for (unsigned i = 1; i < nparams; i++)
|
2013-04-23 11:44:36 +02:00
|
|
|
sf.Params[i] = (_ADDR) *++framep;
|
2008-02-13 10:42:22 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
return 1;
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2011-11-26 20:14:22 +01:00
|
|
|
void
|
2013-01-02 19:34:06 +01:00
|
|
|
cygwin_exception::dumpstack ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2006-02-20 03:04:31 +01:00
|
|
|
static bool already_dumped;
|
2013-05-01 01:47:01 +02:00
|
|
|
myfault efault;
|
|
|
|
if (efault.faulted ())
|
|
|
|
return;
|
2001-04-30 05:09:19 +02:00
|
|
|
|
2012-02-12 23:43:33 +01:00
|
|
|
if (already_dumped || cygheap->rlim_core == 0Ul)
|
2001-04-30 05:09:19 +02:00
|
|
|
return;
|
2006-02-20 03:04:31 +01:00
|
|
|
already_dumped = true;
|
2012-02-12 23:43:33 +01:00
|
|
|
open_stackdumpfile ();
|
|
|
|
|
|
|
|
if (e)
|
2013-01-02 19:34:06 +01:00
|
|
|
dump_exception ();
|
2006-02-20 03:04:31 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
int i;
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
thestack.init (framep, 1, ctx); /* Initialize from the input CONTEXT */
|
|
|
|
#ifdef __x86_64__
|
|
|
|
small_printf ("Stack trace:\r\nFrame Function Args\r\n");
|
|
|
|
#else
|
2000-02-17 20:38:33 +01:00
|
|
|
small_printf ("Stack trace:\r\nFrame Function Args\r\n");
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2000-07-03 22:14:06 +02:00
|
|
|
for (i = 0; i < 16 && thestack++; i++)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
small_printf (_AFMT " " _AFMT, thestack.sf.AddrFrame.Offset,
|
2000-03-09 22:04:05 +01:00
|
|
|
thestack.sf.AddrPC.Offset);
|
2000-02-17 20:38:33 +01:00
|
|
|
for (unsigned j = 0; j < NPARAMS; j++)
|
2013-04-23 11:44:36 +02:00
|
|
|
small_printf ("%s" _AFMT, j == 0 ? " (" : ", ", thestack.sf.Params[j]);
|
2000-02-17 20:38:33 +01:00
|
|
|
small_printf (")\r\n");
|
|
|
|
}
|
2004-03-12 03:07:39 +01:00
|
|
|
small_printf ("End of stack trace%s\n",
|
2000-02-17 20:38:33 +01:00
|
|
|
i == 16 ? " (more stack frames may be present)" : "");
|
|
|
|
}
|
|
|
|
|
2007-07-29 07:22:05 +02:00
|
|
|
bool
|
|
|
|
_cygtls::inside_kernel (CONTEXT *cx)
|
2005-12-27 21:07:59 +01:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
MEMORY_BASIC_INFORMATION m;
|
2006-02-23 20:21:21 +01:00
|
|
|
|
2007-07-29 07:22:05 +02:00
|
|
|
if (!isinitialized ())
|
2006-02-23 20:21:21 +01:00
|
|
|
return true;
|
2005-12-27 21:07:59 +01:00
|
|
|
|
|
|
|
memset (&m, 0, sizeof m);
|
2013-04-23 11:44:36 +02:00
|
|
|
if (!VirtualQuery ((LPCVOID) cx->_GR(ip), &m, sizeof m))
|
|
|
|
sigproc_printf ("couldn't get memory info, pc %p, %E", cx->_GR(ip));
|
2005-12-27 21:07:59 +01:00
|
|
|
|
2008-04-03 17:28:03 +02:00
|
|
|
size_t size = (windows_system_directory_length + 6) * sizeof (WCHAR);
|
|
|
|
PWCHAR checkdir = (PWCHAR) alloca (size);
|
|
|
|
memset (checkdir, 0, size);
|
2005-12-27 21:07:59 +01:00
|
|
|
|
|
|
|
# define h ((HMODULE) m.AllocationBase)
|
2011-12-13 21:06:31 +01:00
|
|
|
if (!h || m.State != MEM_COMMIT) /* Be defensive */
|
2005-12-27 21:07:59 +01:00
|
|
|
res = true;
|
2006-02-23 20:21:21 +01:00
|
|
|
else if (h == user_data->hmodule)
|
|
|
|
res = false;
|
2008-04-03 17:28:03 +02:00
|
|
|
else if (!GetModuleFileNameW (h, checkdir, windows_system_directory_length + 6))
|
2006-02-23 20:21:21 +01:00
|
|
|
res = false;
|
2005-12-27 21:07:59 +01:00
|
|
|
else
|
2008-04-03 17:28:03 +02:00
|
|
|
{
|
|
|
|
/* Skip potential long path prefix. */
|
|
|
|
if (!wcsncmp (checkdir, L"\\\\?\\", 4))
|
|
|
|
checkdir += 4;
|
2011-12-13 21:06:31 +01:00
|
|
|
res = wcsncasecmp (windows_system_directory, checkdir,
|
|
|
|
windows_system_directory_length) == 0;
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifndef __x86_64__
|
2011-12-13 21:06:31 +01:00
|
|
|
if (!res && system_wow64_directory_length)
|
|
|
|
res = wcsncasecmp (system_wow64_directory, checkdir,
|
|
|
|
system_wow64_directory_length) == 0;
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2008-04-03 17:28:03 +02:00
|
|
|
}
|
2013-04-23 11:44:36 +02:00
|
|
|
sigproc_printf ("pc %p, h %p, inside_kernel %d", cx->_GR(ip), h, res);
|
2005-12-27 21:07:59 +01:00
|
|
|
# undef h
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Temporary (?) function for external callers to get a stack dump */
|
|
|
|
extern "C" void
|
2000-07-04 21:07:35 +02:00
|
|
|
cygwin_stackdump ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
CONTEXT c;
|
|
|
|
c.ContextFlags = CONTEXT_FULL;
|
2013-04-23 11:44:36 +02:00
|
|
|
RtlCaptureContext (&c);
|
|
|
|
cygwin_exception exc ((PUINT_PTR) c._GR(bp), &c);
|
2013-01-02 19:34:06 +01:00
|
|
|
exc.dumpstack ();
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-07-04 21:07:35 +02:00
|
|
|
#define TIME_TO_WAIT_FOR_DEBUGGER 10000
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
extern "C" int
|
2001-04-30 05:09:19 +02:00
|
|
|
try_to_debug (bool waitloop)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-01-28 06:51:15 +01:00
|
|
|
debug_printf ("debugger_command '%s'", debugger_command);
|
2005-07-17 02:51:03 +02:00
|
|
|
if (*debugger_command == '\0')
|
2000-02-17 20:38:33 +01:00
|
|
|
return 0;
|
2005-07-17 02:51:03 +02:00
|
|
|
if (being_debugged ())
|
|
|
|
{
|
2006-06-03 04:58:59 +02:00
|
|
|
extern void break_here ();
|
|
|
|
break_here ();
|
2005-07-17 02:51:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
__small_sprintf (strchr (debugger_command, '\0'), " %u", GetCurrentProcessId ());
|
|
|
|
|
2003-02-07 16:00:57 +01:00
|
|
|
LONG prio = GetThreadPriority (GetCurrentThread ());
|
|
|
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST);
|
2000-02-23 05:07:13 +01:00
|
|
|
PROCESS_INFORMATION pi = {NULL, 0, 0, 0};
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2007-12-12 13:12:24 +01:00
|
|
|
STARTUPINFOW si = {0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL};
|
2000-02-17 20:38:33 +01:00
|
|
|
si.lpReserved = NULL;
|
|
|
|
si.lpDesktop = NULL;
|
|
|
|
si.dwFlags = 0;
|
|
|
|
si.cb = sizeof (si);
|
|
|
|
|
|
|
|
/* FIXME: need to know handles of all running threads to
|
|
|
|
suspend_all_threads_except (current_thread_id);
|
|
|
|
*/
|
|
|
|
|
2010-10-24 17:26:05 +02:00
|
|
|
/* If the tty mutex is owned, we will fail to start any cygwin app
|
|
|
|
until the trapped app exits. However, this will only release any
|
|
|
|
the mutex if it is owned by this thread so that may be problematic. */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2006-06-03 22:32:07 +02:00
|
|
|
lock_ttys::release ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-04 21:07:35 +02:00
|
|
|
/* prevent recursive exception handling */
|
2008-04-03 17:28:03 +02:00
|
|
|
PWCHAR rawenv = GetEnvironmentStringsW () ;
|
|
|
|
for (PWCHAR p = rawenv; *p != L'\0'; p = wcschr (p, L'\0') + 1)
|
2000-07-04 21:07:35 +02:00
|
|
|
{
|
2008-04-03 17:28:03 +02:00
|
|
|
if (wcsncmp (p, L"CYGWIN=", wcslen (L"CYGWIN=")) == 0)
|
2000-07-04 21:07:35 +02:00
|
|
|
{
|
2008-04-03 17:28:03 +02:00
|
|
|
PWCHAR q = wcsstr (p, L"error_start") ;
|
2000-07-04 21:07:35 +02:00
|
|
|
/* replace 'error_start=...' with '_rror_start=...' */
|
2003-12-27 01:25:02 +01:00
|
|
|
if (q)
|
|
|
|
{
|
2008-04-03 17:28:03 +02:00
|
|
|
*q = L'_' ;
|
|
|
|
SetEnvironmentVariableW (L"CYGWIN", p + wcslen (L"CYGWIN=")) ;
|
2003-12-27 01:25:02 +01:00
|
|
|
}
|
2000-07-04 21:07:35 +02:00
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-15 16:50:20 +01:00
|
|
|
console_printf ("*** starting debugger for pid %u, tid %u\n",
|
|
|
|
cygwin_pid (GetCurrentProcessId ()), GetCurrentThreadId ());
|
2002-07-15 05:48:52 +02:00
|
|
|
BOOL dbg;
|
2008-12-30 19:18:09 +01:00
|
|
|
WCHAR dbg_cmd[strlen(debugger_command)];
|
|
|
|
sys_mbstowcs (dbg_cmd, strlen(debugger_command) + 1, debugger_command);
|
2007-12-12 13:12:24 +01:00
|
|
|
dbg = CreateProcessW (NULL,
|
|
|
|
dbg_cmd,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&si,
|
|
|
|
&pi);
|
2001-04-30 05:09:19 +02:00
|
|
|
|
2001-11-24 04:11:39 +01:00
|
|
|
if (!dbg)
|
2004-09-03 03:53:12 +02:00
|
|
|
system_printf ("Failed to start debugger, %E");
|
2001-11-24 04:11:39 +01:00
|
|
|
else
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-04-30 05:09:19 +02:00
|
|
|
if (!waitloop)
|
2004-02-08 20:59:27 +01:00
|
|
|
return dbg;
|
2003-02-14 03:52:29 +01:00
|
|
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
|
2002-05-27 04:25:28 +02:00
|
|
|
while (!being_debugged ())
|
2010-03-13 00:13:48 +01:00
|
|
|
yield ();
|
2004-01-26 19:52:02 +01:00
|
|
|
Sleep (2000);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2004-02-08 20:59:27 +01:00
|
|
|
console_printf ("*** continuing pid %u from debugger call (%d)\n",
|
|
|
|
cygwin_pid (GetCurrentProcessId ()), dbg);
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
SetThreadPriority (GetCurrentThread (), prio);
|
2004-02-08 20:59:27 +01:00
|
|
|
return dbg;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
/* Don't unwind the stack on x86_64. It's not necessary to do that from the
|
|
|
|
exception handler. */
|
|
|
|
#define rtl_unwind(el,er)
|
|
|
|
#else
|
|
|
|
static void __reg3 rtl_unwind (exception_list *, PEXCEPTION_RECORD) __attribute__ ((noinline, regparm (3)));
|
|
|
|
void __reg3
|
2005-12-03 06:01:51 +01:00
|
|
|
rtl_unwind (exception_list *frame, PEXCEPTION_RECORD e)
|
2005-12-03 05:23:35 +01:00
|
|
|
{
|
|
|
|
__asm__ ("\n\
|
|
|
|
pushl %%ebx \n\
|
|
|
|
pushl %%edi \n\
|
|
|
|
pushl %%esi \n\
|
|
|
|
pushl $0 \n\
|
|
|
|
pushl %1 \n\
|
|
|
|
pushl $1f \n\
|
|
|
|
pushl %0 \n\
|
|
|
|
call _RtlUnwind@16 \n\
|
|
|
|
1: \n\
|
|
|
|
popl %%esi \n\
|
|
|
|
popl %%edi \n\
|
|
|
|
popl %%ebx \n\
|
|
|
|
": : "r" (frame), "r" (e));
|
|
|
|
}
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2005-12-03 05:23:35 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Main exception handler. */
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
#define CYG_EXC_CONTINUE_EXECUTION EXCEPTION_CONTINUE_EXECUTION
|
|
|
|
#define CYG_EXC_CONTINUE_SEARCH EXCEPTION_CONTINUE_SEARCH
|
|
|
|
|
|
|
|
bool exception::handler_installed NO_COPY;
|
|
|
|
|
|
|
|
int
|
|
|
|
exception::handle (LPEXCEPTION_POINTERS ep)
|
|
|
|
#else
|
2013-05-01 01:47:01 +02:00
|
|
|
#define CYG_EXC_CONTINUE_EXECUTION ExceptionContinueExecution
|
|
|
|
#define CYG_EXC_CONTINUE_SEARCH ExceptionContinueSearch
|
2008-03-12 13:41:50 +01:00
|
|
|
|
2005-12-03 05:23:35 +01:00
|
|
|
int
|
2010-02-28 16:54:25 +01:00
|
|
|
exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, void *)
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-05-19 01:30:02 +02:00
|
|
|
static bool NO_COPY debugging;
|
2005-07-03 04:40:30 +02:00
|
|
|
_cygtls& me = _my_tls;
|
2001-04-30 05:09:19 +02:00
|
|
|
|
2013-05-01 01:47:01 +02:00
|
|
|
if (me.andreas)
|
|
|
|
me.andreas->leave (); /* Return from a "san" caught fault */
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXCEPTION_RECORD *e = ep->ExceptionRecord;
|
|
|
|
CONTEXT *in = ep->ContextRecord;
|
|
|
|
#endif
|
|
|
|
|
2001-05-24 07:20:17 +02:00
|
|
|
if (debugging && ++debugging < 500000)
|
2001-05-05 07:07:20 +02:00
|
|
|
{
|
2009-12-21 10:38:25 +01:00
|
|
|
SetThreadPriority (hMainThread, THREAD_PRIORITY_NORMAL);
|
2013-04-23 11:44:36 +02:00
|
|
|
return CYG_EXC_CONTINUE_EXECUTION;
|
2001-05-05 07:07:20 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2013-05-01 01:47:01 +02:00
|
|
|
/* If we're exiting, tell Windows to keep looking for an
|
|
|
|
exception handler. */
|
2012-12-28 19:06:17 +01:00
|
|
|
if (exit_state || e->ExceptionFlags)
|
2013-04-23 11:44:36 +02:00
|
|
|
return CYG_EXC_CONTINUE_SEARCH;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2013-01-02 19:34:06 +01:00
|
|
|
siginfo_t si = {};
|
2005-09-26 16:51:48 +02:00
|
|
|
si.si_code = SI_KERNEL;
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Coerce win32 value to posix value. */
|
2005-12-03 05:23:35 +01:00
|
|
|
switch (e->ExceptionCode)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
case STATUS_FLOAT_DENORMAL_OPERAND:
|
|
|
|
case STATUS_FLOAT_DIVIDE_BY_ZERO:
|
|
|
|
case STATUS_FLOAT_INVALID_OPERATION:
|
|
|
|
case STATUS_FLOAT_STACK_CHECK:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGFPE;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = FPE_FLTSUB;
|
2004-01-19 06:46:54 +01:00
|
|
|
break;
|
|
|
|
case STATUS_FLOAT_INEXACT_RESULT:
|
|
|
|
si.si_signo = SIGFPE;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = FPE_FLTRES;
|
2004-01-19 06:46:54 +01:00
|
|
|
break;
|
|
|
|
case STATUS_FLOAT_OVERFLOW:
|
|
|
|
si.si_signo = SIGFPE;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = FPE_FLTOVF;
|
2004-01-19 06:46:54 +01:00
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
case STATUS_FLOAT_UNDERFLOW:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGFPE;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = FPE_FLTUND;
|
2004-01-19 06:46:54 +01:00
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
case STATUS_INTEGER_DIVIDE_BY_ZERO:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGFPE;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = FPE_INTDIV;
|
2004-01-19 06:46:54 +01:00
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
case STATUS_INTEGER_OVERFLOW:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGFPE;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = FPE_INTOVF;
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_ILLEGAL_INSTRUCTION:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGILL;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = ILL_ILLOPC;
|
2004-01-19 06:46:54 +01:00
|
|
|
break;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
case STATUS_PRIVILEGED_INSTRUCTION:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGILL;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = ILL_PRVOPC;
|
2004-01-19 06:46:54 +01:00
|
|
|
break;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
case STATUS_NONCONTINUABLE_EXCEPTION:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGILL;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = ILL_ILLADR;
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_TIMEOUT:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGALRM;
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
|
2005-12-01 21:52:00 +01:00
|
|
|
case STATUS_GUARD_PAGE_VIOLATION:
|
|
|
|
si.si_signo = SIGBUS;
|
|
|
|
si.si_code = BUS_OBJERR;
|
|
|
|
break;
|
|
|
|
|
2005-12-27 21:07:59 +01:00
|
|
|
case STATUS_DATATYPE_MISALIGNMENT:
|
|
|
|
si.si_signo = SIGBUS;
|
|
|
|
si.si_code = BUS_ADRALN;
|
|
|
|
break;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
case STATUS_ACCESS_VIOLATION:
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-25 21:23:23 +02:00
|
|
|
switch (mmap_is_attached_or_noreserve ((void *)e->ExceptionInformation[1],
|
|
|
|
1))
|
2007-02-20 01:16:18 +01:00
|
|
|
{
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-25 21:23:23 +02:00
|
|
|
case MMAP_NORESERVE_COMMITED:
|
2013-04-23 11:44:36 +02:00
|
|
|
return CYG_EXC_CONTINUE_EXECUTION;
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-25 21:23:23 +02:00
|
|
|
case MMAP_RAISE_SIGBUS: /* MAP_NORESERVE page, commit failed, or
|
|
|
|
access to mmap page beyond EOF. */
|
2005-12-07 12:16:47 +01:00
|
|
|
si.si_signo = SIGBUS;
|
|
|
|
si.si_code = BUS_OBJERR;
|
2006-07-13 10:33:34 +02:00
|
|
|
break;
|
|
|
|
default:
|
2005-12-27 21:07:59 +01:00
|
|
|
MEMORY_BASIC_INFORMATION m;
|
|
|
|
VirtualQuery ((PVOID) e->ExceptionInformation[1], &m, sizeof m);
|
|
|
|
si.si_signo = SIGSEGV;
|
|
|
|
si.si_code = m.State == MEM_FREE ? SEGV_MAPERR : SEGV_ACCERR;
|
2006-07-13 10:33:34 +02:00
|
|
|
break;
|
2005-12-27 21:07:59 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
case STATUS_ARRAY_BOUNDS_EXCEEDED:
|
|
|
|
case STATUS_IN_PAGE_ERROR:
|
|
|
|
case STATUS_NO_MEMORY:
|
|
|
|
case STATUS_INVALID_DISPOSITION:
|
|
|
|
case STATUS_STACK_OVERFLOW:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGSEGV;
|
2005-09-26 15:23:47 +02:00
|
|
|
si.si_code = SEGV_MAPERR;
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_CONTROL_C_EXIT:
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = SIGINT;
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_INVALID_HANDLE:
|
|
|
|
/* CloseHandle will throw this exception if it is given an
|
|
|
|
invalid handle. We don't care about the exception; we just
|
|
|
|
want CloseHandle to return an error. This can be revisited
|
|
|
|
if gcc ever supports Windows style structured exception
|
|
|
|
handling. */
|
2013-04-23 11:44:36 +02:00
|
|
|
return CYG_EXC_CONTINUE_EXECUTION;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* If we don't recognize the exception, we have to assume that
|
|
|
|
we are doing structured exception handling, and we let
|
|
|
|
something else handle it. */
|
2013-04-23 11:44:36 +02:00
|
|
|
return CYG_EXC_CONTINUE_SEARCH;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
debug_printf ("In cygwin_except_handler exception %y at %p sp %p", e->ExceptionCode, in->_GR(ip), in->_GR(sp));
|
|
|
|
debug_printf ("In cygwin_except_handler signal %d at %p", si.si_signo, in->_GR(ip));
|
|
|
|
|
|
|
|
#ifdef __x86_64__
|
|
|
|
PUINT_PTR framep = (PUINT_PTR) in->Rbp;
|
|
|
|
/* Sometimes, when a stack is screwed up, Rbp tends to be NULL. In that
|
|
|
|
case, base the stacktrace on Rsp. In most cases, it allows to generate
|
|
|
|
useful stack trace. */
|
|
|
|
if (!framep)
|
|
|
|
framep = (PUINT_PTR) in->Rsp;
|
|
|
|
#else
|
|
|
|
PUINT_PTR framep = (PUINT_PTR) in->_GR(sp);
|
|
|
|
for (PUINT_PTR bpend = (PUINT_PTR) __builtin_frame_address (0); framep > bpend; framep--)
|
|
|
|
if (*framep == in->SegCs && framep[-1] == in->_GR(ip))
|
2000-07-03 22:14:06 +02:00
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
framep -= 2;
|
2000-07-03 22:14:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-12 13:41:50 +01:00
|
|
|
/* Temporarily replace windows top level SEH with our own handler.
|
|
|
|
We don't want any Windows magic kicking in. This top level frame
|
|
|
|
will be removed automatically after our exception handler returns. */
|
2010-02-28 16:54:25 +01:00
|
|
|
_except_list->handler = handle;
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2008-03-02 23:51:19 +01:00
|
|
|
|
2013-03-01 16:48:14 +01:00
|
|
|
if (exit_state >= ES_SIGNAL_EXIT
|
|
|
|
&& (NTSTATUS) e->ExceptionCode != STATUS_CONTROL_C_EXIT)
|
|
|
|
api_fatal ("Exception during process exit");
|
2013-01-02 19:34:06 +01:00
|
|
|
else if (!try_to_debug (0))
|
|
|
|
rtl_unwind (frame, e);
|
|
|
|
else
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2013-01-02 19:34:06 +01:00
|
|
|
debugging = true;
|
2013-04-23 11:44:36 +02:00
|
|
|
return CYG_EXC_CONTINUE_EXECUTION;
|
2013-01-02 19:34:06 +01:00
|
|
|
}
|
2005-12-27 21:07:59 +01:00
|
|
|
|
2013-03-28 17:14:53 +01:00
|
|
|
/* FIXME: Probably should be handled in signal processing code */
|
2013-01-02 19:34:06 +01:00
|
|
|
if ((NTSTATUS) e->ExceptionCode == STATUS_ACCESS_VIOLATION)
|
|
|
|
{
|
|
|
|
int error_code = 0;
|
|
|
|
if (si.si_code == SEGV_ACCERR) /* Address present */
|
|
|
|
error_code |= 1;
|
|
|
|
if (e->ExceptionInformation[0]) /* Write access */
|
|
|
|
error_code |= 2;
|
|
|
|
if (!me.inside_kernel (in)) /* User space */
|
|
|
|
error_code |= 4;
|
2013-04-23 11:44:36 +02:00
|
|
|
klog (LOG_INFO,
|
|
|
|
#ifdef __x86_64__
|
|
|
|
"%s[%d]: segfault at %011X rip %011X rsp %011X error %d",
|
|
|
|
#else
|
|
|
|
"%s[%d]: segfault at %08x rip %08x rsp %08x error %d",
|
|
|
|
#endif
|
|
|
|
__progname, myself->pid,
|
|
|
|
e->ExceptionInformation[1], in->_GR(ip), in->_GR(sp),
|
|
|
|
error_code);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2013-04-23 11:44:36 +02:00
|
|
|
cygwin_exception exc (framep, in, e);
|
2013-01-02 19:34:06 +01:00
|
|
|
si.si_cyg = (void *) &exc;
|
2013-04-23 11:44:36 +02:00
|
|
|
si.si_addr = (void *) in->_GR(ip);
|
2005-12-05 21:20:18 +01:00
|
|
|
me.incyg++;
|
2013-01-02 19:34:06 +01:00
|
|
|
sig_send (NULL, si, &me); /* Signal myself */
|
2005-12-05 21:20:18 +01:00
|
|
|
me.incyg--;
|
2005-12-03 05:23:35 +01:00
|
|
|
e->ExceptionFlags = 0;
|
2013-04-23 11:44:36 +02:00
|
|
|
return CYG_EXC_CONTINUE_EXECUTION;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Utilities to call a user supplied exception handler. */
|
|
|
|
|
2001-01-08 05:02:02 +01:00
|
|
|
#define SIG_NONMASKABLE (SIGTOMASK (SIGKILL) | SIGTOMASK (SIGSTOP))
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Non-raceable sigsuspend
|
|
|
|
* Note: This implementation is based on the Single UNIX Specification
|
|
|
|
* man page. This indicates that sigsuspend always returns -1 and that
|
|
|
|
* attempts to block unblockable signals will be silently ignored.
|
|
|
|
* This is counter to what appears to be documented in some UNIX
|
|
|
|
* man pages, e.g. Linux.
|
|
|
|
*/
|
|
|
|
int __stdcall
|
|
|
|
handle_sigsuspend (sigset_t tempmask)
|
|
|
|
{
|
2008-02-15 18:53:11 +01:00
|
|
|
sigset_t oldmask = _my_tls.sigmask; // Remember for restoration
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2012-07-22 00:58:20 +02:00
|
|
|
set_signal_mask (_my_tls.sigmask, tempmask);
|
2013-04-23 11:44:36 +02:00
|
|
|
sigproc_printf ("oldmask %ly, newmask %ly", oldmask, tempmask);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-01-14 20:55:42 +01:00
|
|
|
pthread_testcancel ();
|
2012-08-15 21:07:42 +02:00
|
|
|
cygwait (NULL, cw_infinite, cw_cancel | cw_cancel_self | cw_sig_eintr);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
set_sig_errno (EINTR); // Per POSIX
|
|
|
|
|
|
|
|
/* A signal dispatch function will have been added to our stack and will
|
|
|
|
be hit eventually. Set the old mask to be restored when the signal
|
2004-03-12 04:09:28 +01:00
|
|
|
handler returns and indicate its presence by modifying deltamask. */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-03-12 04:09:28 +01:00
|
|
|
_my_tls.deltamask |= SIG_NONMASKABLE;
|
2003-11-28 21:55:59 +01:00
|
|
|
_my_tls.oldmask = oldmask; // Will be restored by signal handler
|
2000-02-17 20:38:33 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern DWORD exec_exit; // Possible exit value for exec
|
|
|
|
|
2001-01-17 15:57:09 +01:00
|
|
|
extern "C" {
|
|
|
|
static void
|
2013-01-31 06:26:47 +01:00
|
|
|
sig_handle_tty_stop (int sig, siginfo_t *, void *)
|
2001-01-17 15:57:09 +01:00
|
|
|
{
|
2004-09-20 06:58:36 +02:00
|
|
|
/* Silently ignore attempts to suspend if there is no accommodating
|
2001-03-02 03:09:40 +01:00
|
|
|
cygwin parent to deal with this behavior. */
|
2004-11-26 05:15:10 +01:00
|
|
|
if (!myself->cygstarted)
|
2012-07-30 05:44:40 +02:00
|
|
|
myself->process_state &= ~PID_STOPPED;
|
|
|
|
else
|
2001-06-16 19:09:19 +02:00
|
|
|
{
|
2013-04-09 03:01:19 +02:00
|
|
|
_my_tls.incyg = 1;
|
2012-07-30 05:44:40 +02:00
|
|
|
myself->stopsig = sig;
|
|
|
|
myself->alert_parent (sig);
|
|
|
|
sigproc_printf ("process %d stopped by signal %d", myself->pid, sig);
|
|
|
|
/* FIXME! This does nothing to suspend anything other than the main
|
|
|
|
thread. */
|
2013-04-09 03:01:19 +02:00
|
|
|
/* Use special cygwait parameter to handle SIGCONT. _main_tls.sig will
|
|
|
|
be cleared under lock when SIGCONT is detected. */
|
|
|
|
DWORD res = cygwait (NULL, cw_infinite, cw_sig_cont);
|
2012-07-30 05:44:40 +02:00
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case WAIT_SIGNALED:
|
|
|
|
myself->stopsig = SIGCONT;
|
|
|
|
myself->alert_parent (SIGCONT);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
api_fatal ("WaitSingleObject returned %d", res);
|
|
|
|
break;
|
|
|
|
}
|
2013-04-09 03:01:19 +02:00
|
|
|
_my_tls.incyg = 0;
|
2004-01-26 23:25:57 +01:00
|
|
|
}
|
2001-01-17 15:57:09 +01:00
|
|
|
}
|
2012-07-30 05:44:40 +02:00
|
|
|
} /* end extern "C" */
|
2001-01-17 15:57:09 +01:00
|
|
|
|
2004-01-14 16:45:37 +01:00
|
|
|
bool
|
2012-08-17 19:29:21 +02:00
|
|
|
_cygtls::interrupt_now (CONTEXT *cx, siginfo_t& si, void *handler,
|
2005-12-20 01:31:50 +01:00
|
|
|
struct sigaction& siga)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-12-20 01:31:50 +01:00
|
|
|
bool interrupted;
|
|
|
|
|
2010-08-01 21:10:52 +02:00
|
|
|
/* Delay the interrupt if we are
|
|
|
|
1) somehow inside the DLL
|
2011-07-06 20:44:06 +02:00
|
|
|
2) in _sigfe (spinning is true) and about to enter cygwin DLL
|
|
|
|
3) in a Windows DLL. */
|
|
|
|
if (incyg || spinning || inside_kernel (cx))
|
2005-12-20 01:31:50 +01:00
|
|
|
interrupted = false;
|
|
|
|
else
|
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
_ADDR &ip = cx->_GR(ip);
|
|
|
|
push (ip);
|
2012-08-17 19:29:21 +02:00
|
|
|
interrupt_setup (si, handler, siga);
|
2013-04-23 11:44:36 +02:00
|
|
|
ip = pop ();
|
2005-12-20 01:31:50 +01:00
|
|
|
SetThreadContext (*this, cx); /* Restart the thread in a new location */
|
|
|
|
interrupted = true;
|
|
|
|
}
|
|
|
|
return interrupted;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2005-12-20 01:31:50 +01:00
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
void __reg3
|
2012-08-17 19:29:21 +02:00
|
|
|
_cygtls::interrupt_setup (siginfo_t& si, void *handler, struct sigaction& siga)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-12-05 21:20:18 +01:00
|
|
|
push ((__stack_t) sigdelayed);
|
2005-12-23 23:50:20 +01:00
|
|
|
deltamask = siga.sa_mask & ~SIG_NONMASKABLE;
|
2003-11-28 21:55:59 +01:00
|
|
|
sa_flags = siga.sa_flags;
|
2013-01-31 06:26:47 +01:00
|
|
|
func = (void (*) (int, siginfo_t *, void *)) handler;
|
2006-01-01 17:51:29 +01:00
|
|
|
if (siga.sa_flags & SA_RESETHAND)
|
|
|
|
siga.sa_handler = SIG_DFL;
|
2003-11-28 21:55:59 +01:00
|
|
|
saved_errno = -1; // Flag: no errno to save
|
2001-01-17 15:57:09 +01:00
|
|
|
if (handler == sig_handle_tty_stop)
|
|
|
|
{
|
|
|
|
myself->stopsig = 0;
|
|
|
|
myself->process_state |= PID_STOPPED;
|
|
|
|
}
|
2004-02-09 05:04:24 +01:00
|
|
|
|
2012-08-17 19:29:21 +02:00
|
|
|
infodata = si;
|
|
|
|
this->sig = si.si_signo; // Should always be last thing set to avoid a race
|
2004-02-09 05:04:24 +01:00
|
|
|
|
2012-08-15 20:50:44 +02:00
|
|
|
if (incyg)
|
2012-12-07 18:23:22 +01:00
|
|
|
SetEvent (get_signal_arrived (false));
|
2006-02-06 19:24:11 +01:00
|
|
|
|
2013-01-14 07:03:59 +01:00
|
|
|
if (!have_execed)
|
|
|
|
proc_subproc (PROC_CLEARWAIT, 1);
|
2012-08-17 19:29:21 +02:00
|
|
|
sigproc_printf ("armed signal_arrived %p, signal %d", signal_arrived, si.si_signo);
|
2000-02-28 06:05:33 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
extern "C" void __stdcall
|
|
|
|
set_sig_errno (int e)
|
|
|
|
{
|
2003-12-17 23:47:32 +01:00
|
|
|
*_my_tls.errno_addr = e;
|
2003-11-28 21:55:59 +01:00
|
|
|
_my_tls.saved_errno = e;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2012-08-17 19:29:21 +02:00
|
|
|
int
|
|
|
|
sigpacket::setup_handler (void *handler, struct sigaction& siga, _cygtls *tls)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-03-09 22:04:05 +01:00
|
|
|
CONTEXT cx;
|
2002-11-22 05:43:47 +01:00
|
|
|
bool interrupted = false;
|
2000-05-17 07:49:51 +02:00
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
if (tls->sig)
|
2004-01-22 20:03:19 +01:00
|
|
|
{
|
2011-11-14 02:29:49 +01:00
|
|
|
sigproc_printf ("trying to send signal %d but signal %d already armed",
|
2012-08-17 19:29:21 +02:00
|
|
|
si.si_signo, tls->sig);
|
2004-01-22 20:03:19 +01:00
|
|
|
goto out;
|
|
|
|
}
|
2000-10-18 06:53:37 +02:00
|
|
|
|
2011-07-06 18:33:30 +02:00
|
|
|
for (int n = 0; n < CALL_HANDLER_RETRY_OUTER; n++)
|
2000-05-20 07:52:33 +02:00
|
|
|
{
|
2011-07-06 18:33:30 +02:00
|
|
|
for (int i = 0; i < CALL_HANDLER_RETRY_INNER; i++)
|
2002-11-22 05:43:47 +01:00
|
|
|
{
|
2011-07-06 18:33:30 +02:00
|
|
|
tls->lock ();
|
|
|
|
if (tls->incyg)
|
|
|
|
{
|
|
|
|
sigproc_printf ("controlled interrupt. stackptr %p, stack %p, stackptr[-1] %p",
|
|
|
|
tls->stackptr, tls->stack, tls->stackptr[-1]);
|
2012-08-17 19:29:21 +02:00
|
|
|
tls->interrupt_setup (si, handler, siga);
|
2011-07-06 18:33:30 +02:00
|
|
|
interrupted = true;
|
|
|
|
tls->unlock ();
|
2011-07-13 19:53:21 +02:00
|
|
|
goto out;
|
2011-07-06 18:33:30 +02:00
|
|
|
}
|
2000-11-07 00:12:05 +01:00
|
|
|
|
2011-07-06 18:33:30 +02:00
|
|
|
DWORD res;
|
|
|
|
HANDLE hth = (HANDLE) *tls;
|
2012-08-16 19:11:41 +02:00
|
|
|
if (!hth)
|
|
|
|
sigproc_printf ("thread handle NULL, not set up yet?");
|
|
|
|
else
|
2011-07-06 18:33:30 +02:00
|
|
|
{
|
2012-08-16 19:11:41 +02:00
|
|
|
/* Suspend the thread which will receive the signal.
|
|
|
|
If one of these conditions is not true we loop.
|
|
|
|
If the thread is already suspended (which can occur when a program
|
|
|
|
has called SuspendThread on itself) then just queue the signal. */
|
|
|
|
|
|
|
|
sigproc_printf ("suspending thread, tls %p, _main_tls %p", tls, _main_tls);
|
|
|
|
res = SuspendThread (hth);
|
|
|
|
/* Just set pending if thread is already suspended */
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
ResumeThread (hth);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
cx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
|
|
|
|
if (!GetThreadContext (hth, &cx))
|
|
|
|
sigproc_printf ("couldn't get context of thread, %E");
|
|
|
|
else
|
2012-08-17 19:29:21 +02:00
|
|
|
interrupted = tls->interrupt_now (&cx, si, handler, siga);
|
2012-08-16 19:11:41 +02:00
|
|
|
|
|
|
|
tls->unlock ();
|
2011-07-06 18:33:30 +02:00
|
|
|
ResumeThread (hth);
|
2012-08-16 19:11:41 +02:00
|
|
|
if (interrupted)
|
|
|
|
goto out;
|
2011-07-06 18:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sigproc_printf ("couldn't interrupt. trying again.");
|
|
|
|
yield ();
|
|
|
|
}
|
|
|
|
/* Hit here if we couldn't deliver the signal. Take a more drastic
|
|
|
|
action before trying again. */
|
|
|
|
Sleep (1);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2003-08-28 04:04:16 +02:00
|
|
|
out:
|
2012-08-17 19:29:21 +02:00
|
|
|
sigproc_printf ("signal %d %sdelivered", si.si_signo, interrupted ? "" : "not ");
|
2000-02-24 03:49:44 +01:00
|
|
|
return interrupted;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
* wininfo.h (wininfo::timer_active): Delete.
(wininfo::itv): Ditto.
(wininfo::start_time): Ditto.
(wininfo::window_started): Ditto.
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(wininfo::wininfo): Ditto.
(wininfo::lock): New method.
(wininfo::release): Ditto.
* window.cc: Use new lock/acquire wininfo methods throughout.
(wininfo::wininfo): Delete
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(getitimer): Ditto.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
(wininfo::lock): Define new function.
(wininfo::release): Ditto.
(wininfo::process): Delete WM_TIMER handling.
* timer.cc (struct timetracker): Delete it, flags. Add it_interval,
interval_us, sleepto_us, running, init_muto(), syncthread, and gettime().
(ttstart): Make NO_COPY.
(lock_timer_tracker): New class.
(timer_tracker::timer_tracker): Distinguish ttstart case.
(timer_tracker::~timer_tracker): New destructor. Clean out events, and reset
magic.
(timer_tracker::init_muto): New method.
(to_us): Round up as per POSIX.
(timer_thread): Reorganize to match timer_tracker::settime and
timer_tracker::gettime. Call sig_send without wait. Call auto_release.
(timer_tracker::settime): Reorganize logic to avoid race. Call gettime to
recover old value.
(timer_tracker::gettime): New method.
(timer_create): Properly set errno on invalid timerid. Use new
lock_timer_tracker method.
(timer_delete): Ditto. Simplify code slightly.
(timer_gettime): New function.
(fixup_timers_after_fork): Reinit ttstart.
(getitimer): New implementation.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
* cygwin.din: Export timer_gettime.
* winsup.h: Remove has has_visible_window_station declaration.
* Makefile.in (DLL_OFILES): Add lsearch.o.
* cygthread.h (cygthread::notify_detached): New element.
(cygthread::cygthread): Take optional fourth argument signifying event to
signal on thread completion.
* cygthread.cc (cygthread::stub): Signal notify_detached event, if it exists.
(cygthread::cygthread): Initialize notify_detached from fourth argument.
(cygthread::detach): Wait for notify_detached field is present.
* lsearch.cc: New file.
* search.h: Ditto.
* include/cygwin/version.h: Bump API minor number to 126.
* cygwin.din: Export lsearch, lfind.
2005-03-27 03:57:38 +02:00
|
|
|
static inline bool
|
|
|
|
has_visible_window_station ()
|
|
|
|
{
|
|
|
|
HWINSTA station_hdl;
|
|
|
|
USEROBJECTFLAGS uof;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
/* Check if the process is associated with a visible window station.
|
|
|
|
These are processes running on the local desktop as well as processes
|
|
|
|
running in terminal server sessions.
|
|
|
|
Processes running in a service session not explicitely associated
|
|
|
|
with the desktop (using the "Allow service to interact with desktop"
|
|
|
|
property) are running in an invisible window station. */
|
|
|
|
if ((station_hdl = GetProcessWindowStation ())
|
2008-04-03 17:28:03 +02:00
|
|
|
&& GetUserObjectInformationW (station_hdl, UOI_FLAGS, &uof,
|
* wininfo.h (wininfo::timer_active): Delete.
(wininfo::itv): Ditto.
(wininfo::start_time): Ditto.
(wininfo::window_started): Ditto.
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(wininfo::wininfo): Ditto.
(wininfo::lock): New method.
(wininfo::release): Ditto.
* window.cc: Use new lock/acquire wininfo methods throughout.
(wininfo::wininfo): Delete
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(getitimer): Ditto.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
(wininfo::lock): Define new function.
(wininfo::release): Ditto.
(wininfo::process): Delete WM_TIMER handling.
* timer.cc (struct timetracker): Delete it, flags. Add it_interval,
interval_us, sleepto_us, running, init_muto(), syncthread, and gettime().
(ttstart): Make NO_COPY.
(lock_timer_tracker): New class.
(timer_tracker::timer_tracker): Distinguish ttstart case.
(timer_tracker::~timer_tracker): New destructor. Clean out events, and reset
magic.
(timer_tracker::init_muto): New method.
(to_us): Round up as per POSIX.
(timer_thread): Reorganize to match timer_tracker::settime and
timer_tracker::gettime. Call sig_send without wait. Call auto_release.
(timer_tracker::settime): Reorganize logic to avoid race. Call gettime to
recover old value.
(timer_tracker::gettime): New method.
(timer_create): Properly set errno on invalid timerid. Use new
lock_timer_tracker method.
(timer_delete): Ditto. Simplify code slightly.
(timer_gettime): New function.
(fixup_timers_after_fork): Reinit ttstart.
(getitimer): New implementation.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
* cygwin.din: Export timer_gettime.
* winsup.h: Remove has has_visible_window_station declaration.
* Makefile.in (DLL_OFILES): Add lsearch.o.
* cygthread.h (cygthread::notify_detached): New element.
(cygthread::cygthread): Take optional fourth argument signifying event to
signal on thread completion.
* cygthread.cc (cygthread::stub): Signal notify_detached event, if it exists.
(cygthread::cygthread): Initialize notify_detached from fourth argument.
(cygthread::detach): Wait for notify_detached field is present.
* lsearch.cc: New file.
* search.h: Ditto.
* include/cygwin/version.h: Bump API minor number to 126.
* cygwin.din: Export lsearch, lfind.
2005-03-27 03:57:38 +02:00
|
|
|
sizeof uof, &len)
|
|
|
|
&& (uof.dwFlags & WSF_VISIBLE))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-01-11 03:24:06 +01:00
|
|
|
/* Keyboard interrupt handler. */
|
2000-02-17 20:38:33 +01:00
|
|
|
static BOOL WINAPI
|
|
|
|
ctrl_c_handler (DWORD type)
|
|
|
|
{
|
2003-07-26 06:53:59 +02:00
|
|
|
static bool saw_close;
|
2004-02-12 04:01:58 +01:00
|
|
|
|
2011-12-10 02:33:56 +01:00
|
|
|
/* Remove early or we could overthrow the threadlist in cygheap.
|
|
|
|
Deleting this line causes ash to SEGV if CTRL-C is hit repeatedly.
|
|
|
|
I am not exactly sure why that is. Maybe it's just because this
|
|
|
|
adds some early serialization to ctrl_c_handler which prevents
|
|
|
|
multiple simultaneous calls? */
|
|
|
|
_my_tls.remove (INFINITE);
|
|
|
|
|
2005-09-07 05:10:17 +02:00
|
|
|
#if 0
|
|
|
|
if (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT)
|
|
|
|
proc_subproc (PROC_KILLFORKED, 0);
|
|
|
|
#endif
|
|
|
|
|
2001-07-26 02:10:52 +02:00
|
|
|
/* Return FALSE to prevent an "End task" dialog box from appearing
|
|
|
|
for each Cygwin process window that's open when the computer
|
|
|
|
is shut down or console window is closed. */
|
2003-07-26 06:53:59 +02:00
|
|
|
|
2001-07-26 02:10:52 +02:00
|
|
|
if (type == CTRL_SHUTDOWN_EVENT)
|
|
|
|
{
|
2003-06-12 14:36:07 +02:00
|
|
|
#if 0
|
|
|
|
/* Don't send a signal. Only NT service applications and their child
|
2003-07-26 06:53:59 +02:00
|
|
|
processes will receive this event and the services typically already
|
2003-06-12 14:36:07 +02:00
|
|
|
handle the shutdown action when getting the SERVICE_CONTROL_SHUTDOWN
|
|
|
|
control message. */
|
2001-07-26 02:10:52 +02:00
|
|
|
sig_send (NULL, SIGTERM);
|
2003-06-12 14:36:07 +02:00
|
|
|
#endif
|
2001-07-26 02:10:52 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-07-26 06:53:59 +02:00
|
|
|
|
2003-10-14 11:21:55 +02:00
|
|
|
if (myself->ctty != -1)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-07-26 06:53:59 +02:00
|
|
|
if (type == CTRL_CLOSE_EVENT)
|
2004-05-28 21:50:07 +02:00
|
|
|
{
|
2003-10-14 11:21:55 +02:00
|
|
|
sig_send (NULL, SIGHUP);
|
2004-01-19 06:46:54 +01:00
|
|
|
saw_close = true;
|
2003-10-14 11:21:55 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!saw_close && type == CTRL_LOGOFF_EVENT)
|
2004-05-28 21:50:07 +02:00
|
|
|
{
|
2006-04-18 18:24:54 +02:00
|
|
|
/* The CTRL_LOGOFF_EVENT is sent when *any* user logs off.
|
|
|
|
The below code sends a SIGHUP only if it is not performing the
|
|
|
|
default activity for SIGHUP. Note that it is possible for two
|
|
|
|
SIGHUP signals to arrive if a process group leader is exiting
|
|
|
|
too. Getting this 100% right is saved for a future cygwin mailing
|
|
|
|
list goad. */
|
|
|
|
if (global_sigs[SIGHUP].sa_handler != SIG_DFL)
|
|
|
|
{
|
2013-01-02 19:34:06 +01:00
|
|
|
sig_send (myself, SIGHUP);
|
2006-04-18 18:24:54 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2003-10-14 11:21:55 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2001-07-26 02:10:52 +02:00
|
|
|
|
2011-11-14 02:29:49 +01:00
|
|
|
if (ch_spawn.set_saw_ctrl_c ())
|
|
|
|
return TRUE;
|
2002-01-10 04:21:27 +01:00
|
|
|
|
|
|
|
/* We're only the process group leader when we have a valid pinfo structure.
|
|
|
|
If we don't have one, then the parent "stub" will handle the signal. */
|
2002-01-21 00:13:03 +01:00
|
|
|
if (!pinfo (cygwin_pid (GetCurrentProcessId ())))
|
2002-01-10 04:21:27 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2011-05-28 20:17:09 +02:00
|
|
|
tty_min *t = cygwin_shared->tty.get_cttyp ();
|
2002-01-10 04:21:27 +01:00
|
|
|
/* Ignore this if we're not the process group leader since it should be handled
|
2000-02-17 20:38:33 +01:00
|
|
|
*by* the process group leader. */
|
2012-03-29 07:45:49 +02:00
|
|
|
if (t && (!have_execed || have_execed_cygwin)
|
|
|
|
&& t->getpgid () == myself->pid &&
|
|
|
|
(GetTickCount () - t->last_ctrl_c) >= MIN_CTRL_C_SLOP)
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Otherwise we just send a SIGINT to the process group and return TRUE (to indicate
|
|
|
|
that we have handled the signal). At this point, type should be
|
|
|
|
a CTRL_C_EVENT or CTRL_BREAK_EVENT. */
|
|
|
|
{
|
2005-11-25 20:53:52 +01:00
|
|
|
int sig = SIGINT;
|
|
|
|
/* If intr and quit are both mapped to ^C, send SIGQUIT on ^BREAK */
|
|
|
|
if (type == CTRL_BREAK_EVENT
|
2005-12-22 06:57:54 +01:00
|
|
|
&& t->ti.c_cc[VINTR] == 3 && t->ti.c_cc[VQUIT] == 3)
|
|
|
|
sig = SIGQUIT;
|
2000-02-17 20:38:33 +01:00
|
|
|
t->last_ctrl_c = GetTickCount ();
|
2013-01-31 06:26:47 +01:00
|
|
|
t->kill_pgrp (sig);
|
2000-02-17 20:38:33 +01:00
|
|
|
t->last_ctrl_c = GetTickCount ();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-10 04:21:27 +01:00
|
|
|
|
2001-09-05 04:42:49 +02:00
|
|
|
return TRUE;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
/* Function used by low level sig wrappers. */
|
|
|
|
extern "C" void __stdcall
|
|
|
|
set_process_mask (sigset_t newmask)
|
|
|
|
{
|
2012-07-22 00:58:20 +02:00
|
|
|
set_signal_mask (_my_tls.sigmask, newmask);
|
2003-11-28 21:55:59 +01:00
|
|
|
}
|
|
|
|
|
2004-02-26 06:10:49 +01:00
|
|
|
extern "C" int
|
|
|
|
sighold (int sig)
|
|
|
|
{
|
|
|
|
/* check that sig is in right range */
|
|
|
|
if (sig < 0 || sig >= NSIG)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
syscall_printf ("signal %d out of range", sig);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-02-15 18:53:11 +01:00
|
|
|
sigset_t mask = _my_tls.sigmask;
|
2004-02-26 06:10:49 +01:00
|
|
|
sigaddset (&mask, sig);
|
2012-07-22 00:58:20 +02:00
|
|
|
set_signal_mask (_my_tls.sigmask, mask);
|
2004-02-26 06:10:49 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-14 19:34:03 +02:00
|
|
|
extern "C" int
|
|
|
|
sigrelse (int sig)
|
|
|
|
{
|
|
|
|
/* check that sig is in right range */
|
|
|
|
if (sig < 0 || sig >= NSIG)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
syscall_printf ("signal %d out of range", sig);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-02-15 18:53:11 +01:00
|
|
|
sigset_t mask = _my_tls.sigmask;
|
2005-04-14 19:34:03 +02:00
|
|
|
sigdelset (&mask, sig);
|
2012-07-22 00:58:20 +02:00
|
|
|
set_signal_mask (_my_tls.sigmask, mask);
|
2005-04-14 19:34:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-16 19:21:49 +01:00
|
|
|
extern "C" _sig_func_ptr
|
|
|
|
sigset (int sig, _sig_func_ptr func)
|
|
|
|
{
|
|
|
|
sig_dispatch_pending ();
|
|
|
|
_sig_func_ptr prev;
|
|
|
|
|
|
|
|
/* check that sig is in right range */
|
|
|
|
if (sig < 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
syscall_printf ("SIG_ERR = sigset (%d, %p)", sig, func);
|
|
|
|
return (_sig_func_ptr) SIG_ERR;
|
|
|
|
}
|
|
|
|
|
2008-02-15 18:53:11 +01:00
|
|
|
sigset_t mask = _my_tls.sigmask;
|
2006-02-16 19:21:49 +01:00
|
|
|
/* If sig was in the signal mask return SIG_HOLD, otherwise return the
|
|
|
|
previous disposition. */
|
|
|
|
if (sigismember (&mask, sig))
|
|
|
|
prev = SIG_HOLD;
|
|
|
|
else
|
|
|
|
prev = global_sigs[sig].sa_handler;
|
|
|
|
/* If func is SIG_HOLD, add sig to the signal mask, otherwise set the
|
|
|
|
disposition to func and remove sig from the signal mask. */
|
|
|
|
if (func == SIG_HOLD)
|
|
|
|
sigaddset (&mask, sig);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No error checking. The test which could return SIG_ERR has already
|
2006-05-28 17:50:14 +02:00
|
|
|
been made above. */
|
2006-02-16 19:21:49 +01:00
|
|
|
signal (sig, func);
|
|
|
|
sigdelset (&mask, sig);
|
|
|
|
}
|
2012-07-22 00:58:20 +02:00
|
|
|
set_signal_mask (_my_tls.sigmask, mask);
|
2006-02-16 19:21:49 +01:00
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
sigignore (int sig)
|
|
|
|
{
|
|
|
|
return sigset (sig, SIG_IGN) == SIG_ERR ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
2005-12-23 23:50:20 +01:00
|
|
|
/* Update the signal mask for this process and return the old mask.
|
2012-08-03 17:38:59 +02:00
|
|
|
Called from call_signal_handler */
|
2004-03-12 04:09:28 +01:00
|
|
|
extern "C" sigset_t
|
|
|
|
set_process_mask_delta ()
|
|
|
|
{
|
|
|
|
sigset_t newmask, oldmask;
|
|
|
|
|
|
|
|
if (_my_tls.deltamask & SIG_NONMASKABLE)
|
|
|
|
oldmask = _my_tls.oldmask; /* from handle_sigsuspend */
|
|
|
|
else
|
2008-02-15 18:53:11 +01:00
|
|
|
oldmask = _my_tls.sigmask;
|
2004-03-12 04:09:28 +01:00
|
|
|
newmask = (oldmask | _my_tls.deltamask) & ~SIG_NONMASKABLE;
|
2013-04-23 11:44:36 +02:00
|
|
|
sigproc_printf ("oldmask %lx, newmask %lx, deltamask %lx", oldmask, newmask,
|
2004-03-12 04:09:28 +01:00
|
|
|
_my_tls.deltamask);
|
2008-02-15 18:53:11 +01:00
|
|
|
_my_tls.sigmask = newmask;
|
2004-03-12 04:09:28 +01:00
|
|
|
return oldmask;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Set the signal mask for this process.
|
2000-11-16 06:16:59 +01:00
|
|
|
Note that some signals are unmaskable, as in UNIX. */
|
2012-07-22 00:58:20 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
set_signal_mask (sigset_t& setmask, sigset_t newmask)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
newmask &= ~SIG_NONMASKABLE;
|
2012-07-22 00:58:20 +02:00
|
|
|
sigset_t mask_bits = setmask & ~newmask;
|
2013-04-23 11:44:36 +02:00
|
|
|
sigproc_printf ("setmask %lx, newmask %lx, mask_bits %lx", setmask, newmask,
|
2003-12-23 17:26:31 +01:00
|
|
|
mask_bits);
|
2012-07-22 00:58:20 +02:00
|
|
|
setmask = newmask;
|
2003-12-23 17:26:31 +01:00
|
|
|
if (mask_bits)
|
2004-02-01 19:29:12 +01:00
|
|
|
sig_dispatch_pending (true);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2013-01-02 19:34:06 +01:00
|
|
|
/* Exit due to a signal. Should only be called from the signal thread. */
|
|
|
|
extern "C" {
|
|
|
|
static void
|
|
|
|
signal_exit (int sig, siginfo_t *si)
|
|
|
|
{
|
|
|
|
debug_printf ("exiting due to signal %d", sig);
|
|
|
|
exit_state = ES_SIGNAL_EXIT;
|
|
|
|
|
|
|
|
if (cygheap->rlim_core > 0UL)
|
|
|
|
switch (sig)
|
|
|
|
{
|
|
|
|
case SIGABRT:
|
|
|
|
case SIGBUS:
|
|
|
|
case SIGFPE:
|
|
|
|
case SIGILL:
|
|
|
|
case SIGQUIT:
|
|
|
|
case SIGSEGV:
|
|
|
|
case SIGSYS:
|
|
|
|
case SIGTRAP:
|
|
|
|
case SIGXCPU:
|
|
|
|
case SIGXFSZ:
|
2013-05-01 01:47:01 +02:00
|
|
|
sig |= 0x80; /* Flag that we've "dumped core" */
|
|
|
|
if (try_to_debug ())
|
|
|
|
break;
|
|
|
|
if (si->si_code != SI_USER && si->si_cyg)
|
|
|
|
((cygwin_exception *) si->si_cyg)->dumpstack ();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CONTEXT c;
|
|
|
|
c.ContextFlags = CONTEXT_FULL;
|
|
|
|
RtlCaptureContext (&c);
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
2013-05-01 01:47:01 +02:00
|
|
|
cygwin_exception exc ((PUINT_PTR) _my_tls.thread_context.rbp, &c);
|
2013-04-23 11:44:36 +02:00
|
|
|
#else
|
2013-05-01 01:47:01 +02:00
|
|
|
cygwin_exception exc ((PUINT_PTR) _my_tls.thread_context.ebp, &c);
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2013-05-01 01:47:01 +02:00
|
|
|
exc.dumpstack ();
|
|
|
|
}
|
|
|
|
break;
|
2013-01-02 19:34:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lock_process until_exit (true);
|
|
|
|
|
|
|
|
if (have_execed || exit_state > ES_PROCESS_LOCKED)
|
2013-05-01 01:47:01 +02:00
|
|
|
{
|
|
|
|
debug_printf ("recursive exit?");
|
|
|
|
myself.exit (sig);
|
|
|
|
}
|
2013-01-02 19:34:06 +01:00
|
|
|
|
|
|
|
/* Starve other threads in a vain attempt to stop them from doing something
|
|
|
|
stupid. */
|
|
|
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
|
|
|
|
|
|
|
|
sigproc_printf ("about to call do_exit (%x)", sig);
|
|
|
|
do_exit (sig);
|
|
|
|
}
|
|
|
|
} /* extern "C" */
|
|
|
|
|
2013-04-09 03:01:19 +02:00
|
|
|
/* Attempt to carefully handle SIGCONT when we are stopped. */
|
|
|
|
void
|
|
|
|
_cygtls::handle_SIGCONT ()
|
|
|
|
{
|
|
|
|
if (ISSTATE (myself, PID_STOPPED))
|
|
|
|
{
|
|
|
|
myself->stopsig = 0;
|
|
|
|
myself->process_state &= ~PID_STOPPED;
|
|
|
|
int state = 0;
|
|
|
|
/* Carefully tell sig_handle_tty_stop to wake up. */
|
|
|
|
while (state < 2)
|
2013-04-23 11:44:36 +02:00
|
|
|
{
|
|
|
|
lock ();
|
|
|
|
if (sig)
|
|
|
|
yield (); /* state <= 1 */
|
|
|
|
else if (state)
|
|
|
|
state++; /* state == 2 */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sig = SIGCONT;
|
|
|
|
SetEvent (signal_arrived);
|
|
|
|
state++; /* state == 1 */
|
|
|
|
}
|
|
|
|
unlock ();
|
|
|
|
}
|
2013-04-09 03:01:19 +02:00
|
|
|
/* Tell wait_sig to handle any queued signals now that we're alive
|
2013-04-23 11:44:36 +02:00
|
|
|
again. */
|
2013-04-09 03:01:19 +02:00
|
|
|
sig_dispatch_pending (false);
|
|
|
|
}
|
|
|
|
/* Clear pending stop signals */
|
|
|
|
sig_clear (SIGSTOP);
|
|
|
|
sig_clear (SIGTSTP);
|
|
|
|
sig_clear (SIGTTIN);
|
|
|
|
sig_clear (SIGTTOU);
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
int __reg1
|
2004-01-19 06:46:54 +01:00
|
|
|
sigpacket::process ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2013-03-31 14:35:44 +02:00
|
|
|
int rc = 1;
|
|
|
|
bool issig_wait = false;
|
|
|
|
struct sigaction& thissig = global_sigs[si.si_signo];
|
|
|
|
void *handler = have_execed ? NULL : (void *) thissig.sa_handler;
|
2006-07-17 21:30:30 +02:00
|
|
|
|
2013-04-09 03:01:19 +02:00
|
|
|
/* Don't try to send signals if we're just starting up since signal masks
|
|
|
|
may not be available. */
|
2013-03-31 14:35:44 +02:00
|
|
|
if (!cygwin_finished_initializing)
|
|
|
|
{
|
|
|
|
rc = -1;
|
2013-04-09 03:01:19 +02:00
|
|
|
goto done;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-01-19 06:46:54 +01:00
|
|
|
sigproc_printf ("signal %d processing", si.si_signo);
|
|
|
|
|
|
|
|
myself->rusage_self.ru_nsignals++;
|
|
|
|
|
2012-12-07 21:59:44 +01:00
|
|
|
_cygtls *tls;
|
2013-04-09 03:01:19 +02:00
|
|
|
if (si.si_signo == SIGCONT)
|
|
|
|
_main_tls->handle_SIGCONT ();
|
|
|
|
|
|
|
|
if (si.si_signo == SIGKILL)
|
|
|
|
tls = _main_tls; /* SIGKILL is special. It always goes through. */
|
|
|
|
else if (ISSTATE (myself, PID_STOPPED))
|
|
|
|
{
|
|
|
|
rc = -1; /* Don't send signals when stopped */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else if (!sigtls)
|
2012-12-07 18:37:33 +01:00
|
|
|
{
|
2013-03-31 14:35:44 +02:00
|
|
|
tls = cygheap->find_tls (si.si_signo, issig_wait);
|
|
|
|
sigproc_printf ("using tls %p", tls);
|
2012-12-07 18:37:33 +01:00
|
|
|
}
|
2012-07-22 00:58:20 +02:00
|
|
|
else
|
|
|
|
{
|
2013-03-31 14:35:44 +02:00
|
|
|
tls = sigtls;
|
|
|
|
if (sigismember (&tls->sigwait_mask, si.si_signo))
|
|
|
|
issig_wait = true;
|
|
|
|
else if (!sigismember (&tls->sigmask, si.si_signo))
|
|
|
|
issig_wait = false;
|
|
|
|
else
|
|
|
|
tls = NULL;
|
|
|
|
}
|
2013-04-23 11:44:36 +02:00
|
|
|
|
2013-04-09 03:01:19 +02:00
|
|
|
/* !tls means no threads available to catch a signal. */
|
|
|
|
if (!tls)
|
2013-03-31 14:35:44 +02:00
|
|
|
{
|
|
|
|
sigproc_printf ("signal %d blocked", si.si_signo);
|
|
|
|
rc = -1;
|
|
|
|
goto done;
|
2012-07-22 00:58:20 +02:00
|
|
|
}
|
2008-11-28 03:56:09 +01:00
|
|
|
|
2013-03-09 22:55:18 +01:00
|
|
|
/* Do stuff for gdb */
|
|
|
|
if ((HANDLE) *tls)
|
|
|
|
tls->signal_debugger (si);
|
|
|
|
|
2013-03-31 14:35:44 +02:00
|
|
|
if (issig_wait)
|
|
|
|
{
|
|
|
|
tls->sigwait_mask = 0;
|
|
|
|
goto dosig;
|
|
|
|
}
|
2012-12-07 21:59:44 +01:00
|
|
|
|
|
|
|
if (handler == SIG_IGN)
|
|
|
|
{
|
|
|
|
sigproc_printf ("signal %d ignored", si.si_signo);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-01-19 06:46:54 +01:00
|
|
|
if (si.si_signo == SIGKILL)
|
|
|
|
goto exit_sig;
|
2005-08-25 05:12:48 +02:00
|
|
|
if (si.si_signo == SIGSTOP)
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
{
|
2004-01-19 06:46:54 +01:00
|
|
|
sig_clear (SIGCONT);
|
|
|
|
goto stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear pending SIGCONT on stop signals */
|
|
|
|
if (si.si_signo == SIGTSTP || si.si_signo == SIGTTIN || si.si_signo == SIGTTOU)
|
|
|
|
sig_clear (SIGCONT);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (handler == (void *) SIG_DFL)
|
|
|
|
{
|
2004-01-19 06:46:54 +01:00
|
|
|
if (si.si_signo == SIGCHLD || si.si_signo == SIGIO || si.si_signo == SIGCONT || si.si_signo == SIGWINCH
|
|
|
|
|| si.si_signo == SIGURG)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2012-07-30 05:44:40 +02:00
|
|
|
sigproc_printf ("signal %d default is currently ignore", si.si_signo);
|
2000-02-17 20:38:33 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-01-19 06:46:54 +01:00
|
|
|
if (si.si_signo == SIGTSTP || si.si_signo == SIGTTIN || si.si_signo == SIGTTOU)
|
2000-02-17 20:38:33 +01:00
|
|
|
goto stop;
|
|
|
|
|
|
|
|
goto exit_sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handler == (void *) SIG_ERR)
|
|
|
|
goto exit_sig;
|
|
|
|
|
|
|
|
goto dosig;
|
|
|
|
|
2003-09-09 05:11:31 +02:00
|
|
|
stop:
|
2013-04-09 03:01:19 +02:00
|
|
|
tls = _main_tls;
|
2000-02-17 20:38:33 +01:00
|
|
|
handler = (void *) sig_handle_tty_stop;
|
2013-03-31 14:35:44 +02:00
|
|
|
thissig = global_sigs[SIGSTOP];
|
2013-01-02 19:34:06 +01:00
|
|
|
goto dosig;
|
|
|
|
|
|
|
|
exit_sig:
|
|
|
|
handler = (void *) signal_exit;
|
|
|
|
thissig.sa_flags |= SA_SIGINFO;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-09-09 05:11:31 +02:00
|
|
|
dosig:
|
2013-01-14 07:03:59 +01:00
|
|
|
if (have_execed)
|
|
|
|
{
|
|
|
|
sigproc_printf ("terminating captive process");
|
|
|
|
TerminateProcess (ch_spawn, sigExeced = si.si_signo);
|
|
|
|
}
|
2013-01-02 19:34:06 +01:00
|
|
|
/* Dispatch to the appropriate function. */
|
|
|
|
sigproc_printf ("signal %d, signal handler %p", si.si_signo, handler);
|
|
|
|
rc = setup_handler (handler, thissig, tls);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-09-09 05:11:31 +02:00
|
|
|
done:
|
2000-02-17 20:38:33 +01:00
|
|
|
sigproc_printf ("returning %d", rc);
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-02-12 04:01:58 +01:00
|
|
|
int
|
|
|
|
_cygtls::call_signal_handler ()
|
2001-04-02 02:18:29 +02:00
|
|
|
{
|
2011-12-04 18:58:24 +01:00
|
|
|
int this_sa_flags = SA_RESTART;
|
|
|
|
while (1)
|
2001-09-12 07:09:24 +02:00
|
|
|
{
|
2005-12-23 23:50:20 +01:00
|
|
|
lock ();
|
2012-07-29 23:43:29 +02:00
|
|
|
if (!sig)
|
|
|
|
{
|
|
|
|
unlock ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-03 17:38:59 +02:00
|
|
|
/* Pop the stack if the next "return address" is sigdelayed, since
|
|
|
|
this function is doing what sigdelayed would have done anyway. */
|
|
|
|
if (retaddr () == (__stack_t) sigdelayed)
|
2011-12-04 18:58:24 +01:00
|
|
|
pop ();
|
|
|
|
|
2011-12-17 01:03:31 +01:00
|
|
|
debug_only_printf ("dealing with signal %d", sig);
|
2004-02-12 04:01:58 +01:00
|
|
|
this_sa_flags = sa_flags;
|
2013-01-31 06:26:47 +01:00
|
|
|
|
|
|
|
/* Save information locally on stack to pass to handler. */
|
2004-02-12 04:01:58 +01:00
|
|
|
int thissig = sig;
|
2013-01-31 06:26:47 +01:00
|
|
|
siginfo_t thissi = infodata;
|
|
|
|
void (*thisfunc) (int, siginfo_t *, void *) = func;
|
2004-01-14 16:45:37 +01:00
|
|
|
|
2004-03-12 04:09:28 +01:00
|
|
|
sigset_t this_oldmask = set_process_mask_delta ();
|
2004-02-12 04:01:58 +01:00
|
|
|
int this_errno = saved_errno;
|
2012-07-29 23:43:29 +02:00
|
|
|
reset_signal_arrived ();
|
2013-04-09 03:01:19 +02:00
|
|
|
incyg = false;
|
|
|
|
sig = 0; /* Flag that we can accept another signal */
|
2013-01-31 06:26:47 +01:00
|
|
|
unlock (); /* unlock signal stack */
|
|
|
|
|
|
|
|
/* no ucontext_t information provided yet, so third arg is NULL */
|
|
|
|
thisfunc (thissig, &thissi, NULL);
|
2011-12-04 18:58:24 +01:00
|
|
|
incyg = true;
|
2013-01-31 06:26:47 +01:00
|
|
|
|
2012-07-22 00:58:20 +02:00
|
|
|
set_signal_mask (_my_tls.sigmask, this_oldmask);
|
2003-11-28 21:55:59 +01:00
|
|
|
if (this_errno >= 0)
|
|
|
|
set_errno (this_errno);
|
2001-09-12 07:09:24 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 21:06:31 +01:00
|
|
|
return this_sa_flags & SA_RESTART || (this != _main_tls);
|
2001-04-02 02:18:29 +02:00
|
|
|
}
|
2001-04-01 07:38:08 +02:00
|
|
|
|
2006-02-06 19:24:11 +01:00
|
|
|
void
|
2013-03-09 22:55:18 +01:00
|
|
|
_cygtls::signal_debugger (siginfo_t& si)
|
2006-02-06 19:24:11 +01:00
|
|
|
{
|
2013-03-09 22:55:18 +01:00
|
|
|
HANDLE th = NULL;
|
2006-06-03 22:32:07 +02:00
|
|
|
if (isinitialized () && being_debugged ())
|
2006-02-06 19:24:11 +01:00
|
|
|
{
|
2013-03-09 22:55:18 +01:00
|
|
|
CONTEXT c;
|
|
|
|
CONTEXT *pc;
|
|
|
|
|
|
|
|
if (si.si_cyg)
|
|
|
|
pc = ((cygwin_exception *) si.si_cyg)->context ();
|
|
|
|
else if (!(th = (HANDLE) *this))
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SuspendThread (th);
|
|
|
|
c.ContextFlags = CONTEXT_FULL;
|
|
|
|
if (GetThreadContext (th, &c))
|
|
|
|
pc = &c;
|
|
|
|
else
|
|
|
|
goto out;
|
|
|
|
if (incyg)
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
c.Rip = retaddr ();
|
|
|
|
#else
|
2013-03-09 22:55:18 +01:00
|
|
|
c.Eip = retaddr ();
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
|
|
|
memcpy (&thread_context, pc, (&thread_context._internal -
|
|
|
|
(unsigned char *) &thread_context));
|
2013-03-09 22:55:18 +01:00
|
|
|
}
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
char sigmsg[2 * sizeof (_CYGWIN_SIGNAL_STRING " ffffffff ffffffffffffffff")];
|
|
|
|
#else
|
2006-02-06 19:24:11 +01:00
|
|
|
char sigmsg[2 * sizeof (_CYGWIN_SIGNAL_STRING " ffffffff ffffffff")];
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
|
|
|
__small_sprintf (sigmsg, _CYGWIN_SIGNAL_STRING " %d %y %p", si.si_signo,
|
2013-03-09 22:55:18 +01:00
|
|
|
thread_id, &thread_context);
|
2006-02-06 19:24:11 +01:00
|
|
|
OutputDebugString (sigmsg);
|
|
|
|
}
|
2013-03-09 22:55:18 +01:00
|
|
|
out:
|
2013-04-23 11:44:36 +02:00
|
|
|
if (th)
|
|
|
|
ResumeThread (th);
|
2006-02-06 19:24:11 +01:00
|
|
|
}
|