2000-02-18 03:38:33 +08:00
|
|
|
/* exceptions.cc
|
|
|
|
|
2003-01-10 20:32:49 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-18 03:38:33 +08: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. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include <imagehlp.h>
|
2001-11-15 11:25:52 +08:00
|
|
|
#include <stdlib.h>
|
* 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 08:37:18 +08:00
|
|
|
#include <setjmp.h>
|
2003-11-29 04:55:59 +08:00
|
|
|
#include <assert.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
#include "exceptions.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "sync.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2003-11-29 04:55:59 +08:00
|
|
|
#include "cygtls.h"
|
|
|
|
#include "sigproc.h"
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
* 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 08:37:18 +08:00
|
|
|
#define NEED_VFORK
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "perthread.h"
|
2000-09-08 00:23:51 +08:00
|
|
|
#include "shared_info.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "perprocess.h"
|
|
|
|
#include "security.h"
|
2003-11-29 04:55:59 +08:00
|
|
|
#include "cygthread.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-11-07 07:12:05 +08:00
|
|
|
#define CALL_HANDLER_RETRY 20
|
|
|
|
|
2003-11-15 07:40:06 +08:00
|
|
|
char debugger_command[2 * CYG_MAX_PATH + 20];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
static int handle_exceptions (EXCEPTION_RECORD *, void *, CONTEXT *, void *);
|
|
|
|
extern void sigdelayed ();
|
|
|
|
};
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
_threadinfo NO_COPY dummy_thread;
|
|
|
|
_threadinfo NO_COPY *_last_thread = &dummy_thread;
|
|
|
|
extern _threadinfo *_main_tls;
|
|
|
|
|
2003-12-07 02:08:38 +08:00
|
|
|
CRITICAL_SECTION NO_COPY _threadinfo::protect_linked_list;
|
|
|
|
|
2000-09-16 10:36:11 +08:00
|
|
|
extern DWORD sigtid;
|
|
|
|
|
2002-01-10 11:21:27 +08:00
|
|
|
extern HANDLE hExeced;
|
|
|
|
extern DWORD dwExeced;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
static BOOL WINAPI ctrl_c_handler (DWORD);
|
2000-07-27 04:36:19 +08:00
|
|
|
static void signal_exit (int) __attribute__ ((noreturn));
|
2000-02-24 10:49:44 +08:00
|
|
|
static char windows_system_directory[1024];
|
|
|
|
static size_t windows_system_directory_length;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* This is set to indicate that we have already exited. */
|
|
|
|
|
|
|
|
static NO_COPY int exit_already = 0;
|
|
|
|
static NO_COPY muto *mask_sync = NULL;
|
|
|
|
|
2001-10-13 09:35:15 +08:00
|
|
|
NO_COPY static struct
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
unsigned int code;
|
|
|
|
const char *name;
|
2001-10-13 09:35:15 +08:00
|
|
|
} status_info[] =
|
2000-02-18 03:38:33 +08: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. */
|
|
|
|
|
|
|
|
// Set up the exception handler for the current thread. The PowerPC & Mips
|
|
|
|
// use compiler generated tables to set up the exception handlers for each
|
|
|
|
// region of code, and the kernel walks the call list until it finds a region
|
|
|
|
// of code that handles exceptions. The x86 on the other hand uses segment
|
|
|
|
// register fs, offset 0 to point to the current exception handler.
|
|
|
|
|
|
|
|
asm (".equ __except_list,0");
|
|
|
|
|
|
|
|
extern exception_list *_except_list asm ("%fs:__except_list");
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_exception_handler (exception_list *el)
|
|
|
|
{
|
|
|
|
el->handler = handle_exceptions;
|
|
|
|
el->prev = _except_list;
|
|
|
|
_except_list = el;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-09-12 14:41:53 +08:00
|
|
|
init_console_handler ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-01-10 11:21:27 +08:00
|
|
|
(void) SetConsoleCtrlHandler (ctrl_c_handler, FALSE);
|
|
|
|
if (!SetConsoleCtrlHandler (ctrl_c_handler, TRUE))
|
|
|
|
system_printf ("SetConsoleCtrlHandler failed, %E");
|
2003-09-12 14:41:53 +08:00
|
|
|
}
|
2002-01-10 11:21:27 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
extern "C" void
|
|
|
|
init_exceptions (exception_list *el)
|
|
|
|
{
|
2001-04-30 11:09:19 +08:00
|
|
|
init_exception_handler (el);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
void
|
|
|
|
_threadinfo::set_state (bool is_exception)
|
|
|
|
{
|
|
|
|
initialized = CYGTLS_INITIALIZED + is_exception;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_threadinfo::reset_exception ()
|
|
|
|
{
|
|
|
|
if (initialized == CYGTLS_EXCEPTION)
|
|
|
|
{
|
|
|
|
#ifdef DEBUGGING
|
|
|
|
debug_printf ("resetting stack after an exception stack %p, stackptr %p", stack, stackptr);
|
|
|
|
#endif
|
|
|
|
set_state (false);
|
|
|
|
stackptr--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-03 13:21:55 +08:00
|
|
|
void
|
|
|
|
_threadinfo::call (void (*func) (void *, void *), void *arg)
|
|
|
|
{
|
|
|
|
char buf[CYGTLS_PADSIZE];
|
|
|
|
_my_tls.call2 (func, arg, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_threadinfo::call2 (void (*func) (void *, void *), void *arg, void *buf)
|
|
|
|
{
|
2003-12-07 02:08:38 +08:00
|
|
|
init_thread (buf);
|
2003-12-03 13:21:55 +08:00
|
|
|
func (arg, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-12-07 02:08:38 +08:00
|
|
|
_threadinfo::init ()
|
|
|
|
{
|
|
|
|
InitializeCriticalSection (&protect_linked_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_threadinfo::init_thread (void *)
|
2003-11-29 04:55:59 +08:00
|
|
|
{
|
|
|
|
memset (this, 0, sizeof (*this));
|
|
|
|
stackptr = stack;
|
2003-12-07 02:08:38 +08:00
|
|
|
|
|
|
|
EnterCriticalSection (&protect_linked_list);
|
2003-11-29 04:55:59 +08:00
|
|
|
prev = _last_thread;
|
|
|
|
_last_thread->next = this;
|
|
|
|
_last_thread = this;
|
2003-12-07 02:08:38 +08:00
|
|
|
LeaveCriticalSection (&protect_linked_list);
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
set_state (false);
|
|
|
|
errno_addr = &errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_threadinfo::remove ()
|
|
|
|
{
|
2003-12-07 02:08:38 +08:00
|
|
|
EnterCriticalSection (&protect_linked_list);
|
2003-12-07 11:27:51 +08:00
|
|
|
if (prev)
|
2003-12-07 10:33:31 +08:00
|
|
|
{
|
2003-12-07 11:27:51 +08:00
|
|
|
prev->next = next;
|
|
|
|
if (next)
|
|
|
|
next->prev = prev;
|
|
|
|
if (this == _last_thread)
|
|
|
|
_last_thread = prev;
|
|
|
|
prev = next = NULL;
|
2003-12-07 10:33:31 +08:00
|
|
|
}
|
2003-12-07 02:08:38 +08:00
|
|
|
LeaveCriticalSection (&protect_linked_list);
|
2003-11-29 04:55:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_threadinfo::push (__stack_t addr, bool exception)
|
|
|
|
{
|
|
|
|
*stackptr++ = (__stack_t) addr;
|
|
|
|
set_state (exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
__stack_t
|
|
|
|
_threadinfo::pop ()
|
|
|
|
{
|
|
|
|
#ifdef DEBUGGING
|
|
|
|
assert (stackptr > stack);
|
|
|
|
#endif
|
|
|
|
__stack_t res = *--stackptr;
|
2003-11-30 10:19:45 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
*stackptr = 0;
|
2003-11-29 04:55:59 +08:00
|
|
|
debug_printf ("popped %p, stack %p, stackptr %p", res, stack, stackptr);
|
|
|
|
#endif
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
extern "C" void
|
|
|
|
error_start_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
{
|
|
|
|
debugger_command[0] = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-15 07:40:06 +08:00
|
|
|
char pgm[CYG_MAX_PATH + 1];
|
|
|
|
if (!GetModuleFileName (NULL, pgm, CYG_MAX_PATH))
|
2002-07-15 11:48:52 +08:00
|
|
|
strcpy (pgm, "cygwin1.dll");
|
|
|
|
for (char *p = strchr (pgm, '\\'); p; p = strchr (p, '\\'))
|
|
|
|
*p = '/';
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-06-09 21:29:12 +08:00
|
|
|
__small_sprintf (debugger_command, "%s \"%s\"", buf, pgm);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-04-30 11:09:19 +08:00
|
|
|
static void
|
|
|
|
open_stackdumpfile ()
|
|
|
|
{
|
|
|
|
if (myself->progname[0])
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
/* write to progname.stackdump if possible */
|
2001-09-07 02:06:27 +08:00
|
|
|
if (!myself->progname[0])
|
|
|
|
p = "unknown";
|
|
|
|
else if ((p = strrchr (myself->progname, '\\')))
|
2001-04-30 11:09:19 +08:00
|
|
|
p++;
|
|
|
|
else
|
|
|
|
p = myself->progname;
|
|
|
|
char corefile[strlen (p) + sizeof (".stackdump")];
|
|
|
|
__small_sprintf (corefile, "%s.stackdump", p);
|
|
|
|
HANDLE h = CreateFile (corefile, GENERIC_WRITE, 0, &sec_none_nih,
|
|
|
|
CREATE_ALWAYS, 0, 0);
|
|
|
|
if (h != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2001-10-03 11:49:26 +08:00
|
|
|
if (!myself->ppid_handle)
|
|
|
|
system_printf ("Dumping stack trace to %s", corefile);
|
|
|
|
else
|
|
|
|
debug_printf ("Dumping stack trace to %s", corefile);
|
2001-04-30 11:09:19 +08:00
|
|
|
SetStdHandle (STD_ERROR_HANDLE, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Utilities for dumping the stack, etc. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
exception (EXCEPTION_RECORD *e, CONTEXT *in)
|
|
|
|
{
|
2000-08-03 03:26:01 +08:00
|
|
|
const char *exception_name = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (e)
|
|
|
|
{
|
|
|
|
for (int i = 0; status_info[i].name; i++)
|
|
|
|
{
|
|
|
|
if (status_info[i].code == e->ExceptionCode)
|
|
|
|
{
|
|
|
|
exception_name = status_info[i].name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
#define HAVE_STATUS
|
|
|
|
if (exception_name)
|
|
|
|
small_printf ("Exception: %s at eip=%08x\r\n", exception_name, in->Eip);
|
|
|
|
else
|
|
|
|
small_printf ("Exception %d at eip=%08x\r\n", e->ExceptionCode, in->Eip);
|
|
|
|
small_printf ("eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\r\n",
|
|
|
|
in->Eax, in->Ebx, in->Ecx, in->Edx, in->Esi, in->Edi);
|
|
|
|
small_printf ("ebp=%08x esp=%08x program=%s\r\n",
|
|
|
|
in->Ebp, in->Esp, myself->progname);
|
|
|
|
small_printf ("cs=%04x ds=%04x es=%04x fs=%04x gs=%04x ss=%04x\r\n",
|
|
|
|
in->SegCs, in->SegDs, in->SegEs, in->SegFs, in->SegGs, in->SegSs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STATUS
|
|
|
|
system_printf ("Had an exception");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
/* Print a stack backtrace. */
|
|
|
|
|
|
|
|
#define HAVE_STACK_TRACE
|
|
|
|
|
|
|
|
/* A class for manipulating the stack. */
|
|
|
|
class stack_info
|
|
|
|
{
|
2000-07-05 03:07:35 +08:00
|
|
|
int walk (); /* Uses the "old" method */
|
2000-07-04 04:14:06 +08:00
|
|
|
char *next_offset () {return *((char **) sf.AddrFrame.Offset);}
|
2001-05-05 10:44:36 +08:00
|
|
|
bool needargs;
|
|
|
|
DWORD dummy_frame;
|
2000-02-18 03:38:33 +08:00
|
|
|
public:
|
2001-05-05 10:44:36 +08:00
|
|
|
STACKFRAME sf; /* For storing the stack information */
|
|
|
|
void init (DWORD, bool, bool); /* Called the first time that stack info is needed */
|
2000-03-10 05:04:05 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Postfix ++ iterates over the stack, returning zero when nothing is left. */
|
2003-02-04 11:01:17 +08:00
|
|
|
int operator ++(int) { return walk (); }
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The number of parameters used in STACKFRAME */
|
2000-07-05 03:07:35 +08:00
|
|
|
#define NPARAMS (sizeof (thestack.sf.Params) / sizeof (thestack.sf.Params[0]))
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* This is the main stack frame info for this process. */
|
2000-03-10 05:04:05 +08:00
|
|
|
static NO_COPY stack_info thestack;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Initialize everything needed to start iterating. */
|
|
|
|
void
|
2001-05-05 10:44:36 +08:00
|
|
|
stack_info::init (DWORD ebp, bool wantargs, bool goodframe)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-30 11:09:19 +08:00
|
|
|
# define debp ((DWORD *) ebp)
|
2000-07-05 03:07:35 +08:00
|
|
|
memset (&sf, 0, sizeof (sf));
|
2001-05-05 10:44:36 +08:00
|
|
|
if (!goodframe)
|
|
|
|
sf.AddrFrame.Offset = ebp;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dummy_frame = ebp;
|
|
|
|
sf.AddrFrame.Offset = (DWORD) &dummy_frame;
|
|
|
|
}
|
2001-04-30 11:09:19 +08:00
|
|
|
sf.AddrReturn.Offset = debp[1];
|
2000-02-18 03:38:33 +08:00
|
|
|
sf.AddrFrame.Mode = AddrModeFlat;
|
2001-05-05 10:44:36 +08:00
|
|
|
needargs = wantargs;
|
2001-04-30 11:09:19 +08:00
|
|
|
# undef debp
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk the stack by looking at successive stored 'bp' frames.
|
|
|
|
This is not foolproof. */
|
|
|
|
int
|
2000-03-10 05:04:05 +08:00
|
|
|
stack_info::walk ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
char **ebp;
|
2001-05-05 10:44:36 +08:00
|
|
|
if ((ebp = (char **) next_offset ()) == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
|
2001-05-05 10:44:36 +08:00
|
|
|
sf.AddrFrame.Offset = (DWORD) ebp;
|
|
|
|
sf.AddrPC.Offset = sf.AddrReturn.Offset;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (!sf.AddrPC.Offset)
|
|
|
|
return 0; /* stack frames are exhausted */
|
|
|
|
|
|
|
|
/* The return address always follows the stack pointer */
|
|
|
|
sf.AddrReturn.Offset = (DWORD) *++ebp;
|
|
|
|
|
2001-05-05 10:44:36 +08:00
|
|
|
if (needargs)
|
|
|
|
/* The arguments follow the return address */
|
|
|
|
for (unsigned i = 0; i < NPARAMS; i++)
|
|
|
|
sf.Params[i] = (DWORD) *++ebp;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-07-04 04:14:06 +08:00
|
|
|
static void
|
2001-05-05 10:44:36 +08:00
|
|
|
stackdump (DWORD ebp, int open_file, bool isexception)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-30 11:09:19 +08:00
|
|
|
extern unsigned long rlim_core;
|
|
|
|
|
|
|
|
if (rlim_core == 0UL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (open_file)
|
|
|
|
open_stackdumpfile ();
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int i;
|
|
|
|
|
2001-05-05 10:44:36 +08:00
|
|
|
thestack.init (ebp, 1, !isexception); /* Initialize from the input CONTEXT */
|
2000-02-18 03:38:33 +08:00
|
|
|
small_printf ("Stack trace:\r\nFrame Function Args\r\n");
|
2000-07-04 04:14:06 +08:00
|
|
|
for (i = 0; i < 16 && thestack++; i++)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-03-10 05:04:05 +08:00
|
|
|
small_printf ("%08x %08x ", thestack.sf.AddrFrame.Offset,
|
|
|
|
thestack.sf.AddrPC.Offset);
|
2000-02-18 03:38:33 +08:00
|
|
|
for (unsigned j = 0; j < NPARAMS; j++)
|
2000-03-10 05:04:05 +08:00
|
|
|
small_printf ("%s%08x", j == 0 ? " (" : ", ", thestack.sf.Params[j]);
|
2000-02-18 03:38:33 +08:00
|
|
|
small_printf (")\r\n");
|
|
|
|
}
|
|
|
|
small_printf ("End of stack trace%s",
|
|
|
|
i == 16 ? " (more stack frames may be present)" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Temporary (?) function for external callers to get a stack dump */
|
|
|
|
extern "C" void
|
2000-07-05 03:07:35 +08:00
|
|
|
cygwin_stackdump ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
CONTEXT c;
|
|
|
|
c.ContextFlags = CONTEXT_FULL;
|
2000-05-07 11:29:08 +08:00
|
|
|
GetThreadContext (GetCurrentThread (), &c);
|
2001-05-05 10:44:36 +08:00
|
|
|
stackdump (c.Ebp, 0, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-07-05 03:07:35 +08:00
|
|
|
#define TIME_TO_WAIT_FOR_DEBUGGER 10000
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
extern "C" int
|
2001-04-30 11:09:19 +08:00
|
|
|
try_to_debug (bool waitloop)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-01-28 13:51:15 +08:00
|
|
|
debug_printf ("debugger_command '%s'", debugger_command);
|
2002-10-15 04:25:52 +08:00
|
|
|
if (*debugger_command == '\0' || being_debugged ())
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
__small_sprintf (strchr (debugger_command, '\0'), " %u", GetCurrentProcessId ());
|
|
|
|
|
2003-02-07 23:00:57 +08:00
|
|
|
LONG prio = GetThreadPriority (GetCurrentThread ());
|
|
|
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST);
|
2000-02-23 12:07:13 +08:00
|
|
|
PROCESS_INFORMATION pi = {NULL, 0, 0, 0};
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-02-23 12:07:13 +08:00
|
|
|
STARTUPINFO si = {0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL};
|
2000-02-18 03:38:33 +08: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);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* if any of these mutexes is owned, we will fail to start any cygwin app
|
|
|
|
until trapped app exits */
|
|
|
|
|
|
|
|
ReleaseMutex (title_mutex);
|
|
|
|
|
2000-07-05 03:07:35 +08:00
|
|
|
/* prevent recursive exception handling */
|
|
|
|
char* rawenv = GetEnvironmentStrings () ;
|
|
|
|
for (char* p = rawenv; *p != '\0'; p = strchr (p, '\0') + 1)
|
|
|
|
{
|
|
|
|
if (strncmp (p, "CYGWIN=", sizeof ("CYGWIN=") - 1) == 0)
|
|
|
|
{
|
|
|
|
char* q = strstr (p, "error_start") ;
|
|
|
|
/* replace 'error_start=...' with '_rror_start=...' */
|
|
|
|
if (q) *q = '_' ;
|
|
|
|
SetEnvironmentVariable ("CYGWIN", p + sizeof ("CYGWIN=")) ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-15 11:48:52 +08:00
|
|
|
BOOL dbg;
|
2000-02-18 03:38:33 +08:00
|
|
|
dbg = CreateProcess (NULL,
|
|
|
|
debugger_command,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&si,
|
|
|
|
&pi);
|
2001-04-30 11:09:19 +08:00
|
|
|
|
2001-11-24 11:11:39 +08:00
|
|
|
if (!dbg)
|
|
|
|
system_printf ("Failed to start debugger: %E");
|
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-30 11:09:19 +08:00
|
|
|
if (!waitloop)
|
|
|
|
return 1;
|
2003-02-14 10:52:29 +08:00
|
|
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
|
2002-05-27 10:25:28 +08:00
|
|
|
while (!being_debugged ())
|
2003-02-07 23:00:57 +08:00
|
|
|
Sleep (0);
|
|
|
|
Sleep (2000);
|
2001-11-24 11:11:39 +08:00
|
|
|
small_printf ("*** continuing from debugger call\n");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
SetThreadPriority (GetCurrentThread (), prio);
|
2001-04-30 11:09:19 +08:00
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Main exception handler. */
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
extern "C" DWORD __stdcall RtlUnwind (void *, void *, void *, DWORD);
|
2000-02-18 03:38:33 +08:00
|
|
|
static int
|
2003-11-29 04:55:59 +08:00
|
|
|
handle_exceptions (EXCEPTION_RECORD *e0, void *frame, CONTEXT *in0, void *)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
static bool NO_COPY debugging = false;
|
2001-04-30 11:09:19 +08:00
|
|
|
static int NO_COPY recursed = 0;
|
|
|
|
|
2001-05-24 13:20:17 +08:00
|
|
|
if (debugging && ++debugging < 500000)
|
2001-05-05 13:07:20 +08:00
|
|
|
{
|
|
|
|
SetThreadPriority (hMainThread, THREAD_PRIORITY_NORMAL);
|
|
|
|
return 0;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* If we've already exited, don't do anything here. Returning 1
|
|
|
|
tells Windows to keep looking for an exception handler. */
|
|
|
|
if (exit_already)
|
|
|
|
return 1;
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
EXCEPTION_RECORD e = *e0;
|
|
|
|
CONTEXT in = *in0;
|
|
|
|
|
|
|
|
extern DWORD ret_here[];
|
|
|
|
RtlUnwind (frame, ret_here, e0, 0);
|
|
|
|
__asm__ volatile (".equ _ret_here,.");
|
|
|
|
|
|
|
|
int sig;
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Coerce win32 value to posix value. */
|
2003-11-29 04:55:59 +08:00
|
|
|
switch (e.ExceptionCode)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
case STATUS_FLOAT_DENORMAL_OPERAND:
|
|
|
|
case STATUS_FLOAT_DIVIDE_BY_ZERO:
|
|
|
|
case STATUS_FLOAT_INEXACT_RESULT:
|
|
|
|
case STATUS_FLOAT_INVALID_OPERATION:
|
|
|
|
case STATUS_FLOAT_OVERFLOW:
|
|
|
|
case STATUS_FLOAT_STACK_CHECK:
|
|
|
|
case STATUS_FLOAT_UNDERFLOW:
|
|
|
|
case STATUS_INTEGER_DIVIDE_BY_ZERO:
|
|
|
|
case STATUS_INTEGER_OVERFLOW:
|
|
|
|
sig = SIGFPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_ILLEGAL_INSTRUCTION:
|
|
|
|
case STATUS_PRIVILEGED_INSTRUCTION:
|
|
|
|
case STATUS_NONCONTINUABLE_EXCEPTION:
|
|
|
|
sig = SIGILL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_TIMEOUT:
|
|
|
|
sig = SIGALRM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_ACCESS_VIOLATION:
|
|
|
|
case STATUS_DATATYPE_MISALIGNMENT:
|
|
|
|
case STATUS_ARRAY_BOUNDS_EXCEEDED:
|
|
|
|
case STATUS_GUARD_PAGE_VIOLATION:
|
|
|
|
case STATUS_IN_PAGE_ERROR:
|
|
|
|
case STATUS_NO_MEMORY:
|
|
|
|
case STATUS_INVALID_DISPOSITION:
|
|
|
|
case STATUS_STACK_OVERFLOW:
|
|
|
|
sig = SIGSEGV;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_CONTROL_C_EXIT:
|
|
|
|
sig = SIGINT;
|
|
|
|
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. */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
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. */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
debug_printf ("In cygwin_except_handler exc %p at %p sp %p", e.ExceptionCode, in.Eip, in.Esp);
|
|
|
|
debug_printf ("In cygwin_except_handler sig = %d at %p", sig, in.Eip);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-11-29 06:13:57 +08:00
|
|
|
if (global_sigs[sig].sa_mask & SIGTOMASK (sig))
|
|
|
|
syscall_printf ("signal %d, masked %p", sig, global_sigs[sig].sa_mask);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-04 04:14:06 +08:00
|
|
|
debug_printf ("In cygwin_except_handler calling %p",
|
2003-11-29 06:13:57 +08:00
|
|
|
global_sigs[sig].sa_handler);
|
2000-07-04 04:14:06 +08:00
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
DWORD *ebp = (DWORD *)in.Esp;
|
2000-07-04 04:14:06 +08:00
|
|
|
for (DWORD *bpend = (DWORD *) __builtin_frame_address (0); ebp > bpend; ebp--)
|
2003-11-29 04:55:59 +08:00
|
|
|
if (*ebp == in.SegCs && ebp[-1] == in.Eip)
|
2000-07-04 04:14:06 +08:00
|
|
|
{
|
|
|
|
ebp -= 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (!myself->progname[0]
|
2000-09-16 10:36:11 +08:00
|
|
|
|| GetCurrentThreadId () == sigtid
|
2003-11-29 06:13:57 +08:00
|
|
|
|| (void *) global_sigs[sig].sa_handler == (void *) SIG_DFL
|
|
|
|
|| (void *) global_sigs[sig].sa_handler == (void *) SIG_IGN
|
|
|
|
|| (void *) global_sigs[sig].sa_handler == (void *) SIG_ERR)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* Print the exception to the console */
|
2003-11-29 04:55:59 +08:00
|
|
|
if (1)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
for (int i = 0; status_info[i].name; i++)
|
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
if (status_info[i].code == e.ExceptionCode)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-05-11 13:11:12 +08:00
|
|
|
if (!myself->ppid_handle)
|
|
|
|
system_printf ("Exception: %s", status_info[i].name);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Another exception could happen while tracing or while exiting.
|
|
|
|
Only do this once. */
|
2001-04-30 11:09:19 +08:00
|
|
|
if (recursed++)
|
2000-07-05 03:07:35 +08:00
|
|
|
system_printf ("Error while dumping state (probably corrupted stack)");
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
|
|
|
{
|
2001-04-30 11:09:19 +08:00
|
|
|
if (try_to_debug (0))
|
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
debugging = true;
|
2001-04-30 11:09:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
open_stackdumpfile ();
|
2003-11-29 04:55:59 +08:00
|
|
|
exception (&e, &in);
|
2001-05-05 10:44:36 +08:00
|
|
|
stackdump ((DWORD) ebp, 0, 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-04-30 11:09:19 +08:00
|
|
|
|
|
|
|
signal_exit (0x80 | sig); // Flag signal + core dump
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
_my_tls.push ((__stack_t) ebp, true);
|
|
|
|
sig_send (NULL, sig, &_my_tls); // Signal myself
|
|
|
|
return 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
|
|
|
#ifndef HAVE_STACK_TRACE
|
|
|
|
void
|
|
|
|
stack (void)
|
|
|
|
{
|
|
|
|
system_printf ("Stack trace not yet supported on this machine.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Utilities to call a user supplied exception handler. */
|
|
|
|
|
2001-01-08 12:02:02 +08:00
|
|
|
#define SIG_NONMASKABLE (SIGTOMASK (SIGKILL) | SIGTOMASK (SIGSTOP))
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
#define HAVE_CALL_HANDLER
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2003-08-19 12:10:42 +08:00
|
|
|
sig_dispatch_pending ();
|
2000-02-18 03:38:33 +08:00
|
|
|
sigset_t oldmask = myself->getsigmask (); // Remember for restoration
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
set_signal_mask (tempmask & ~SIG_NONMASKABLE);// Let signals we're
|
2000-02-18 03:38:33 +08:00
|
|
|
// interested in through.
|
|
|
|
sigproc_printf ("old mask %x, new mask %x", oldmask, tempmask);
|
|
|
|
|
2003-01-15 03:55:42 +08:00
|
|
|
pthread_testcancel ();
|
|
|
|
pthread::cancelable_wait (signal_arrived, INFINITE);
|
2000-02-18 03:38:33 +08: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
|
|
|
|
handler returns. */
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
_my_tls.oldmask = oldmask; // Will be restored by signal handler
|
2000-02-18 03:38:33 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern DWORD exec_exit; // Possible exit value for exec
|
|
|
|
|
2001-01-17 22:57:09 +08:00
|
|
|
extern "C" {
|
|
|
|
static void
|
|
|
|
sig_handle_tty_stop (int sig)
|
|
|
|
{
|
2001-03-02 10:09:40 +08:00
|
|
|
/* Silently ignore attempts to suspend if there is no accomodating
|
|
|
|
cygwin parent to deal with this behavior. */
|
|
|
|
if (!myself->ppid_handle)
|
2001-06-17 01:09:19 +08:00
|
|
|
{
|
|
|
|
myself->process_state &= ~PID_STOPPED;
|
|
|
|
return;
|
|
|
|
}
|
2002-01-20 07:57:45 +08:00
|
|
|
|
2001-01-17 22:57:09 +08:00
|
|
|
myself->stopsig = sig;
|
|
|
|
/* See if we have a living parent. If so, send it a special signal.
|
2003-05-30 23:01:33 +08:00
|
|
|
It will figure out exactly which pid has stopped by scanning
|
|
|
|
its list of subprocesses. */
|
2001-01-17 22:57:09 +08:00
|
|
|
if (my_parent_is_alive ())
|
|
|
|
{
|
2003-09-27 10:30:46 +08:00
|
|
|
pinfo parent (myself->ppid);
|
2003-09-16 11:07:27 +08:00
|
|
|
if (ISSTATE (parent, PID_NOCLDSTOP))
|
2002-01-20 07:57:45 +08:00
|
|
|
sig_send (parent, SIGCHLD);
|
2001-01-17 22:57:09 +08:00
|
|
|
}
|
|
|
|
sigproc_printf ("process %d stopped by signal %d, myself->ppid_handle %p",
|
|
|
|
myself->pid, sig, myself->ppid_handle);
|
2002-08-18 12:13:57 +08:00
|
|
|
if (WaitForSingleObject (sigCONT, INFINITE) != WAIT_OBJECT_0)
|
|
|
|
api_fatal ("WaitSingleObject failed, %E");
|
2001-01-17 22:57:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-24 10:49:44 +08:00
|
|
|
int
|
2003-11-29 04:55:59 +08:00
|
|
|
interruptible (DWORD pc)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-04-08 12:13:12 +08:00
|
|
|
int res;
|
2000-11-02 10:15:02 +08:00
|
|
|
MEMORY_BASIC_INFORMATION m;
|
|
|
|
|
|
|
|
memset (&m, 0, sizeof m);
|
|
|
|
if (!VirtualQuery ((LPCVOID) pc, &m, sizeof m))
|
|
|
|
sigproc_printf ("couldn't get memory info, pc %p, %E", pc);
|
|
|
|
|
|
|
|
char *checkdir = (char *) alloca (windows_system_directory_length + 4);
|
|
|
|
memset (checkdir, 0, sizeof (checkdir));
|
|
|
|
|
|
|
|
# define h ((HMODULE) m.AllocationBase)
|
|
|
|
/* Apparently Windows 95 can sometimes return bogus addresses from
|
2002-11-15 12:35:13 +08:00
|
|
|
GetThreadContext. These resolve to a strange allocation base.
|
2000-11-02 10:15:02 +08:00
|
|
|
These should *never* be treated as interruptible. */
|
|
|
|
if (!h || m.State != MEM_COMMIT)
|
|
|
|
res = 0;
|
|
|
|
else if (h == user_data->hmodule)
|
|
|
|
res = 1;
|
|
|
|
else if (!GetModuleFileName (h, checkdir, windows_system_directory_length + 2))
|
2000-02-26 09:11:54 +08:00
|
|
|
res = 0;
|
|
|
|
else
|
2000-11-02 10:15:02 +08:00
|
|
|
res = !strncasematch (windows_system_directory, checkdir,
|
|
|
|
windows_system_directory_length);
|
2003-11-29 04:55:59 +08:00
|
|
|
sigproc_printf ("pc %p, h %p, interruptible %d", pc, h, res);
|
2000-11-02 10:15:02 +08:00
|
|
|
# undef h
|
2000-02-26 09:11:54 +08:00
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2003-11-29 04:55:59 +08:00
|
|
|
void __stdcall
|
|
|
|
_threadinfo::interrupt_setup (int sig, void *handler,
|
|
|
|
struct sigaction& siga, __stack_t retaddr)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
__stack_t *retaddr_in_tls = stackptr - 1;
|
|
|
|
push ((__stack_t) sigdelayed);
|
|
|
|
oldmask = myself->getsigmask ();
|
|
|
|
newmask = oldmask | siga.sa_mask | SIGTOMASK (sig);
|
|
|
|
sa_flags = siga.sa_flags;
|
|
|
|
func = (void (*) (int)) handler;
|
|
|
|
saved_errno = -1; // Flag: no errno to save
|
2001-01-17 22:57:09 +08:00
|
|
|
if (handler == sig_handle_tty_stop)
|
|
|
|
{
|
|
|
|
myself->stopsig = 0;
|
|
|
|
myself->process_state |= PID_STOPPED;
|
|
|
|
}
|
2003-11-29 04:55:59 +08:00
|
|
|
this->sig = sig; // Should ALWAYS be second to last setting set to avoid a race
|
|
|
|
*retaddr_in_tls = retaddr;
|
2001-06-25 05:57:50 +08:00
|
|
|
/* Clear any waiting threads prior to dispatching to handler function */
|
|
|
|
int res = SetEvent (signal_arrived); // For an EINTR case
|
2003-11-29 04:55:59 +08:00
|
|
|
proc_subproc (PROC_CLEARWAIT, 1);
|
2001-06-25 05:57:50 +08:00
|
|
|
sigproc_printf ("armed signal_arrived %p, res %d", signal_arrived, res);
|
2000-02-28 13:05:33 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
bool
|
|
|
|
_threadinfo::interrupt_now (CONTEXT *ctx, int sig, void *handler,
|
|
|
|
struct sigaction& siga)
|
2000-02-28 13:05:33 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
push (0);
|
|
|
|
interrupt_setup (sig, handler, siga, (__stack_t) ctx->Eip);
|
2000-02-28 13:05:33 +08:00
|
|
|
ctx->Eip = (DWORD) sigdelayed;
|
2003-11-29 08:26:40 +08:00
|
|
|
SetThreadContext (*this, ctx); /* Restart the thread in a new location */
|
2000-11-06 14:36:32 +08:00
|
|
|
return 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-10-17 07:55:58 +08:00
|
|
|
void __stdcall
|
2000-04-08 12:13:12 +08:00
|
|
|
signal_fixup_after_fork ()
|
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
if (_my_tls.sig)
|
2000-04-08 12:13:12 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
_my_tls.sig = 0;
|
|
|
|
_my_tls.stackptr = _my_tls.stack + 1; // FIXME?
|
|
|
|
set_signal_mask (_my_tls.oldmask);
|
2000-04-08 12:13:12 +08:00
|
|
|
}
|
2002-08-12 03:19:29 +08:00
|
|
|
sigproc_init ();
|
2000-04-08 12:13:12 +08:00
|
|
|
}
|
2000-07-05 03:07:35 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
extern "C" void __stdcall
|
|
|
|
set_sig_errno (int e)
|
|
|
|
{
|
|
|
|
set_errno (e);
|
2003-11-29 04:55:59 +08:00
|
|
|
_my_tls.saved_errno = e;
|
2000-10-09 10:53:44 +08:00
|
|
|
// sigproc_printf ("errno %d", e);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
static int setup_handler (int, void *, struct sigaction&, _threadinfo *tls)
|
|
|
|
__attribute__((regparm(3)));
|
2000-02-18 03:38:33 +08:00
|
|
|
static int
|
2003-11-29 04:55:59 +08:00
|
|
|
setup_handler (int sig, void *handler, struct sigaction& siga, _threadinfo *tls)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-03-10 05:04:05 +08:00
|
|
|
CONTEXT cx;
|
2002-11-22 12:43:47 +08:00
|
|
|
bool interrupted = false;
|
2000-05-17 13:49:51 +08:00
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
if (tls->sig)
|
2003-08-28 10:04:16 +08:00
|
|
|
goto out;
|
2000-10-18 12:53:37 +08:00
|
|
|
|
2002-11-22 12:43:47 +08:00
|
|
|
for (int i = 0; i < CALL_HANDLER_RETRY; i++)
|
2000-05-20 13:52:33 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
__stack_t retaddr;
|
|
|
|
__stack_t *retaddr_on_stack = tls->stackptr - 1;
|
|
|
|
if (retaddr_on_stack >= tls->stack
|
|
|
|
&& (retaddr = InterlockedExchange ((LONG *) retaddr_on_stack, 0)))
|
2002-11-22 12:43:47 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
if (!retaddr)
|
|
|
|
continue;
|
|
|
|
tls->reset_exception ();
|
|
|
|
tls->interrupt_setup (sig, handler, siga, retaddr);
|
|
|
|
sigproc_printf ("interrupted known cygwin routine");
|
|
|
|
interrupted = true;
|
|
|
|
break;
|
2002-11-22 12:43:47 +08:00
|
|
|
}
|
2000-11-07 07:12:05 +08:00
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
DWORD res;
|
2003-11-29 08:26:40 +08:00
|
|
|
HANDLE hth = (HANDLE) *tls;
|
2003-11-29 04:55:59 +08:00
|
|
|
|
|
|
|
/* Suspend the thread which will receive the signal. But first ensure that
|
|
|
|
this thread doesn't have any mutos. (FIXME: Someday we should just grab
|
|
|
|
all of the mutos rather than checking for them)
|
|
|
|
For Windows 95, we also have to ensure that the addresses returned by GetThreadContext
|
|
|
|
are valid.
|
|
|
|
If one of these conditions is not true we loop for a fixed number of times
|
|
|
|
since we don't want to stall the signal handler. FIXME: Will this result in
|
|
|
|
noticeable delays?
|
|
|
|
If the thread is already suspended (which can occur when a program has called
|
|
|
|
SuspendThread on itself then just queue the signal. */
|
2000-11-06 14:36:32 +08:00
|
|
|
|
2003-08-28 10:04:16 +08:00
|
|
|
#ifndef DEBUGGING
|
2003-11-29 04:55:59 +08:00
|
|
|
sigproc_printf ("suspending mainthread");
|
2003-08-28 10:04:16 +08:00
|
|
|
#else
|
2003-11-29 04:55:59 +08:00
|
|
|
cx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
|
|
|
|
if (!GetThreadContext (hth, &cx))
|
|
|
|
memset (&cx, 0, sizeof cx);
|
|
|
|
sigproc_printf ("suspending mainthread PC %p", cx.Eip);
|
2003-08-28 10:04:16 +08:00
|
|
|
#endif
|
2003-11-29 04:55:59 +08:00
|
|
|
res = SuspendThread (hth);
|
|
|
|
/* Just release the lock now since we hav suspended the main thread and it
|
|
|
|
definitely can't be grabbing it now. This will have to change, of course,
|
|
|
|
if/when we can send signals to other than the main thread. */
|
2002-11-22 12:43:47 +08:00
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
/* Just set pending if thread is already suspended */
|
|
|
|
if (res)
|
2000-11-07 07:12:05 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
(void) ResumeThread (hth);
|
|
|
|
break;
|
2000-11-07 07:12:05 +08:00
|
|
|
}
|
2003-11-29 04:55:59 +08:00
|
|
|
|
|
|
|
// FIXME - add check for reentering of DLL here
|
|
|
|
|
|
|
|
muto *m;
|
|
|
|
/* FIXME: Make multi-thread aware */
|
|
|
|
for (m = muto_start.next; m != NULL; m = m->next)
|
|
|
|
if (m->unstable () || m->owner () == cygthread::main_thread_id)
|
|
|
|
{
|
|
|
|
sigproc_printf ("suspended thread owns a muto (%s)", m->name);
|
|
|
|
goto resume_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
cx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
|
|
|
|
if (!GetThreadContext (hth, &cx))
|
|
|
|
system_printf ("couldn't get context of main thread, %E");
|
2000-11-06 14:36:32 +08:00
|
|
|
else if (interruptible (cx.Eip))
|
2003-11-29 04:55:59 +08:00
|
|
|
interrupted = tls->interrupt_now (&cx, sig, handler, siga);
|
2002-11-22 12:43:47 +08:00
|
|
|
|
|
|
|
resume_thread:
|
2003-11-29 04:55:59 +08:00
|
|
|
res = ResumeThread (hth);
|
2002-11-22 12:43:47 +08:00
|
|
|
|
|
|
|
if (interrupted)
|
2000-11-06 14:36:32 +08:00
|
|
|
break;
|
2002-11-22 12:43:47 +08:00
|
|
|
sigproc_printf ("couldn't interrupt. trying again.");
|
2003-11-29 04:55:59 +08:00
|
|
|
low_priority_sleep (0);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-08-28 10:04:16 +08:00
|
|
|
out:
|
|
|
|
sigproc_printf ("signal %d %sdelivered", sig, interrupted ? "" : "not ");
|
2000-02-24 10:49:44 +08:00
|
|
|
return interrupted;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
#endif /* i386 */
|
|
|
|
|
|
|
|
#ifndef HAVE_CALL_HANDLER
|
2001-01-27 10:23:46 +08:00
|
|
|
#error "Need to supply machine dependent setup_handler"
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif
|
|
|
|
|
2002-01-11 10:24:06 +08:00
|
|
|
/* Keyboard interrupt handler. */
|
2000-02-18 03:38:33 +08:00
|
|
|
static BOOL WINAPI
|
|
|
|
ctrl_c_handler (DWORD type)
|
|
|
|
{
|
2003-07-26 12:53:59 +08:00
|
|
|
static bool saw_close;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-07-26 08:10:52 +08: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 12:53:59 +08:00
|
|
|
|
2001-07-26 08:10:52 +08:00
|
|
|
if (type == CTRL_SHUTDOWN_EVENT)
|
|
|
|
{
|
2003-06-12 20:36:07 +08:00
|
|
|
#if 0
|
|
|
|
/* Don't send a signal. Only NT service applications and their child
|
2003-07-26 12:53:59 +08:00
|
|
|
processes will receive this event and the services typically already
|
2003-06-12 20:36:07 +08:00
|
|
|
handle the shutdown action when getting the SERVICE_CONTROL_SHUTDOWN
|
|
|
|
control message. */
|
2001-07-26 08:10:52 +08:00
|
|
|
sig_send (NULL, SIGTERM);
|
2003-06-12 20:36:07 +08:00
|
|
|
#endif
|
2001-07-26 08:10:52 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-07-26 12:53:59 +08:00
|
|
|
|
2003-10-14 17:21:55 +08:00
|
|
|
if (myself->ctty != -1)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-07-26 12:53:59 +08:00
|
|
|
if (type == CTRL_CLOSE_EVENT)
|
2003-10-14 17:21:55 +08:00
|
|
|
{
|
|
|
|
saw_close = true;
|
|
|
|
sig_send (NULL, SIGHUP);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!saw_close && type == CTRL_LOGOFF_EVENT)
|
|
|
|
{
|
|
|
|
/* Check if the process is actually associated with a visible
|
|
|
|
window station, one which actually represents a visible desktop.
|
|
|
|
If not, the CTRL_LOGOFF_EVENT doesn't concern this process. */
|
|
|
|
if (has_visible_window_station ())
|
2003-11-29 04:55:59 +08:00
|
|
|
sig_send (myself_nowait, SIGHUP);
|
2003-10-14 17:21:55 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-07-26 08:10:52 +08:00
|
|
|
|
2002-01-10 11:21:27 +08:00
|
|
|
/* If we are a stub and the new process has a pinfo structure, let it
|
|
|
|
handle this signal. */
|
|
|
|
if (dwExeced && pinfo (dwExeced))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* 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 07:13:03 +08:00
|
|
|
if (!pinfo (cygwin_pid (GetCurrentProcessId ())))
|
2002-01-10 11:21:27 +08:00
|
|
|
return TRUE;
|
|
|
|
|
2000-07-05 03:07:35 +08:00
|
|
|
tty_min *t = cygwin_shared->tty.get_tty (myself->ctty);
|
2002-01-10 11:21:27 +08:00
|
|
|
/* Ignore this if we're not the process group leader since it should be handled
|
2000-02-18 03:38:33 +08:00
|
|
|
*by* the process group leader. */
|
2001-09-05 10:42:49 +08:00
|
|
|
if (myself->ctty != -1 && t->getpgid () == myself->pid &&
|
|
|
|
(GetTickCount () - t->last_ctrl_c) >= MIN_CTRL_C_SLOP)
|
2000-02-18 03:38:33 +08: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. */
|
|
|
|
{
|
|
|
|
t->last_ctrl_c = GetTickCount ();
|
|
|
|
kill (-myself->pid, SIGINT);
|
|
|
|
t->last_ctrl_c = GetTickCount ();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-10 11:21:27 +08:00
|
|
|
|
2001-09-05 10:42:49 +08:00
|
|
|
return TRUE;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
/* Function used by low level sig wrappers. */
|
|
|
|
extern "C" void __stdcall
|
|
|
|
set_process_mask (sigset_t newmask)
|
|
|
|
{
|
|
|
|
set_signal_mask (newmask);
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Set the signal mask for this process.
|
2000-11-16 13:16:59 +08:00
|
|
|
Note that some signals are unmaskable, as in UNIX. */
|
2000-02-18 03:38:33 +08:00
|
|
|
extern "C" void __stdcall
|
2003-11-29 04:55:59 +08:00
|
|
|
set_signal_mask (sigset_t newmask, sigset_t& oldmask)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
mask_sync->acquire (INFINITE);
|
|
|
|
newmask &= ~SIG_NONMASKABLE;
|
|
|
|
sigproc_printf ("old mask = %x, new mask = %x", myself->getsigmask (), newmask);
|
|
|
|
myself->setsigmask (newmask); // Set a new mask
|
|
|
|
mask_sync->release ();
|
* 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 08:37:18 +08:00
|
|
|
if (oldmask & ~newmask)
|
|
|
|
sig_dispatch_pending ();
|
|
|
|
else
|
2003-11-29 04:55:59 +08:00
|
|
|
sigproc_printf ("not calling sig_dispatch_pending");
|
2000-02-18 03:38:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
_threadinfo *
|
2003-12-07 10:56:52 +08:00
|
|
|
_threadinfo::find_tls (int sig)
|
2003-11-29 04:55:59 +08:00
|
|
|
{
|
2003-12-07 10:56:52 +08:00
|
|
|
EnterCriticalSection (&protect_linked_list);
|
2003-11-29 04:55:59 +08:00
|
|
|
for (_threadinfo *t = _last_thread; t ; t = t->prev)
|
|
|
|
if (sigismember (&t->sigwait_mask, sig))
|
|
|
|
return t;
|
2003-12-07 10:56:52 +08:00
|
|
|
LeaveCriticalSection (&protect_linked_list);
|
2003-11-29 04:55:59 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int __stdcall
|
2003-11-29 04:55:59 +08:00
|
|
|
sig_handle (int sig, sigset_t mask, int pid, _threadinfo *tls)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
* 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 08:37:18 +08:00
|
|
|
if (sig == SIGCONT)
|
|
|
|
{
|
|
|
|
DWORD stopped = myself->process_state & PID_STOPPED;
|
|
|
|
myself->stopsig = 0;
|
|
|
|
myself->process_state &= ~PID_STOPPED;
|
|
|
|
/* Clear pending stop signals */
|
|
|
|
sig_clear (SIGSTOP);
|
|
|
|
sig_clear (SIGTSTP);
|
|
|
|
sig_clear (SIGTTIN);
|
|
|
|
sig_clear (SIGTTOU);
|
|
|
|
if (stopped)
|
|
|
|
SetEvent (sigCONT);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
int rc = 1;
|
|
|
|
bool insigwait_mask = tls ? sigismember (&tls->sigwait_mask, sig) : false;
|
* 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 08:37:18 +08:00
|
|
|
if (sig != SIGKILL && sig != SIGSTOP
|
2003-11-29 04:55:59 +08:00
|
|
|
&& (sigismember (&mask, sig)
|
|
|
|
|| (tls
|
|
|
|
&& (insigwait_mask || sigismember (&tls->sigmask, sig)))
|
|
|
|
|| main_vfork->pid
|
* 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 08:37:18 +08:00
|
|
|
|| ISSTATE (myself, PID_STOPPED)))
|
|
|
|
{
|
|
|
|
sigproc_printf ("signal %d blocked", sig);
|
2003-12-07 10:56:52 +08:00
|
|
|
if (insigwait_mask || (tls = _threadinfo::find_tls (sig)) != NULL)
|
2003-11-29 04:55:59 +08:00
|
|
|
goto thread_specific;
|
|
|
|
rc = -1;
|
|
|
|
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 08:37:18 +08:00
|
|
|
}
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
/* Clear pending SIGCONT on stop signals */
|
|
|
|
if (sig == SIGSTOP || sig == SIGTSTP || sig == SIGTTIN || sig == SIGTTOU)
|
|
|
|
sig_clear (SIGCONT);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
* 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 08:37:18 +08:00
|
|
|
sigproc_printf ("signal %d processing", sig);
|
2003-11-29 06:13:57 +08:00
|
|
|
struct sigaction thissig = global_sigs[sig];
|
2003-11-29 04:55:59 +08:00
|
|
|
void *handler;
|
|
|
|
handler = (void *) thissig.sa_handler;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
myself->rusage_self.ru_nsignals++;
|
|
|
|
|
|
|
|
if (sig == SIGKILL)
|
|
|
|
goto exit_sig;
|
|
|
|
|
|
|
|
if (sig == SIGSTOP)
|
|
|
|
goto stop;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
char sigmsg[24];
|
|
|
|
__small_sprintf (sigmsg, "cygwin: signal %d\n", sig);
|
|
|
|
OutputDebugString (sigmsg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (handler == (void *) SIG_DFL)
|
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
if (insigwait_mask)
|
|
|
|
goto thread_specific;
|
2002-01-06 06:25:34 +08:00
|
|
|
if (sig == SIGCHLD || sig == SIGIO || sig == SIGCONT || sig == SIGWINCH
|
2003-09-12 14:41:53 +08:00
|
|
|
|| sig == SIGURG)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
sigproc_printf ("default signal %d ignored", sig);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sig == SIGTSTP || sig == SIGTTIN || sig == SIGTTOU)
|
|
|
|
goto stop;
|
|
|
|
|
|
|
|
goto exit_sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handler == (void *) SIG_IGN)
|
|
|
|
{
|
|
|
|
sigproc_printf ("signal %d ignored", sig);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handler == (void *) SIG_ERR)
|
|
|
|
goto exit_sig;
|
|
|
|
|
|
|
|
goto dosig;
|
|
|
|
|
2003-09-09 11:11:31 +08:00
|
|
|
stop:
|
2001-01-17 22:57:09 +08:00
|
|
|
/* Eat multiple attempts to STOP */
|
|
|
|
if (ISSTATE (myself, PID_STOPPED))
|
|
|
|
goto done;
|
2000-02-18 03:38:33 +08:00
|
|
|
handler = (void *) sig_handle_tty_stop;
|
2003-11-29 06:13:57 +08:00
|
|
|
thissig = global_sigs[SIGSTOP];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-09-09 11:11:31 +08:00
|
|
|
dosig:
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Dispatch to the appropriate function. */
|
2001-01-17 22:57:09 +08:00
|
|
|
sigproc_printf ("signal %d, about to call %p", sig, handler);
|
2003-11-29 04:55:59 +08:00
|
|
|
rc = setup_handler (sig, handler, thissig, tls ?: _main_tls);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-09-09 11:11:31 +08:00
|
|
|
done:
|
2000-02-18 03:38:33 +08:00
|
|
|
sigproc_printf ("returning %d", rc);
|
|
|
|
return rc;
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
thread_specific:
|
|
|
|
tls->sig = sig;
|
|
|
|
sigproc_printf ("releasing sigwait for thread");
|
|
|
|
SetEvent (tls->event);
|
|
|
|
goto done;
|
|
|
|
|
2003-09-09 11:11:31 +08:00
|
|
|
exit_sig:
|
2000-02-18 03:38:33 +08:00
|
|
|
if (sig == SIGQUIT || sig == SIGABRT)
|
|
|
|
{
|
2000-07-04 04:14:06 +08:00
|
|
|
CONTEXT c;
|
|
|
|
c.ContextFlags = CONTEXT_FULL;
|
|
|
|
GetThreadContext (hMainThread, &c);
|
2001-04-30 11:09:19 +08:00
|
|
|
if (!try_to_debug ())
|
2001-05-05 10:44:36 +08:00
|
|
|
stackdump (c.Ebp, 1, 1);
|
2000-07-27 04:13:27 +08:00
|
|
|
sig |= 0x80;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
sigproc_printf ("signal %d, about to call do_exit", sig);
|
2000-07-27 04:13:27 +08:00
|
|
|
signal_exit (sig);
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Never returns */
|
|
|
|
}
|
|
|
|
|
2002-12-26 04:33:21 +08:00
|
|
|
CRITICAL_SECTION NO_COPY exit_lock;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Cover function to `do_exit' to handle exiting even in presence of more
|
2000-07-27 04:13:27 +08:00
|
|
|
exceptions. We used to call exit, but a SIGSEGV shouldn't cause atexit
|
2000-02-18 03:38:33 +08:00
|
|
|
routines to run. */
|
|
|
|
static void
|
2000-07-27 04:13:27 +08:00
|
|
|
signal_exit (int rc)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-12-26 04:33:21 +08:00
|
|
|
EnterCriticalSection (&exit_lock);
|
2000-07-27 04:13:27 +08:00
|
|
|
rc = EXIT_SIGNAL | (rc << 8);
|
2000-02-18 03:38:33 +08:00
|
|
|
if (exit_already++)
|
2000-10-15 09:37:07 +08:00
|
|
|
myself->exit (rc);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-09-11 08:25:57 +08:00
|
|
|
/* We'd like to stop the main thread from executing but when we do that it
|
|
|
|
causes random, inexplicable hangs. So, instead, we set up the priority
|
|
|
|
of this thread really high so that it should do its thing and then exit. */
|
2001-11-01 00:30:46 +08:00
|
|
|
(void) SetThreadPriority (hMainThread, THREAD_PRIORITY_IDLE);
|
2002-10-06 09:01:58 +08:00
|
|
|
(void) SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
|
2000-09-11 08:25:57 +08:00
|
|
|
|
|
|
|
/* Unlock any main thread mutos since we're executing with prejudice. */
|
|
|
|
muto *m;
|
|
|
|
for (m = muto_start.next; m != NULL; m = m->next)
|
2003-11-29 04:55:59 +08:00
|
|
|
if (m->unstable () || m->owner () == cygthread::main_thread_id)
|
2000-09-11 08:25:57 +08:00
|
|
|
m->reset ();
|
|
|
|
|
|
|
|
user_data->resourcelocks->Delete ();
|
|
|
|
user_data->resourcelocks->Init ();
|
|
|
|
|
2000-10-24 10:25:27 +08:00
|
|
|
if (hExeced)
|
2003-09-12 14:41:53 +08:00
|
|
|
{
|
|
|
|
sigproc_printf ("terminating captive process");
|
|
|
|
TerminateProcess (hExeced, rc);
|
|
|
|
}
|
2000-10-24 10:25:27 +08:00
|
|
|
|
2000-11-02 10:15:02 +08:00
|
|
|
sigproc_printf ("about to call do_exit (%x)", rc);
|
2002-12-11 12:00:04 +08:00
|
|
|
(void) SetEvent (signal_arrived);
|
2000-02-18 03:38:33 +08:00
|
|
|
do_exit (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE NO_COPY title_mutex = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
events_init (void)
|
|
|
|
{
|
2002-12-31 07:08:35 +08:00
|
|
|
char *name;
|
2003-11-15 07:40:06 +08:00
|
|
|
char mutex_name[CYG_MAX_PATH];
|
2003-01-03 14:20:23 +08:00
|
|
|
/* title_mutex protects modification of console title. It's necessary
|
2000-02-18 03:38:33 +08:00
|
|
|
while finding console window handle */
|
|
|
|
|
|
|
|
if (!(title_mutex = CreateMutex (&sec_all_nih, FALSE,
|
2003-05-21 16:01:57 +08:00
|
|
|
name = shared_name (mutex_name,
|
|
|
|
"title_mutex", 0))))
|
2002-12-31 07:08:35 +08:00
|
|
|
api_fatal ("can't create title mutex '%s', %E", name);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
ProtectHandle (title_mutex);
|
2002-02-23 03:33:41 +08:00
|
|
|
new_muto (mask_sync);
|
2000-02-24 10:49:44 +08:00
|
|
|
windows_system_directory[0] = '\0';
|
|
|
|
(void) GetSystemDirectory (windows_system_directory, sizeof (windows_system_directory) - 2);
|
|
|
|
char *end = strchr (windows_system_directory, '\0');
|
|
|
|
if (end == windows_system_directory)
|
|
|
|
api_fatal ("can't find windows system directory");
|
|
|
|
if (end[-1] != '\\')
|
|
|
|
{
|
|
|
|
*end++ = '\\';
|
|
|
|
*end = '\0';
|
|
|
|
}
|
|
|
|
windows_system_directory_length = end - windows_system_directory;
|
2000-03-05 14:34:55 +08:00
|
|
|
debug_printf ("windows_system_directory '%s', windows_system_directory_length %d",
|
|
|
|
windows_system_directory, windows_system_directory_length);
|
2002-12-26 04:33:21 +08:00
|
|
|
InitializeCriticalSection (&exit_lock);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
events_terminate (void)
|
|
|
|
{
|
|
|
|
exit_already = 1;
|
|
|
|
}
|
|
|
|
|
2001-04-01 13:38:08 +08:00
|
|
|
extern "C" {
|
2003-11-29 04:55:59 +08:00
|
|
|
int __stdcall
|
2001-04-02 08:18:29 +08:00
|
|
|
call_signal_handler_now ()
|
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
int sa_flags = 0;
|
|
|
|
while (_my_tls.sig && _my_tls.stackptr > _my_tls.stack)
|
2001-09-12 13:09:24 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
sa_flags = _my_tls.sa_flags;
|
|
|
|
int sig = _my_tls.sig;
|
|
|
|
void (*sigfunc) (int) = _my_tls.func;
|
|
|
|
(void) _my_tls.pop ();
|
|
|
|
#ifdef DEBUGGING
|
|
|
|
if (_my_tls.stackptr > (_my_tls.stack + 1))
|
|
|
|
try_to_debug ();
|
|
|
|
#endif
|
|
|
|
reset_signal_arrived ();
|
|
|
|
sigset_t oldmask = _my_tls.oldmask;
|
|
|
|
int this_errno = _my_tls.saved_errno;
|
|
|
|
set_process_mask (_my_tls.newmask);
|
|
|
|
_my_tls.sig = 0;
|
|
|
|
sigfunc (sig);
|
|
|
|
set_process_mask (oldmask);
|
|
|
|
if (this_errno >= 0)
|
|
|
|
set_errno (this_errno);
|
2001-09-12 13:09:24 +08:00
|
|
|
}
|
|
|
|
|
2001-04-02 08:18:29 +08:00
|
|
|
return sa_flags & SA_RESTART;
|
|
|
|
}
|
2001-04-01 13:38:08 +08:00
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
#define pid_offset (unsigned)(((_pinfo *)NULL)->pid)
|
2000-12-20 14:03:16 +08:00
|
|
|
void __stdcall
|
2000-02-26 09:11:54 +08:00
|
|
|
reset_signal_arrived ()
|
|
|
|
{
|
|
|
|
(void) ResetEvent (signal_arrived);
|
|
|
|
sigproc_printf ("reset signal_arrived");
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|