summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/miscfuncs.cc
Commit message (Collapse)AuthorAgeFilesLines
* yield: Don't lower thread priority, it leads to starvationCorinna Vinschen2017-03-081-5/+6
| | | | | | | ...and it's not required anymore to have the same effect as the original code post-XP. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Cygwin: Emit correct errno EAGAIN if we can't create another threadCorinna Vinschen2017-03-081-0/+2
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* miscfuncs.cc: Revert exclusion of inclusion of exception.hCorinna Vinschen2017-01-191-0/+1
| | | | | | x86 still needs it. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* miscfuncs.cc: Drop unneeded includes and unused global variableCorinna Vinschen2017-01-191-12/+0
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* check_iovec: Change test to be more robust against invalid iovcnt valuesCorinna Vinschen2017-01-191-1/+1
| | | | | | Stop running wild if iovcnt is < 0 to begin with. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Don't assert on sum of iov_len overflowing an ssize_tCorinna Vinschen2017-01-191-3/+3
| | | | | | Rather return EINVAL per POSIX. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Move string functions from miscfunc.cc to strfuncs.ccCorinna Vinschen2017-01-191-192/+0
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Move getentropy/getrandom into own fileCorinna Vinschen2017-01-191-57/+0
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Export getentropy and getrandom callsCorinna Vinschen2016-12-161-3/+47
| | | | | | | | | | | | getentropy per OpenBSD http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2 getrandom per Linux http://man7.org/linux/man-pages/man2/getrandom.2.html Note that GRND_NONBLOCK is not handled
* Define RtlGenRandom correctly in ntsecapi.h wrapperCorinna Vinschen2016-12-141-0/+1
| | | | | | | Include ntsecapi.h where required and just redefine RtlGenRandom correctly in the ntsecapi.h wrapper. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Rearrange RNG code slightlyCorinna Vinschen2016-12-131-6/+0
| | | | | | | | | | | | | | | In preparation of exporting getentropy/getrandom to userspace, rearrange code a bit: - Define RtlGenRandom in ntdll.h. - Drop calls to getentropy in favor of RtlGenRandom (fhandler_socket, fhandler_dev_random). - Add try/except blocks in fhandler_dev_random to return EFAULT rather than crashing if buffer pointer is invalid. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Fix SetThreadName with gdb 7.10 on x86Jon Turney2016-10-201-1/+8
| | | | | | | | | | | Additionally to eccefd97, we need to ensure the exception handler is installed for the _ljfault used to implement _try/_except to get called. Also use the correct macro for x86 conditional compilation. Addresses https://cygwin.com/ml/cygwin/2016-09/msg00143.html Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
* Fix formattingCorinna Vinschen2016-08-251-5/+6
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Fix SetThreadName with current gdbJon Turney2016-08-251-1/+6
| | | | | | | | | | | Wrap SetThreadName()'s call to RaiseException() in __try/__except/__endtry, so that if the attached debugger doesn't know about MS_VC_EXCEPTION (e.g. current gdb and probably strace as well) and continues exception processing, we ignore it, rather than dying due an unhandled exception. Also remove an unnecessary cast in the RaiseException() invocation. Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
* Send thread names to debuggerJon Turney2016-08-231-0/+26
| | | | | | | | | | | | | | | | | | GDB since commit 24cdb46e [1] can report and use these names. Add utility function SetThreadName(), which sends a thread name to the debugger. Use that: - to set the default thread name for main thread and newly created pthreads. - in pthread_setname_np() for user thread names. - for helper thread names in cygthread::create() - for helper threads which are created directly with CreateThread. Note that there can still be anonymous threads, created by system or injected DLLs. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=24cdb46e9f0a694b4fbc11085e094857f08c0419
* Drop has_set_thread_stack_guarantee flagCorinna Vinschen2016-06-241-53/+31
|
* Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout optioncygwin-2_5_2-releaseCorinna Vinschen2016-06-231-3/+0
| | | | | | | | | | | | | | Bump GPLv2+ to GPLv3+ for some files, clarify BSD 2-clause. Everything else stays under GPLv3+. New Linking Exception exempts resulting executables from LGPLv3 section 4. Add CONTRIBUTORS file to keep track of licensing. Remove 'Copyright Red Hat Inc' comments. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Implement getentropy for CygwinCorinna Vinschen2016-03-181-0/+19
| | | | | | | | | | | | | | * miscfuncs.cc (getentropy): Move fhandler_dev_random::crypt_gen_random here and rename to getentropy. Fix type and return values to match getentropy requirements. * miscfuncs.h (getentropy): Add prototype. * fhandler.h (fhandler_dev_random::crypt_gen_random): Remove prototype. * fhandler_random.cc (fhandler_dev_random::crypt_gen_random): Drop. (fhandler_dev_random::write): Use getentropy instead. (fhandler_dev_random::read): Ditto. * fhandler_socket.cc (fhandler_socket::af_local_set_secret): Ditto. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Always allocate main thread stack from pthread stack area on x86_64.Corinna Vinschen2015-12-071-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | * dcrt0.cc: Semi-revert commit 12743c2d5d2721f3a80b4d7671a349be03c1f520. (dll_crt0_0): Drop setting wow64_needs_stack_adjustment on 64 bit. (_dll_crt0): Split out 64 bit code again and always create new main thread stack, unless forked off from the non main thread in the parent. Call create_new_main_thread_stack with parent stack commitsize if started from the parent's main thread. Only call child_info_fork::alloc_stack for the latter case on 64 bit. Slightly rearrange moving rsp and rbp to new stack and document how. Revert 32 bit wow64 handling to its former self. * miscfunc.cc (create_new_main_thread_stack): Take a commitsize parameter and use it if it's not 0. Don't set _main_tls here, it's done in the caller _dll_crt0 anyway. Return stackbase - 16 bytes, rather than stacklimit (which was very wrong anyway). * miscfuncs.h (create_new_main_thread_stack): Accommodate declaration to aforementioned change. * wincap.h (wincaps::has_3264_stack_broken): Remove element. * wincap.cc: Ditto, throughout. * wow64.cc: Semi-revert to pre-12743c2d5d2721f3a80b4d7671a349be03c1f520 but keep architecture-agnostic type changes intact. Fix formatting. * wow64.h: Revert to pre-12743c2d5d2721f3a80b4d7671a349be03c1f520. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Always move 64 bit main thread stack to defined pthread stack areaCorinna Vinschen2015-12-031-0/+41
| | | | | | | | | | | x86_64 only: * dcrt0.cc (_dll_crt0): Always move stack to pthread stack area. Explain why. * miscfuncs.cc (create_new_main_thread_stack): New function to create OS-like stack for main thread in pthread stack area. * miscfuncs.cc (create_new_main_thread_stack): Declare. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* miscfuncs.cc: Fix typos in commentCorinna Vinschen2015-12-021-2/+2
|
* miscfuncs.cc: Fix comment preceeding x86_64 memset and friends.Corinna Vinschen2015-08-101-4/+5
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Cygwin: Fix x86_64 memcpy/memset for n > 2GBCorinna Vinschen2015-07-291-19/+173
| | | | | | | | | | | | | | | | https://cygwin.com/ml/cygwin/2015-07/msg00344.html: RtlFillMemory and RtlCopyMemory only work for size values up to 2GB. Fix this problem by using NetBSD code for memset and memcpy. Add entry points for memmove, wmemset, wmemmove, wmemcpy. Thanks to Roman Petrovski <RPetrovski@illumina.com> for pointing this out. * miscfuncs.cc (memset): x86_64 only: Implement in assembler. (memmove,memcpy): x86_64 only: Ditto. (wmemmove,wmemcpy): x86_64 only: Ditto. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Implement correct RLIMIT_STACK handlingCorinna Vinschen2015-07-051-35/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* * gendef: Export _sigbe on 64 bit as well.Corinna Vinschen2015-01-161-1/+14
| | | | | | | | | | | | * malloc_wrapper.cc (free): In malloc_printf, call caller_return_address instead of __builtin_return_address. (malloc): Ditto. (realloc): Ditto. (calloc): Ditto. * miscfuncs.cc (__caller_return_address): New function. * miscfuncs.h (caller_return_address): New macro calling __caller_return_address. (__caller_return_address): Add prototype.
* * cygheap.cc (init_cygheap::find_tls): Add comment.Corinna Vinschen2014-11-281-13/+11
| | | | | | | | | | | | | | | | * cygtls.cc (well_known_dlls): Rephrase comment. (bloda_detect): New function. (_cygtls::call2): Call init_thread and bloda_detect for non-pthread threads only. (_cygtls::remove): Move remove_tls and remove_wq calls up to run first. * miscfuncs.cc (struct pthread_wrapper_arg): Rename from struct thread_wrapper_arg. (pthread_wrapper): Rename from thread_wrapper and drop "static". Fix comment. Drop call to _cygtls::remove. Call api_fatal rather than ExitThread. Explain why. * miscfuncs.h (pthread_wrapper): Declare pthread_wrapper. * thread.cc (pthread::exit): Add a FIXME comment. Call _cygtls::remove before calling ExitThread.
* * init.cc (dll_entry): Revert previous patch. This requires anotherCorinna Vinschen2014-11-211-1/+1
| | | | | | | | | solution. * miscfuncs.cc (thread_wrapper): Ditto. * sigproc.cc (exit_thread): Disable sending a signal for synchronization with process exit. Explain why. Keep code in for later inspection, should the problem show up again. (sig_send): Use "tls", rather than "tid" as name for _cygtls arg.
* * init.cc (dll_entry): Call _my_tls.remove with INFINITE wait periodCorinna Vinschen2014-11-201-1/+1
| | | | | to avoid SEGVs and subsequent hangs in _cygtls::find_tls. * miscfuncs.cc (thread_wrapper): Ditto.
* * Throughout, use __try/__except/__endtry blocks, rather than myfaultCorinna Vinschen2014-08-221-31/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
* * miscfuncs.cc (__import_address): Cover the first dereference to impCorinna Vinschen2014-08-211-2/+2
| | | | under the fault handler.
* * miscfuncs.cc (strlwr): Rename from cygwin_strlwr. Drop __stdcallCorinna Vinschen2014-08-181-4/+4
| | | | | | | decoration. (strupr): Rename from cygwin_strupr. Drop __stdcall decoration. * string.h (strlwr): Remove override macro. Simply declare. (strupr): Ditto.
* * miscfuncs.cc (check_iovec): Allow 0 as valid iovcnt value.Corinna Vinschen2014-04-231-1/+1
|
* * ldap.cc (rediscover_thread): Give argument a useful name.Corinna Vinschen2014-02-111-1/+1
| | | | | | | * miscfuncs.cc (NT_readline::init): It's a really bad idea trying to print a pointer to a PUNICODE_STRING as PUNICODE_STRING. Fix it. * uinfo.cc (cygheap_domain_info::init): Print status codes as hex values in debug output.
* * miscfuncs.h (class NT_readline): New class to implement line-wiseCorinna Vinschen2014-02-081-1/+77
| | | | | | | reading from file using native NT functions. * miscfuncs.cc (NT_readline::init): New method. * mount.cc (mount_info::from_fstab): Utilize NT_readline to read fstab files.
* Throughout, keep function definitions and declarations in sync withCorinna Vinschen2013-11-251-1/+1
| | | | newlib in terms of C99 "restrict" keyword.
* Throughout, drop unnecessary explicit includes of windows header filesCorinna Vinschen2013-11-241-3/+0
| | | | | | | | | | | | included by default. * winlean.h: Add long comment to explain why we have to define certain symbols. (_NORMALIZE_): Define. (_WINNLS_): Drop definition and subsequent undef. (_WINNETWK_): Ditto. (_WINSVC_): Ditto. 2013-11-23 Eric Blake <eblake@redhat.com>
* * miscfuncs.cc (yield): Revert (after researching) to calling SleepEx with 0.Christopher Faylor2013-06-081-15/+11
| | | | We don't want to actually sleep when calling this function.
* revert accidentally checked in filesChristopher Faylor2013-06-081-2/+4
|
* * cygwait.cc (cygwait): Remove lock around sig retrieval since this code isChristopher Faylor2013-06-081-4/+2
| | | | | | essentially guarded by thread-specific signal_arrived. * exceptions.cc (_cygtls::handle_SIGCONT): Simplify. Eliminate lock/unlock since code is guarded by signal_arrived.
* * exceptions.cc (_cygtls::handle_SIGCONT): Simplify loop waiting forCorinna Vinschen2013-06-061-6/+12
| | | | | | | sig_handle_tty_stop to wake up. Make sure to unlock before calling yield to avoid starvation of sig_handle_tty_stop. Add comments. * miscfuncs.cc (yield): Explain why yield should never be called under _cygtls::lock conditions. Call SleepEx with 1ms timeout. Explain why.
* * globals.cc (__isthreaded): New global variable. Explain what it'sCorinna Vinschen2013-05-211-0/+3
| | | | | used for. * miscfuncs.cc (thread_wrapper): Set __isthreaded to 1 here.
* Throughout, (mainly in fhandler*) fix remaining gcc 4.7 mismatchYaakov Selkowitz2013-05-011-1/+1
| | | | | | | | | warnings between regparm definitions and declarations. * smallprint.cc (__small_vswprintf): Conditionalize declaration and setting of l_opt for only x86_64. * spawn.cc (child_info_spawn::worker): Remove unused 'pid' variable. * thread.cc (verifyable_object_isvalid): Temporarily define as non-inline with gcc 4.7+, regardless of target.
* * Merge in cygwin-64bit-branch.Corinna Vinschen2013-04-231-15/+132
|
* * miscfuncs.cc (__import_address): On second thought, the chance that thisChristopher Faylor2013-01-231-1/+1
| | | | pointer could be NULL is very low so don't bother checking for it.
* * miscfuncs.cc (__import_address): Avoid NULL explicitly.Christopher Faylor2013-01-231-1/+1
|
* * miscfuncs.cc (__import_address): Avoid treating random instructions as importChristopher Faylor2013-01-231-0/+5
| | | | | jump. * malloc_wrapper.cc (malloc_init): Remove comment about 64-bit.
* Throughout, change __attribute__ ((regparm (N))) to just __regN. Throughout,Christopher Faylor2013-01-211-3/+3
| | | | | | | | | | | | | | | | | | | (mainly in fhandler*) start fixing gcc 4.7.2 mismatch between regparm definitions and declarations. * gendef: Define some functions to take @ declaration to accommodate _regN defines which use __stdcall. * gentls_offsets: Define __regN macros as empty. * autoload.cc (wsock_init): Remove unneeded regparm attribute. * winsup.h (__reg1): Define. (__reg2): Define. (__reg3): Define. * advapi32.cc (DuplicateTokenEx): Coerce some initializers to avoid warnings from gcc 4.7.2. * exceptions.cc (status_info): Declare struct to use NTSTATUS. (cygwin_exception::dump_exception): Coerce e->ExceptionCode to NTSTATUS. * fhandler_clipboard.cc (cygnativeformat): Redefine as UINT to avoid gcc 4.7.2 warnings. (fhandler_dev_clipboard::read): Ditto.
* * malloc_wrapper.cc: Change 'use_internal_malloc' to 'use_internal' throughout.Christopher Faylor2013-01-201-2/+11
| | | | | | | | | | | | (export_malloc_called): Delete. (internal_malloc_determined): New variable. (malloc_init): Control calculation of internal/external malloc based on 'internal_malloc_determined'. Use import_address() to determine if malloc in user_data is ours or not. * miscfuncs.cc (thread_wrapper): Make static. (__import_address): Define new function. * miscfuncs.h (import_address): New define. (__import_address): Declare new function.
* Revert the reversion and go with implementation described in cgf-000017, withChristopher Faylor2012-12-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | some modifications. * init.cc (dll_entry): Revert previous change. * miscfuncs.cc: Include sigproc.h for exit_thread declaration. * winsup.h (ExitThread): Define as 'exit_thread' to ensure no accidental use. * sigproc.cc (exit_thread): New function. (wait_sig): Handle __SIGTHREADEXIT case. Don't just block rather than returning from this function. * sigproc.h (__SIGTHREADEXIT): New enum. (exit_thread): Declare. * sync.cc (muto::release): Accept a tls command-line argument. * sync.h (muto::release): Accept a tls command-line parameter. Default to &_my_tls. * cygerrno.h (__set_errno): Define as extern so that no function code is ever emitted. * cygserver_ipc.h (cygserver_ipc.h): Ditto. * miscfuncs.h (transform_chars): Ditto. * path.h (has_attribute): Ditto. * security.h (privilege_luid): Ditto. * winsup.h (flush_file_buffers): Ditto.
* * DevNotes: Add entry cgf-000018.Christopher Faylor2012-12-211-2/+1
| | | | | | | | | | | | | | * init.cc (dll_entry): Grab process lock before exiting to ensure that thread doesn't exit before parent if parent is exiting. * _cygtls.cc (_cygtls::call2): Revert previous 2012-12-21 change. * miscfuncs.cc (thread_wrapper): Ditto. * thread.cc (pthread::exit): Ditto. * sigproc.cc (exit_thread): Ditto. (wait_sig): Ditto. * sync.cc (muto::release): Ditto. * sync.h (muto::release): Ditto. * sigproc.h (__SIGTHREADEXIT): Delete enum. (exit_thread): Delete declaration.