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
This patch adds pthread_getname_np and pthread_setname_np.
These were added to glibc in 2.12[1] and are also present in some form on
NetBSD and several UNIXes.
The code is based on NetBSD's implementation with changes to better match
Linux behaviour.
Implementation quirks:
* pthread_setname_np with a NULL pointer segfaults (as linux)
* pthread_setname_np returns ERANGE for names longer than 16 characters (as
linux)
* pthread_getname_np with a NULL pointer returns EFAULT (as linux)
* pthread_getname_np with a buffer length of less than 16 returns ERANGE (as
linux)
* pthread_getname_np truncates the thread name to fit the buffer length.
This guarantees success even when the default thread name is longer than 16
characters, but means there is no way to discover the actual length of the
thread name. (Linux always truncates the thread name to 16 characters)
* Changing program_invocation_short_name changes the default thread name (on
linux, it has no effect on the default thread name)
I'll leave it up to you to decide if any of these matter.
This is implemented via class pthread_attr to make it easier to add
pthread_attr_[gs]etname_np (present in NetBSD and some UNIXes) should it
ever be added to Linux (or we decide we want it anyway).
[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=NEWS
This routine makes a call to fabs instead of fabsl(), causing truncation.
Clang complains (warning: absolute value function 'fabs' given an argument of type 'long double' but has parameter of type 'double' which may cause truncation of value).
Signed-off-by: David Wohlferd <dw@LimeGreenSocks.com>
The R language has some hacks specifically for mingw-w64 that
were caused by our handling of NaNs in sqrt(x). R uses a
special valued NaN to mean 'Not Available' and expects it to
be retained through various calculations. Our sqrt(x) doesn't
do this, instead it normalises such a NaN (retaining sign).
From:
http://wwwf.imperial.ac.uk/~drmii/M3SC_2016/IEEE_2008_4610935.pdf
"6.2.3 NaN propagation
An operation that propagates a NaN operand to its result and
has a single NaN as an input should produce a NaN with the
payload of the input NaN if representable in the destination
format."
There might even be a slight speed-up from this too.
Thanks to Duncan Murdoch for finding the reference.
Change nl_langinfo to nl_langinfo_l using locale given as argument.
Remove outdated TRANSITION_PERIOD_HACK. The codeset is stored in
the locale for quite some time now. For !MB_CAPABLE targets, just
return "US_ASCII" as codeset.
Implement nl_langinfo by calling nl_langinfo_l. Export nl_langinfo_l
from Cygwin DLL and bump minor API version number.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The former __locale_charset always fetched the current locale's charset.
We need the per-locale charset, too, in future. Rename __locale_charset
to __current_locale_charset and change __locale_charset to take a
locale_t as parameter. Accommodate througout.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit 6f3943b erroneously removed the `#ifdef _COMPILING_NEWLIB'
guarding the __getreent inline function. This patch ignored the
fact that config.h is included when building applications, and the
code in question requires internal, auto-generated headers to be
available which are not exposed to user-space.
Reinstantiate defined(_COMPILING_NEWLIB) test and alternatively
check for defined (__INSIDE_CYGWIN__), otherwise we'd have to
reinstantiate the __getreent macro in cygtls.h which is really
confusing.
While testing it turned out that a low number of source codes inside
Cygwin won't see the inline __getreent due to a missing __INSIDE_CYGWIN__
definition. For malloc.cc this was actually deliberate to get different
definitions from including cygmalloc.h. Change this by defining
__INSIDE_CYGWIN__ in malloc.cc but changing the test in cygmalloc.h
to test for defined(DLMALLOC_VERSION). This might need a change if we
ever get around to replace dlmalloc with a newer, more threading-aware
malloc implementation.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit 97d0449 left a bit to be desired. First, the fact that any
new-style ACL couldn't be "standard ACL" anymore was very much over
the top. On one hand Admins and SYSTEM ACEs are not supposed to be
masked, but on the other hand we *must* create the CLASS_OBJ
because otherwise we don't have information about masking the
execute perms for both groups. The ACL would also fail aclcheck.
And while get_posix_access now returns the "is standard acl" flag,
it hasn't been utilized by set_created_file_access. Rather,
set_created_file_access has simply continued to check for
nentries > MIN_ACL_ENTRIES, which led to all kinds of weird group
and CLASS_OBJ perms. The new code now always manipulates CLASS_OBJ
perms if a CLASS_OBJ is present, and it always manipulates group perms
if the ACL has been marked as "standard" ACL.
Another problem (not related to commit 97d0449) is the order
get_posix_access adds missing perms. CLASS_OBJ perms are computed
*before* missing GROUP_OBJ perms have been added. Thus the CLASS_OBJ
perms could be too tight and led to additional, buggy DENY ACEs.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This partially reverts commit 10a30e7 as far as the Cygwin version of
the __getreent function is concerned. Remove _COMPILING_NEWLIB guard
only allowing to use __getreent inline function when building newlib,
since we wan to use it in Cygwin as well.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Stefan Assmann <sassmann@redhat.com>
This reverts commit 4de8596. It worked around a problem which was
actually introduced by patch 10a30e7 a few weeks ago. Rather than
adding special code to the newlib version of __getreent, the followup
patch reinstantiates the original, Cygwin-only implementation of
__getreent.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Stefan Assmann <sassmann@redhat.com>
No real domain, no DC, no infos via NetUserGetInfo... nothing. Just nothing.
Use fixed uid 0x1000 (4096) for AzureAD user and gid 0x1001 (4097) for
AzureAD group. Note that this group is part of the user token, but it's
not the primary group. The primary group SID is, unfortunately, the
user's SID.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far the lib function __getreent always returned _impure_ptr. On Cygwin
this is only correct after _impure_ptr got initialized. The inline
function in include/cygwin/config.h always returns the right _reent ptr,
though.
After introducing per-thread locales, the __getreent function is called
prior to initialization of _impure_ptr (from dll_crt0_0) to access the
locale pointer, which leads to a crash.
Fix the __getreent lib function for Cygwin to return the correct _reent
pointer all the time. Rename inline function to __inline_getreent
and introduce a macro __getreent calling the inline function. Change
the lib function __getreent to call __inline_getreent on Cygwin.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The default UI language returned by GetUserDefaultUILanguage does not
necessarily reflect what the user really wants. E. g., the system could
be en_US, but the desired language is en_CA, without having a CA langpack
installed.
Changing the settings under "Languages" and changing the keyboard layout
is only affecting the so-called "Input language", while what's returned
by GetUserDefaultUILanguage is the "Display language". Changing the
latter requires installing MUI langpacks.
Thus, we introduce a way to fetch the "Input language" using the -i or
--input option.
Also clean up documentation of locale(1).
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Add global const __C_locale for reference purposes.
Bump Cygwin API minor number and DLL major version number to 2.6.0.
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
This allows looping through the structs and buffers. Also
rearrange definitions to follow order of LC_xxx values.
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
Don't use global variables. This allows to call loadlocale from
the yet to be created newlocale().
Rename _thr_locale_t to __locale_t (these locales are not restricted
to threads so the name is misleading).
Along these lines, fix _set_ctype to take a __locale_t as parameter.
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
- Remove charset parameter from low level __foo_wctomb/__foo_mbtowc calls.
- Instead, create array of function for ISO and Windows codepages to point
to function which does not require to evaluate the charset string on
each call. Create matching helper functions. I.e., __iso_wctomb,
__iso_mbtowc, __cp_wctomb and __cp_mbtowc are functions returning the
right function pointer now.
- Create __WCTOMB/__MBTOWC macros utilizing per-reent locale and replace
calls to __wctomb/__mbtowc with calls to __WCTOMB/__MBTOWC.
- Drop global __wctomb/__mbtowc vars.
- Utilize aforementioned changes in Cygwin to get rid of charset in other,
calling functions and simplify the code.
- In Cygwin restrict global cygheap locale info to the job performed
by internal_setlocale. Use UTF-8 instead of ASCII on the fly in
internal conversion functions.
- In Cygwin dll_entry, make sure to initialize a TLS area with a NULL
_REENT->_locale pointer. Add comment to explain why.
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
Move all locale category structure definitions into setlocale.h and remove
other headers in locale subdir. Create inline accessor functions for
current category struct pointers and use throughout. Use pointers to
"C" locale category structs by default in __global_locale.
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
Introduce first cut of struct _thr_locale_t used for the locale_t definition.
Introduce global instance called __global_locale used by default.
Introduce internal inline functions __get_global_locale, __get_locale_r,
__get_current_locale.
Remove usage of global variables in favor of accessor functions pointing to
__global_locale for now. Include all local headers in locale subdir from
setlocale.h to get single include for internal locale access.
Introduce __CTYPE_PTR macro to replace direct access to __ctype_ptr__
and use throughout in isxxx functions.
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
This is a followup to a report back in 2011 about essentially the same issue:
https://cygwin.com/ml/cygwin/2011-04/msg00031.html
The same test program in that report demonstrates the issue, but with
kill sending any non-zero signal. To reiterate, the problem here is
POSIX compliance with respect to sending signals to zombie processes.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html
claims:
Existing implementations vary on the result of a kill() with pid
indicating an inactive process (a terminated process that has not been
waited for by its parent). Some indicate success on such a call
(subject to permission checking), while others give an error of
[ESRCH]. Since the definition of process lifetime in this volume of
POSIX.1-2008 covers inactive processes, the [ESRCH] error as described
is inappropriate in this case. In particular, this means that an
application cannot have a parent process check for termination of a
particular child with kill(). (Usually this is done with the null
signal; this can be done reliably with waitpid().)
In response to the originally issue, this was fixed *specifically* for
the case of kill(pid, 0). But my reading of the above is that kill()
should return 0 in this case regardless of the signal (modulo
permissions, etc.). On Linux, for example, when calling kill with pid
of a zombie process the kernel will happily deliver the signal to the
relevant task_struct; it will just never be acted on since the task
will never run again.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit d7586cb incorrectly checked only for the new cursor position
beyond the old cursor position to decide if we have to correct for user
scrolling. Since this situation is handled just fine if the cursor is
still visible, only perform the subsequent correction if the cursor is
not in the visible console window.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit ba58e5f lowered permission requirements when opening threads
and processes to {PROCESS,THREAD}_QUERY_LIMITED_INFORMATION. However,
when creating the /proc/<PID>/maps file, the call to VirtualQueryEx
requires PROCESS_QUERY_INFORMATION access
Note: It seems PROCESS_QUERY_LIMITED_INFORMATION is sufficient starting
with Windows 8.1, but this is neither documented on MSDN, nor is it a
safe bet. It may have to do with a fixed implementation of the UAC
trust levels. Let's better follow the docs for now.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
We must call SetConsoleCursorPosition prior to SetConsoleWindowInfo,
otherwise the scroll bars will not be updated by the OS. Make sure
to scroll the console window by just the right amount to have the
new cursor position one line after the used console buffer area at
the top of the console window, no matter the scroll state.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
SIGTTIN should be raised when read() is made on a tty in a backgrounded
process, but not when it's tested with poll()/select().
I guess poll()/select() does need to call bg_check(), in order to detect the
error conditions that notices (that is, if bg_check() returns bg_eof or
bg_error, then fd is ready as an error condition exists) so add an optional
parameter to fhandler_base::bg_select() to indicate that signals aren't
desired.
See https://cygwin.com/ml/cygwin-developers/2016-07/msg00004.html