Peter Foley [Sat, 19 Mar 2016 17:45:49 +0000 (13:45 -0400)]
Add necessary braces to if statements
The missing braces cause only the first expression to be guarded by the
else clause.
winsup/cygwin/ChangeLog
* fhandler_disk_file.cc (facl): Add missing braces to if statement.
* mount.cc (dos_drive_mappings): Add missing braces to if statement.
Corinna Vinschen [Sat, 19 Mar 2016 12:21:18 +0000 (13:21 +0100)]
Remove ill-advised cygwin_props
Cygwin_props have been invented to allow switching off the unique
installation keys in the first place, supposedly for debugging.
This never really was a good idea, after all we *want* the installations
to be independent and there's no good reason to break that, not even
for debugging purposes.
Other than that, cygwin_props were meant to be used for some other global
settings which never took place. There's just no good reason to tweak
the DLL binary invisibly where a setting could be done in a file or the
environment.
This patch removes the cygwin_props entirely, including the related
settings in cygcheck.
Yaakov Selkowitz [Fri, 18 Mar 2016 19:10:43 +0000 (14:10 -0500)]
sparc64: move struct timeval to <sys/_timeval.h>
commit bb0159489785d577ad0b8061a1ba7956ee0f89d0 moved the struct timeval
declaration from <sys/time.h> to <sys/_timeval.h>, and commit 01885f533de81ff73e9da1519a4b5f2316b49f86 changed <sys/select.h> to include
<sys/_timeval.h>. Therefore, sparc64's own struct timeval needs to be
moved accordingly in order to avoid a conflict from the generic type.
Sebastian Huber [Fri, 18 Mar 2016 10:49:28 +0000 (11:49 +0100)]
Add arc4random() etc. from OpenBSD 5.8
According to the OpenBSD man page, "A Replacement Call for Random". It
offers high quality random numbers derived from input data obtained by
the OpenBSD specific getentropy() system call which is declared in
<unistd.h> and must be implemented for each Newlib port externally. The
arc4random() functions are used for example in LibreSSL and OpenSSH.
Cygwin provides currently its own implementation of the arc4random
family. Maybe it makes sense to use this getentropy() implementation:
Yaakov Selkowitz [Mon, 14 Mar 2016 21:55:26 +0000 (16:55 -0500)]
Feature test macros overhaul: stdlib.h
Throughout, simplify the C99/C11 conditionals, and replace
__STRICT_ANSI__ with the proper internal POSIX macros. The _*_r
reentrant functions need not be guarded (and most haven't been) because
such names in the global scope are reserved to the implementation.
atoff is unique to newlib.
dtoa is not actually exported (_dtoa_r is used internally), is
nonstandard, and the declaration conflicts with the code included in
MySQL, NSPR, and SpiderMonkey.
mktemp was removed in POSIX.1-2001.
The qsort_r declarations are reordered so that the GNU version retains
precedence.
Yaakov Selkowitz [Mon, 14 Mar 2016 21:40:44 +0000 (16:40 -0500)]
Feature test macros overhaul: stdio.h
Throughout, remove references to __STRICT_ANSI__ and use the proper
internal macros and versions for C99, POSIX, ATFILE for the various *at
functions, or LARGEFILE for fseeko and ftello.
[v]asprintf are GNU extensions, but the *iprintf, *iscanf, and
*asnprintf functions are unique to newlib.
getw and putw were removed from POSIX.1-2001. funopen is BSD, and
fopencookie is GNU.
Yaakov Selkowitz [Mon, 14 Mar 2016 21:26:18 +0000 (16:26 -0500)]
Feature test macros overhaul: math.h
Simplify the C99 conditionals. Mark the drem and gamma functions as
BSD|SVID, the Bessel double functions also XSI and the floats also SUSv3.
signgam is BSD|SVID|XSI, and matherr is SVID. Finally, use the internal
macros to control the symbolic constants.
The previous implementation was flawed in its approach that macros were
often used to hide symbols if defined (e.g. !defined __STRICT_ANSI__ or
!defined _POSIX_SOURCE), whereas the approach of glibc is that these macros
make symbols available when defined (e.g. defined _BSD_SOURCE, or as used
internally, #if __BSD_VISIBLE). As much open-source software is written
with glibc in mind, this necessitated patching numerous packages just to
compile.
In particular, __STRICT_ANSI__ (which is defined by gcc -ansi or -std=c*)
was given too much importance. This implementation limits the influence
of __STRICT_ANSI__ to controlling the default when no other feature test
macros are defined, and to the inclusion of <alloca.h> in <stdlib.h> as
documented. These are the only places where __STRICT_ANSI__ should be
tested.
The following macros are now accepted: _ATFILE_SOURCE, _BSD_SOURCE,
_DEFAULT_SOURCE, _ISOC99_SOURCE, _ISOC11_SOURCE, _LARGEFILE_SOURCE,
_SVID_SOURCE, _XOPEN_SOURCE_EXTENDED.
The existing __*_VISIBLE internal macros have been kept mostly
compatible with the original BSD implementation, with some changes to
the criteria which controls them. Several more macros in this style
have been added where needed for concision or accuracy.
Enabling C++11 or newer in the compiler also enables C99 and C11
functions. Doing so should help move away from the need to define
_GNU_SOURCE in g++ for _GLIBCXX_USE_C99 support as on Linux:
This enables the following ESC sequences:
ESC[c sends primary device attributes
ESC[>c sends secondary device attributes
ESC[6n sends cursor position report
* fhandler.h (class dev_console): Add console read-ahead buffer.
(class fhandler_console): Add peek function for it (for select).
* fhandler_console.cc (fhandler_console::setup): Init buffer.
(fhandler_console::read): Check console read-aheader buffer.
(fhandler_console::char_command): Put responses to terminal
requests (device status and cursor position reports) into
common console buffer (shared between CONOUT/CONIN)
instead of fhandler buffer (separated).
* select.cc (peek_console): Check console read-ahead buffer.
Jon Turney [Tue, 15 Mar 2016 12:57:33 +0000 (12:57 +0000)]
Attempt to fix Coverity issues in ssp
* ssp.c (lookup_thread_id): Consistently check if tix is a null
pointer.
(run_program): Annotate that STATUS_BREAKPOINT falls-through to
STATUS_SINGLE_STEP case.
(main): Guard against high_pc-low_pc overflow and malloc failure.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Corinna Vinschen [Sun, 13 Mar 2016 15:02:55 +0000 (16:02 +0100)]
Don't write NULL SID ACE if it's not necessary.
If the ACL is supposed to reflect only standard POSIX permissions,
and if the permissions are so that user has more perms than group
and group has more perms than other, we don't really need the NULL
SID ACE. If the permissions are that simple, get_posix_access will
not call AuthZ.
* sec_acl.cc (set_posix_perms): Don't write NULL SID ACE if it's
not required. Explain why.
Stefan Roesch [Thu, 10 Mar 2016 16:50:52 +0000 (17:50 +0100)]
or1k: Fix multicore stack calculation
Change the type of the stack pointers to enable pointer calculations at byte
granularity, which is needed for the calculation of _or1k_stack_core[c] and
_or1k_exception_stack_core[c] with _or1k_stack_size and
_or1k_exception_stack_size. (util.c:53-54)
Corinna Vinschen [Sat, 12 Mar 2016 22:41:21 +0000 (23:41 +0100)]
Update setvbuf to latest OpenBSD implementation
Newlib's setvbuf function is very old and has two bugs:
- It sets the SRD/SWR flags incorrectly in case of files opened for
reading and writing.
See https://cygwin.com/ml/cygwin/2016-03/msg00180.html
for a desription of the effect.
- It always sets the buffer size to BUFSIZ if it's not provided by
the application, independent of the optimal blocksize for the
underlying IO device.
Update setvbuf to latest code from OpenBSD to fix both problems.
Corinna Vinschen [Sat, 12 Mar 2016 22:25:11 +0000 (23:25 +0100)]
Use __sputc_r inline code when building with gcc
Per the preceeding comment this inline code is disabled since 1993(!)
because of a bug in GCC at the time. This is long gone and the equivalent
inline code is used in the BSDs for quite some time. Enable this code for
newlib as well.
Corinna Vinschen [Sat, 12 Mar 2016 16:56:21 +0000 (17:56 +0100)]
Fix reading/writing Samba ACLs using RFC2307 mapping
When using RFC2307 uid/gid-mapping on Samba shares, the POSIX ACL contains
the Windows SIDs. When writing back such an ACL we have to map the
Windows SIDs back to the corresponding Samba SIDs representing the UNIX
uid/gid value. When reading Samba SIDs, make sure never to evaluate a
UNIX user account as group.
* sec_acl.cc (set_posix_access): Convert Windows SIDs to
RFC2307-mapped Sambe UNIX SIDs.
* sec_helper.cc (cygpsid::get_id): Skip UNIX user accounts when
trying to evaluate a SID as group. Skip UNIX group accounts when
trying to evaluate a SID as user.
* cygheap.h (cygheap_ugid_cache::reverse_get): New method to
get nfs id from cygwin id.
(cygheap_ugid_cache::reverse_get_uid): Wrapper for uids.
(cygheap_ugid_cache::reverse_get_gid): Wrapper for gids.
... is a variable length list of subauth_count DWORD values being
the actual subauths.
- cygsid::append (DWORD rid)
allows to append a single RID to an alreaday constituted SID.
* security.h (cygsid::create): Declare public.
(cygsid::append): Ditto.
* sec_helper.cc (cygsid::create): Implement.
(cygsid::append): Implement.
* uinfo.cc (pwdgrp::fetch_account_from_windows): Use both new
methods as appropriate. Drop setting csid from string. Create
SID strings for printing SIDs only.
Corinna Vinschen [Fri, 11 Mar 2016 21:50:24 +0000 (22:50 +0100)]
gmon.h: Fix type of gmonparam state member
gmonparam::state is used in calls to Win32 Interlocked functions.
Having this defined as int breaks the build on i686. Redefine as
LONG (same size and correct type on all platforms) to make gcc happy.
Václav Haisman [Fri, 11 Mar 2016 10:28:27 +0000 (11:28 +0100)]
Spinlock spin with pause instruction
Hi.
I have noticed that Cygwin's spinlock goes into heavy sleeping code
for each spin. It seems it would be a good idea to actually try to
spin a bit first. There is this 'pause' instruction which let's the
CPU make such busy loops be less busy. Here is a patch to do this.
Mark Geisert [Sat, 20 Feb 2016 06:58:31 +0000 (22:58 -0800)]
Support profiling of multi-threaded apps.
This patch set modifies Cygwin's profiling support to sample PC values
of all an app's threads, not just the main thread. There is no change
to how profiling is requested: just compile and link the app with "-pg"
as usual. The profiling info is dumped into file gmon.out as always.
A new facility enabled via the environment variable GMON_OUT_PREFIX.
This facility is intended to match an undocumented Linux glibc feature.
Exporting the variable with a non-empty value such as "foo" causes the
profiling info to go to a file named foo.$pid instead of the default.
With that, both resulting processes of a fork() can have their profiling
data captured in separate files. gprof already knows how to accumulate
data from multiple files if they all pertain to the same app.
There is no change to the normal Cygwin execution paths if profiling is
not enabled. And when it is enabled, only the one profiling thread per
profiled app is doing more work than it used to.
* include/sys/cygwin.h: Add CW_CYGHEAP_PROFTHR_ALL.
* cygheap.cc (cygheap_profthr_all): New C-callable function that
runs cygheap's threadlist handing each pthread's thread handle in
turn to profthr_byhandle().
* external.cc (cygwin_internal): Add case CW_CYGHEAP_PROFTHR_ALL.
* gmon.c (_mcleanup): Add support for multiple simultaneous
gmon.out* files named via environment variable GMON_OUT_PREFIX.
* gmon.h (struct gmonparam): Make state decl volatile.
* mcount.c (_MCOUNT_DECL): Change stores into gmonparam.state to use
Interlocked operations. Add #include "winsup.h", update commentary.
* profil.c (profthr_byhandle): New function abstracting out the
updating of profile counters based on a thread handle.
(profthr_func): Update to call profthr_byhandle() to sample the main
thread then call cygheap_profthr_all() indirectly through
cygwin_internal(CW_CYGHEAP_PROFTHR_ALL) to sample all other threads.
(profile_off): Zero targthr to indicate profiling was turned off.
(profile_on): Fix handle leak on failure path.
(profile_child): New callback func to restart profiling in child
process after a fork if the parent was being profiled.
(profile_ctl): Call pthread_atfork() to set profile_child callback.
Corinna Vinschen [Thu, 10 Mar 2016 17:00:00 +0000 (18:00 +0100)]
getifaddrs: Return pointer to extended interface info in ifa_data member
According to https://cygwin.com/ml/cygwin/2016-03/msg00124.html it's a
problem to collect friendlyname info using AF_INET6 sockets. Fix problem
by exposing additional hardware info for all collected interfaces via the
pointer in the ifaddrs::ifa_data member.
* include/ifaddrs.h (struct ifaddrs_hwdata): Define as struct of
not yet exposed members of struct ifall, defined in net.cc.
* net.cc (struct ifall): Replace hardware dta members with struct
ifaddrs_hwdata. Accommodate throughout.
(get_ifs): Let ifaddrs ifa_data member point to ifall::ifa_hwdata
member.
Corinna Vinschen [Thu, 10 Mar 2016 09:36:00 +0000 (10:36 +0100)]
Revamp acl_extended_fd/acl_extended_file to avoid open(2) call
Calling open from acl_extended_file{_nofollow} indiscriminately may hang
if the file is a FIFO. Ultimately the FIFO implementation needs a thorough
rewrite, but for the time being we better do what stat(2) and friends do:
Just create an fhandler directly.
* sec_posixacl.cc (__acl_extended_fh): New static function calling
fhandler::facl.
(acl_extended_fd): Just call __acl_extended_fh.
(__acl_extended_file): Take just a path_conv as parameter and
create temporary fhandler to call __acl_extended_fh.
(acl_extended_file): Create path_conv from incoming path and
call __acl_extended_file on it.
(acl_extended_file_nofollow): Ditto.
Overwite potentially faked kernel version with correct values
* ntdll.h (RtlGetNtVersionNumbers): Declare.
* wincap.cc (wincapc::init): Overwrite kernel version info
returned by RtlGetVersion with correct info returnd by
RtlGetNtVersionNumbers. Add comment.
Originally, using RtlGetVersion instead of GetVersionEx was supposed to
fix the fact that GetVersionInfo returns the wrong kernel version if the
executable has been built with an old manifest (or none at all), starting
with Windows 8.1. Either this never really worked as desired and our
testing was flawed, or this has been changed again with Windows 10, so
that RtlGetVersion does the kernel faking twist as well. Since we're
only reading the value in the first process in a process tree. the entire
process tree is running with a wrong OS version information in that case.
Fortunately, the (undocumented) RtlGetNtVersionNumbers function is not
affected by this nonsense, so we simply override the OS version info
fields with the correct values now.
The problem this patch fixes showed up after updating to gcc-5.3.0. The
cuplrit is a change in gcc when emitting section attributes. It only
shows up when building without optimization. Effect in Cygwin: ws2_32
functions failed to load.
In the original code the definition of "NO_COPY wsadata" was preceeding
an __asm__ block (the definition of the _wsock_init wrapper), while the
definition of "NO_COPY here" immediately follows the same assembler
block. When gcc-5.3.0 emits assembler code for the wsadata definition,
it emits the .data_cygwin_nocopy section attribute.
Next it emits the assembler output for the __asm_ block, entirely ignoring
its content. The __asm__ block adds a .text section definition.
Eventually gcc emits assembler code for the here definition. However,
apparently gcc still "knows" that it just emitted the .data_cygwin_nocopy
section attribute and so doesn't redefine it. Remember the __asm__? It
changed the section to .text.
So with gcc-4.9.3 we got:
.section .data_cygwin_nocopy,"w"
wsadata:
__asm__ block:
.text
.section .data_cygwin_nocopy,"w"
here:
With gcc 5.3.0 we now get:
.section .data_cygwin_nocopy,"w"
wsadata:
__asm__ block:
.text
here:
So "here" is now in the .text segment which is read-only. Hilarity ensues.
Jon Turney [Mon, 7 Mar 2016 18:42:41 +0000 (18:42 +0000)]
faq: Sort BLODA list and update advice on fixing fork failures
* faq-using.xml (bloda): Alphabetically sort BLODA list for ease
of finding things in it.
(fixing-fork-failures): Update to suggest rebase-trigger rather
than running rebaseall via dash yourself. Mention detect_bloda
CYGWIN token.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
acl_create_entry: Don't invalidate existing entry_d and permset_d.
* sec_posixacl .cc (__acl_dup): Remove.
(acl_dup): Fold __acl_dup functionality into this function.
(acl_create_entry): Don't create new acl_t. Just realloc
acl->entry to make room for new aclent_t.
* Makefile.in (DLL_OFILES): Add sec_posixacl.o.
(SUBLIBS): Add libacl.a
(libacl.a): New rule to create libacl.a.
* common.din: Export POSIX ACL functions as well as most libacl.a
extensions.
* fhandler.h (fhander_base::acl_get): New prototype.
(fhander_base::acl_set): Ditto.
(fhandler_disk_file::acl_get): Ditto.
(fhandler_disk_file::acl_set): Ditto.
* include/acl/libacl.h: New file.
* include/cygwin/version.h: Bump API minor version.
* include/sys/acl.h: Drop including cygwin/acl.h. Accommodate
throughout Cygwin. Add POSIX ACL definitions.
* sec_acl.cc: Include sec_posixacl.h. Replace ILLEGAL_UID and
ILLEGAL_GID with ACL_UNDEFINED_ID where sensible.
(__aclcheck): New internal acl check function to be used for
Solaris and POSIX ACLs.
(aclcheck32): Call __aclcheck.
(__aclcalcmask): New function to compute ACL_MASK value.
(__aclsort): New internal acl sort function to be used for Solaris
and POSIX ACLs.
(aclsort32): Call __aclsort.
(permtostr): Work directly on provided buffer.
(__acltotext): New internal acltotext function to be used for
Solaris and POSIX ACLs.
(acltotext32): Call __acltotext.
(__aclfromtext): New internal aclfromtext function to be used for
Solaris and POSIX ACLs.
(aclfromtext32): Call __aclfromtext.
* sec_posixacl.cc: New file implemeting POSIX ACL functions.
* sec_posixacl.h: New internal header.
Patrick Bendorf [Mon, 29 Feb 2016 13:34:09 +0000 (14:34 +0100)]
ccwrap: fix build with non-english locale set (v2)
after some discussion on irc and the list i'm resubmitting a simpler
version of the patch.
setting the locale on cygwin to 'C.UTF-8' is not needed, so i'm always
setting it to 'C' which is sufficient for the build process and the
most simple fix.
Patrick Bendorf [Mon, 29 Feb 2016 12:19:43 +0000 (13:19 +0100)]
ccwrap: fix build with non-english locale set
short explanation: after setting up cygwin on my systems the default
locale is set to "de_DE.UTF-8". this leads to ccwrap not picking up
certain "-isystem" arguments, which in turn leads to "stddef.h: no such
file or directory". this breaks the build process for systems having non
english locale.
ccwrap scans the output of the first compiler invocation (line 21) for
some specific english output on and around line 43.
i changed the patch to check uname -o for cygwin string and set the
locale to either C or C.UTF-8
Corinna Vinschen [Fri, 26 Feb 2016 17:52:46 +0000 (18:52 +0100)]
Enable HW interrupt setup on x86/x86_64 systems by default
* configure.host: Define _I386MACH_DISABLE_HW_INTERRUPTS on rdos.
Remove setting _I386MACH_ALLOW_HW_INTERRUPTS anywhere else.
* libc/machine/i386/i386mach.h: Replace test for
_I386MACH_ALLOW_HW_INTERRUPTS with test for
!_I386MACH_DISABLE_HW_INTERRUPTS.
* libc/machine/x86_64/x86_64mach.h: Ditto.
* libc/sys/linux/machine/i386/i386mach.h: Ditto.
* libm/machine/i386/i386mach.h: Ditto.
* pthread.h: Add prototypes for pthread_condattr_getclock(),
pthread_condattr_setclock(), pthread_setschedpri(),
pthread_getcpuclockid(), pthread_getconcurrency(), and
pthread_setconcurrency(). Also cleaned up file header to
remove CVS Id string.
* sys/types.h: Add clock ID to pthread_condattr_t.
Jon Turney [Mon, 2 Nov 2015 15:02:29 +0000 (15:02 +0000)]
ssp: Fixes for 64-bit
Fix various 32/64-bit portability issues in ssp, the single-step profiler, and
also build it for 64-bit.
This didn't turn out to actually be very useful for what I wanted to use it for,
so it's only been lightly tested.
It appears that on x86_64, single-step exceptions occur for much more of the
code in system DLLs, unlike x86, so ssp may take much, much longer to profile
some programs. There is existing code to use breakpoints to mitigate this, but
that is currently disabled.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Corinna Vinschen [Wed, 17 Feb 2016 15:40:27 +0000 (16:40 +0100)]
setuid: Create token from scratch without credentials of caller
* sec_auth.cc (get_token_group_sidlist): Drop auth_luid and
auth_pos parameter. Remove code adding a logon SID.
(get_initgroups_sidlist): Drop auth_luid and auth_pos parameter.
Drop in call to get_token_group_sidlist. Accommodate in callers.
(get_setgroups_sidlist): Ditto.
(create_token): Explicitely set auth_luid to ANONYMOUS_LOGON_LUID
or LOCALSERVICE_LUID depending on OS. Explain why.
Remove handling of logon SID since we don't generate one anymore.
(lsaauth): Drop now unused local variable auth_luid and auth_pos.
* wincap.h (wincaps::has_broken_whoami): New element.
* wincap.cc: Implement above element throughout.