aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin
AgeCommit message (Collapse)AuthorFilesLines
2015-07-23Fix potential buffer overflow in makecontext trampolineCorinna Vinschen2-1/+13
glibc's tst-makecontext2 testcase uncovered a bug in __cont_link_context. If the function misses to reserve shadow space for the calls to setcontext/cygwin_exit, both functions could overwrite memory beyond the stack configured in uc_stack. * exceptions.cc (__cont_link_context): x86_64: align stack and reserve shadow space for subsequent function calls, otherwise suffer potential buffer overflow. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-23Ignore non-absolute $HOME when started from native processCorinna Vinschen3-2/+17
* uinfo.cc (cygheap_user::ontherange): Ignore $HOME if it's not starting with a slash (aka, absolute POSIX Path). Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-21Cygwin: Implement siglongjmp and sigsetjmp functions.Corinna Vinschen5-23/+120
* libc/include/machine/setjmp.h (siglongjmp): Declare as function on Cygwin. (sigsetjmp): Ditto. (_longjmp): Mark as noreturn function on Cygwin. * common.din (siglongjmp): Export. (sigsetjmp): Export. * gendef: Change formatting of some comments. (sigsetjmp): Implement. (siglongjmp): Implement. (__setjmpex): x86_64 only: Drop entry point. (setjmp): x86_64 only: Store tls stackptr in Frame now, store MXCSR and FPUCW registers in Spare, as MSVCRT does. (longjmp): x86_64 only: Restore tls stackptr from Frame now, restore MXCSR and FPUCW registers from Spare. * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump. * new-features.xml (ov-new2.2): Document sigsetjmp, siglongjmp. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-20Add previous ldd fix to release fileCorinna Vinschen1-0/+2
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-19Lower Cygwin's MINSIGSTKSZ and SIGSTKSZCorinna Vinschen2-6/+9
* include/cygwin/signal.h (MINSIGSTKSZ): Define as 8K, unconditionally. (SIGSTKSZ): Define as 32K, unconditionally. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-19Reduce stack pressure throughout CygwinCorinna Vinschen10-85/+141
* dcrt0.cc (initial_env): Reduce size of local path buffers to PATH_MAX. Allocate debugger_command from process heap. (init_windows_system_directory): Very early initialize new global variable global_progname. * dll_init.cc (dll_list::alloc): Make path buffer static. Explain why. (dll_list::populate_deps): Use tmp_pathbuf for local path buffer. * exceptions.cc (debugger_command): Convert to PWCHAR. (error_start_init): Allocate debugger_command and fill with wide char strings. Only allocate if NULL. (try_to_debug): Just check if debugger_command is a NULL pointer to return. Drop conversion from char to WCHAR and drop local variable dbg_cmd. * globals.cc (global_progname): New global variable to store Windows application path. * pinfo.cc (pinfo_basic::pinfo_basic): Just copy progname over from global_progname. (pinfo::status_exit): Let path_conv create the POSIX path to avoid local buffer. * pseudo_reloc.cc (__report_error): Utilize global_progname, drop local buffer. * smallprint.cc (__small_vsprintf): Just utilize global_progname for %P format specifier. (__small_vswprintf): Ditto. * strace.cc (PROTECT): Change to reflect x being a pointer. Reformat. (CHECK): Ditto. Reformat. (strace::activate): Utilize global_progname, drop local buffer. Fix formatting. (strace::vsprntf): Reduce size of local progname buffer to NAME_MAX. Copy and, if necessary, convert only the last path component to progname. (strace_buf_guard): New muto. (buf): New static pointer. (strace::vprntf): Use buf under strace_buf_guard lock only. Allocate buffer space for buf on Windows heap. * wow64.cc (wow64_respawn_process): Utilize global_progname, drop local path buffer. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-18Remove x86_64 __sjfault/__ljfaultCorinna Vinschen2-65/+5
* gendef: Remove unused 64 bit versions of __sjfault and __ljfault. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-18Rearrange makecontext and add lots of commentsCorinna Vinschen2-12/+42
* exceptions.cc (makecontext): Rearrange order of initialization and document at great length. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Fix ucontext creation in call_signal handlerCorinna Vinschen2-4/+21
* exceptions.cc (__unwind_single_frame): Define empty macro on i686. (_cygtls::call_signal_handler): Try to make sure signal context makes sense in case we're generating context here. Add comment to explain. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Comment fixupCorinna Vinschen2-6/+13
* exceptions.cc (getcontext/x86_64): Drop comment on RtlCaptureContext. (swapcontext/x86_64): Fix comment yet again. (getcontext/i686): Move comment from x86_64 getcontext, slightly rearranged, to preceeding comment. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Reuse __unwind_single_frame where appropriateCorinna Vinschen2-58/+42
* exceptions.cc (__unwind_single_frame): Move up in file to be accessible from other places. Move comment to getcontext. (stack_info::walk): Call __unwind_single_frame in 64 bit case. Fix preceeding comment. (myfault_altstack_handler): Call __unwind_single_frame. (getcontext): Give comment from __unwind_single_frame a new home. (swapcontext): Fix comment. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Implement getcontext, setcontext, makecontext, swapcontextCorinna Vinschen7-2/+278
* common.din (getcontext): Export. (makecontext): Export. (setcontext): Export. (swapcontext): Export. * exceptions.cc (__unwind_single_frame): New static functions, 64 bit only. (setcontext): New function. (getcontext): New function. (swapcontext): New function. (__cont_link_context): New function. (makecontext): New function. * include/cygwin/version.h (CYGWIN_VERSION_DLL_MAJOR): Bump to 2002. (CYGWIN_VERSION_API_MINOR): Bump. * include/ucontext.h (getcontext): Add prototype. (setcontext): Ditto. (swapcontext): Ditto. (makecontext): Ditto. * ntdll.h (NtContinue): Ditto. * new-features.xml (ov-new2.2): Add new section. Document getcontext, setcontext, makecontext, swapcontext. * posix.xml (std-deprec): Add getcontext, setcontext, makecontext, swapcontext. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-17Document the fact that we forgot to bump for sigaltstack and sethostnameCorinna Vinschen2-1/+7
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-13exceptions.cc: Reenable code only disabled for debug purposesCorinna Vinschen2-2/+5
* exceptions.cc (exception::handle): Reenable code only disabled for debug purposes. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-08tzset: Check timezone and country case-insensitiveCorinna Vinschen1-0/+4
* tzset.c (main): Check timezone and country case-insensitive. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-07Add accidentally missing ChangeLog entry for previous patchCorinna Vinschen1-0/+16
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-07x86_64: Handle myfault exceptions when running on alternate signal stackCorinna Vinschen5-2/+71
x86_64 only: * cygtls.cc (san::leave): Restore _my_tls.andreas. * cygtls.h (class san): Add _clemente as in 32 bit case. Add ret and frame members. (san::san): Handle _my_tls.andreas as on 32 bit. Take parameter and write it to new member ret. Store current stack pointer in frame. (san::~san): New destructor to restore _my_tls.andreas. (__try): Use __l_except address as parameter to san::san. * dcrt0.cc (dll_crt0_0): Add myfault_altstack_handler as vectored continuation handler. * exception.h (myfault_altstack_handler): Declare. * exceptions.cc (myfault_altstack_handler): New function. Explain what it's good for. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-07Simplify stack allocation code in child after forkCorinna Vinschen3-69/+68
* child_info.h (CURR_CHILD_INFO_MAGIC): Update. (child_info_fork::alloc_stack_hard_way): Drop declaration. * dcrt0.cc (child_info_fork::alloc_stack_hard_way): Fold into child_info_fork::alloc_stack. (getstack): Remove. (child_info_fork::alloc_stack): Simplify check for application-provided stack in "hard way" code. Don't call getstack for each page, just reallocate stack immediately as required. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-07Simplify fork code setting up child stack infoCorinna Vinschen2-29/+25
* fork.cc (frok::parent): Simplify code propagating stack setup to child process. Tweak comments. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-06winsup/cygwin: rework basename redefinition handling in path.ccYaakov Selkowitz2-3/+11
This fixes the compile after commit 79e419de6261c4e04785908828096cb4d56b8680. * path.cc: Rework basename redefinition handling. Explain why.
2015-07-05Align hard stack allocation to pthread stack setup changesCorinna Vinschen2-11/+23
* dcrt0.cc (CYGWIN_GUARD): Remove. (child_info_fork::alloc_stack_hard_way): Align stack commit to changes of thread stack setup in CygwinCreateThread. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-05Implement correct RLIMIT_STACK handlingCorinna Vinschen6-71/+164
* miscfuncs.cc (struct pthread_wrapper_arg): Add member guardsize. (pthread_wrapper): Set thread stack guarantee according to guardsize. Tweak assembler code so that $rax/$eax is not required by GCC to prepare the wrapper_arg value. (CygwinCreateThread): Fix deadzone handling. Drop setting a "POSIX" guardpage (aka page w/ PAGE_NOACCESS). Always use Windows guard pages instead. On post-XP systems (providing SetThreadStackGuarantee) always set up stack Windows like with reserved/commited areas and movable guard pages. Only on XP set up stack fully commited if the guardpage size is not the default system guardpage size. Fill out pthread_wrapper_arg::guardsize. Improve comments. * resource.cc: Implement RSTACK_LIMIT Linux-like. (DEFAULT_STACKSIZE): New macro. (DEFAULT_STACKGUARD): Ditto. (rlimit_stack_guard): New muto. (rlimit_stack): New global variable holding current RSTACK_LIMIT values. (__set_rlimit_stack): Set rlimit_stack under lock. (__get_rlimit_stack): Initialize rlimit_stack from executable header and return rlimit_stack values under lock. (get_rlimit_stack): Filtering function to return useful default stacksize from rlimit_stack.rlim_cur value. (getrlimit): Call __get_rlimit_stack in RLIMIT_STACK case. (setrlimit): Call __set_rlimit_stack in RLIMIT_STACK case. * thread.cc (pthread::create): Fetch default stacksize calling get_rlimit_stack. (pthread_attr::pthread_attr): Fetch default guardsize calling wincap.def_guard_page_size. (pthread_attr_getstacksize): Fetch default stacksize calling get_rlimit_stack. * thread.h (PTHREAD_DEFAULT_STACKSIZE): Remove. (PTHREAD_DEFAULT_GUARDSIZE): Remove. (get_rlimit_stack): Declare. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-05Disable fetching heap info on 64 bit XP/2003Corinna Vinschen5-1/+27
* fhandler_process.cc (heap_info::heap_info): Disable fetching heap info on 64 bit XP/2003. Explain why. * wincap.h (wincaps::has_broken_rtl_query_process_debug_information): New element. * wincap.cc: Implement above element throughout. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-05Add missing wincap changes to previous ChangeLog entryCorinna Vinschen1-0/+3
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-04Fix original stack when running signal handler on alternate stackCorinna Vinschen8-134/+291
* autoload.cc (SetThreadStackGuarantee): Import. * cygtls.h (struct _cygtls): Replace thread_context with a ucontext_t called context. * exceptions.cc (exception::handle): Exit from process via signal_exit in case sig_send returns from handling a stack overflow SIGSEGV. Explain why. (dumpstack_overflow_wrapper): Thread wrapper to create a stackdump from another thread. (signal_exit): Fix argument list to reflect three-arg signal handler. In case we have to create a stackdump for a stack overflow condition, do so from a separate thread. Explain why. (sigpacket::process): Don't run signal_exit on alternate stack. (altstack_wrapper): Wrapper function to do stack correction when calling the signal handler on an alternate stack to handle a stack overflow. Make sure to have lots of comments. (_cygtls::call_signal_handler): Drop local context variable to reduce stack pressure. Use this->context instead. Change inline assembler to call altstack_wrapper. (_cygtls::signal_debugger): Accommodate aforementioned change to struct _cygtls. * tlsoffset.h: Regenerate. * tlsoffset64.h: Regenerate. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-01Document previous changeCorinna Vinschen1-0/+3
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-07-01Fix fork after recovered stack overflowCorinna Vinschen2-2/+19
* fork.cc (frok::parent): Set stacktop value based on requested stack pointer value in child. Explain why. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-30Add comment to sigaltstack to explain setting ss_flags hereCorinna Vinschen2-0/+8
* signal.cc (sigaltstack): Add comment. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-27Handle ss_flags value longjmp safe.Corinna Vinschen3-5/+18
* exceptions.cc (_cygtls::call_signal_handler): Drop manipulating thread's ss_flags here. It's not safe against longjmp. * signal.cc (sigaltstack): Check if we're running on the alternate stack and set ss_flags returned in oss to SS_ONSTACK. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-26Define larger MINSIGSTKSZ and SIGSTKSZ values for CygwinCorinna Vinschen2-0/+13
* include/cygwin/signal.h: Revert to define MINSIGSTKSZ and SIGSTKSZ here with bigger values to allow _cygtls to reside on signal stack, should it turn out to be required at one point. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-26Fix values returned by getrlimit(RLIMIT_STACK)Corinna Vinschen2-10/+31
* resource.cc (getrlimit): Fix values returned by RLIMIT_STACK. Explain why this had to be changed. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-23Complement SIGEV_* enums with macrosKen Brown2-0/+8
* include/cygwin/signal.h (SIGEV_*): Add macros. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-22Don't push on original stack during alternate signal stack setupCorinna Vinschen2-56/+56
* exceptions.cc (_cygtls::call_signal_handler): Drop pushing a register on the original stack, it confuses GCC. Rearrange the assembler code so that $rax/$eax is not used by GCC to prepare an argument value. Use $rax/$eax without saving. Drop clearing $rbp/$epb. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-21Safe all clobbered volatile registers when using alternate stackCorinna Vinschen2-22/+54
* exceptions.cc (_cygtls::call_signal_handler): Drop subtracting 16 bytes from the alternate stack, it's not necessary. Safe all clobbered registers. Safe one on the orignal stack, the others on the alternate stack on both platforms. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-20Fix commentsCorinna Vinschen1-2/+2
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-20ChangeLog entries for Cygwin's alternate signal stack implementationCorinna Vinschen1-0/+25
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-20Add alternate signal stack to docsCorinna Vinschen1-0/+6
* new-features.xml (ov-new2.1): Add alterante signal stack info. * posix.xml (std-susv4): Move sigaltstack here. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-20Implement using alternate signal stack in CygwinCorinna Vinschen1-13/+108
* exceptions.cc (_cygtls::call_signal_handler): Implement alternate signal stack handling. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-20Use MINSIGSTKSZ and SIGSTKSZ from newlib for Cygwin as wellCorinna Vinschen1-3/+0
* libc/include/sys/signal.h: Move altstack macros completely outside of rtems block. * include/cygwin/signal.h: Remove definitions of MINSIGSTKSZ and SIGSTKSZ here. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-20Handle exceptions in sigaltstackCorinna Vinschen1-21/+35
* signal.cc (sigaltstack): Add fault handler. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-19Preliminary infrastructure to implement alternate stackCorinna Vinschen8-147/+208
* libc/include/sys/signal.h: Define SS_ONSTACK and SS_DISABLE unconditionally. (sigaltstack): Enable prototype on Cygwin. * common.din (sigaltstack): Export. * cygtls.cc (_cygtls::init_thread): Initialize altstack. * cygtls.h (__tlsstack_t): Rename from __stack_t to distinguish more clearly from stack_t. Accommodate throughout. (_cygtls): Add altstack member. * exceptions.cc (exception::handle): Set SIGSEGV handler to SIG_DFL if we encounter a stack overflow, and no alternate stack has been defined. * include/cygwin/signal.h (MINSIGSTKSZ): Define (SIGSTKSZ): Define. (SA_ONSTACK): Define. * signal.cc (sigaltstack): New function. * tlsoffset.h: Regenerate. * tlsoffset64.h: Ditto. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-19Formatting fixes in exceptions.ccCorinna Vinschen2-37/+67
* Makefile.in (install-man): Exclude release subdir from search paths. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-18Disallow installing "man pages" from release subdirCorinna Vinschen2-4/+8
* Makefile.in (install-man): Exclude release subdir from search paths. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-17Add sethostnameCorinna Vinschen5-2/+26
* net.cc (sethostname): New function. * common.din (sethostname): Export * include/cygwin/version.h (CYGWIN_VERSION_DLL_MAJOR): Bump to 2001. (CYGWIN_VERSION_DLL_MINOR): Set to 0. * new-features.xml (ov-new): Rename from ov-new1.7. (ov-new2.1): Add new section. Document sethostname. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-17Add release/2.0.5 fileCorinna Vinschen1-0/+16
2015-06-15Try to handle concurrent close on socket more gracefullyCorinna Vinschen2-14/+53
* fhandler_socket.cc (LOCK_EVENTS): Don't enter critical section with invalid mutex handle since then socket has been closed. (UNLOCK_EVENTS): Close critical section. (fhandler_socket::evaluate_events): Handle calling connect on shutdown socket. (fhandler_socket::wait_for_events): Try for pthread_testcancel in case of WAIT_FAILED. Try to come up with a better errno in case we waited on an invalid handle. (fhandler_socket::release_events): Change wsock_mtx and wsock_evt to NULL under lock to avoid accessing invalid handle. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-15Handle more Winsock error codes.Corinna Vinschen2-0/+7
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-15Don't enforce SA_RESTART in non-main threadsCorinna Vinschen2-1/+12
* exceptions.cc (_cygtls::call_signal_handler): Disable enforcing SA_RESTART in non-main threads to allow returning with EINTR from system calls. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-06-11Fix ChangeLog entryCorinna Vinschen1-1/+1
2015-06-11Bump minor DLL version to 5Corinna Vinschen2-1/+5
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>