pfg [Sun, 23 Dec 2018 18:15:48 +0000 (18:15 +0000)]
gai_strerror() - Update string error messages according to RFC 3493.
Error messages in gai_strerror(3) vary largely among OSs.
For new software we largely replaced the obsoleted EAI_NONAME and
with EAI_NODATA but we never updated the corresponding message to better
match the intended use. We also have references to ai_flags and ai_family
which are not very descriptive for non-developer end users.
Bring new new error messages based on informational RFC 3493, which has
obsoleted RFC 2553, and make them consistent among the header adn
manpage.
Ken Brown [Sun, 22 Sep 2019 15:33:34 +0000 (11:33 -0400)]
Cygwin: rmdir: fail if last component is a symlink, as on Linux
If the last component of the directory name is a symlink followed by a
slash, rmdir now fails, following Linux but not POSIX, even if the
symlink resolves to an existing empty directory.
Ken Brown [Sat, 21 Sep 2019 17:09:09 +0000 (13:09 -0400)]
Cygwin: remove old cruft from path_conv::check
Prior to commit b0717aae, path_conv::check had the following code:
if (strncmp (path, "\\\\.\\", 4))
{
/* Windows ignores trailing dots and spaces in the last path
component, and ignores exactly one trailing dot in inner
path components. */
char *tail = NULL;
[...]
if (!tail || tail == path)
/* nothing */;
else if (tail[-1] != '\\')
{
*tail = '\0';
[...]
}
Commit b0717aae0 intended to disable this code, but it inadvertently
disabled only part of it. In particular, the declaration of the local
tail variable was in the disabled code, but the following remained:
if (!tail || tail == path)
/* nothing */;
else if (tail[-1] != '\\')
{
*tail = '\0';
[...]
}
[A later commit removed the disabled code.]
The tail variable here points into a string different from path,
causing that string to be truncated under some circumstances. See
- After commit d4045fdbef60d8e7e0d11dfe38b048ea2cb8708b, the TTY
displayed by ps command is incorrect if the process is non-cygwin
process. This patch fixes this issue.
Cygwin: pty: Use autoload feature for pseudo console system calls.
- The autoload feature is used rather than GetModuleHandle(),
GetProcAddress() for CreatePseudoConsole(), ResizePseudoConsole()
and ClosePseudoConsole().
Cygwin: pty: Use system NLS function instead of PTY's own one.
- Since calling system __loadlocale() caused execution error,
PTY used its own NLS function. The cause of the error has been
found, the corresponding code has been rewritten using system
function.
Mark Geisert [Sat, 14 Sep 2019 04:58:02 +0000 (21:58 -0700)]
Cygwin: fix CPU_SET macro visibility
The CPU_SET macros defined in Cygwin's include/sys/cpuset.h must not
be visible in an application's namespace unless _GNU_SOURCE has been
#defined. Internally this means wrapping them in #if __GNU_VISIBLE.
Cygwin: console: Fix read() in non-canonical mode.
- In non-canonical mode, cygwin console returned only one character
even if several keys are typed before read() called. This patch
fixes this behaviour.
Cygwin: pty: Switch input and output pipes individually.
- Previously, input and output pipes were switched together between
the traditional pty and the pseudo console. However, for example,
if stdin is redirected to another device, it is better to leave
input pipe traditional pty side even for non-cygwin program. This
patch realizes such behaviour.
Cygwin: pty: Fix screen alternation while pseudo console switching.
- If screen alternated while pseudo console switching, it sometimes
failed. This might happen when the output of the non-cygwin program
is piped to less. This patch fixes this issue.
Cygwin: pty: Fix the behaviour of Ctrl-C in the pseudo console mode.
- When the I/O pipe is switched to the pseudo console side, the
behaviour of Ctrl-C was unstable. This rarely happens, however,
for example, shell sometimes crashes by Ctrl-C in that situation.
Furthermore, Ctrl-C was ignored if output of non-cygwin program
is redirected to pipe. This patch fixes these issues.
Joel Sherrill [Tue, 10 Sep 2019 15:49:11 +0000 (10:49 -0500)]
libc/include/devctl.h: Add SOCKCLOSE per FACE Technical Standard, Edition 3.0
The FACE Technical Standard, Edition 3.0 and later require the
definition of the subcommand SOCKCLOSE in <devctl.h>.
Reference: https://www.opengroup.org/face
Cygwin: pty: Make sure to show system error messages
- Forcibly attach to pseudo console in advance so that the error
messages by system_printf() are displayed to screen reliably.
This is needed when stdout is redirected to another pty. In this
case, process has two ptys opened. However, process can attach
to only one console. So it is necessary to change console attached.
Cygwin: pty: Fix potential state mismatch regarding pseudo console.
- PTY with pseudo console support sitll has problem which potentially
cause state mismatch between state variable and real console state.
This patch fixes this issue.
Cygwin: pty: Fix select() with pseudo console support.
- select() did not work correctly when both read and except are
polled simultaneously for the same fd and the r/w pipe is switched
to pseudo console side. This patch fixes this isseu.
Cygwin: pty: Disable clear screen on new pty if TERM=dumb or emacs*.
- Pseudo console support introduced by commit 169d65a5774acc76ce3f3feeedcbae7405aa9b57 shows garbage ^[[H^[[J in
some of emacs screens. These screens do not handle ANSI escape
sequences. Therefore, clear screen is disabled on these screens.
- Pseudo console support introduced by commit 169d65a5774acc76ce3f3feeedcbae7405aa9b57 sometimes cause random
crash or freeze by pressing ^C while cygwin and non-cygwin
processes are executed simultaneously in the same pty. This
patch is a workaround for this issue.
Cygwin: pty: Limit API hook to the program linked with the APIs.
- API hook used for pseudo console support causes slow down.
This patch limits API hook to only program which is linked
with the corresponding APIs. Normal cygwin program is not
linked with such APIs (such as WriteFile, etc...) directly,
therefore, no slow down occurs. However, console access by
cygwin.dll itself cannot switch the r/w pipe to pseudo console
side. Therefore, the code to switch it forcely to pseudo
console side is added to smallprint.cc and strace.cc.
Cygwin: pty: Fix state management for pseudo console support.
- Pseudo console support introduced by commit 169d65a5774acc76ce3f3feeedcbae7405aa9b57 has some bugs which
cause mismatch between state variables and real pseudo console
state regarding console attaching and r/w pipe switching. This
patch fixes this issue by redesigning the state management.
Cygwin: pty: Move function hook_api() into hookapi.cc.
- PTY uses Win32 API hook for pseudo console suppot. The function
hook_api() is used for this purpose and defined in fhandler_tty.cc
previously. This patch moves it into hookapi.cc.
Adjust nios2 and m68k semihosting for sys/stat.h changes.
Commit 72ff9acad2ab54e80a19ddaec0106065c817e3f6 caused st_atime,
st_ctime, and st_mtime to be defined as macros. This collided with
use of these identifiers as field names in struct gdb_stat (which
represents the GDB RSP encoding of struct stat) in libgloss
semihosting support for nios2 and m68k. This patch renames the
affected fields of struct gdb_stat.
Takashi Yano [Tue, 27 Aug 2019 18:04:02 +0000 (03:04 +0900)]
Cygwin: pty: add pseudo console support.
- Support pseudo console in PTY. Pseudo console is a new feature
in Windows 10 1809, which provides console APIs on virtual
terminal. With this patch, native console applications can work
in PTYs such as mintty, ssh, gnu screen or tmux.
Jeff Johnston [Mon, 19 Aug 2019 22:01:45 +0000 (18:01 -0400)]
Revert previous change to sys/stat.h and fix cris libgloss
- revert previous fix which altered sys/stat.h
- fix libgloss/cris/gensyscalls to undef st_atime, st_mtime,
and st_ctime macros which cannot be used with new_stat structure
Corinna Vinschen [Fri, 16 Aug 2019 14:36:06 +0000 (16:36 +0200)]
Cygwin: select: revamp non-polling code for signalfd
Rather than waiting for signalfd_select_wait in a thread, which is racy,
create a global event "my_pendingsigs_evt" which is set and reset by
wait_sig depending only on the fact if blocked signals are pending or not.
This in turn allows to WFMO on this event in select as soon as signalfds
are present in the read descriptor set. Select's peek and verify
will then check if one of the present signalfds is affected.
Mark Geisert [Thu, 15 Aug 2019 05:59:43 +0000 (22:59 -0700)]
Cygwin: ldd: Try harder to get dll names
Borrow a trick from strace to lessen occurrences of "??? => ???" in ldd
output. Specifically, if the module name isn't found in the usual place
in the mapped image, use the file handle we have to look up the name.
Corinna Vinschen [Mon, 12 Aug 2019 20:40:50 +0000 (22:40 +0200)]
Cygwin: fix potential SEGV in sigwaitinfo/signalfd scenario
On sigwaitinfo or reading from a signalfd, signal processing sets up
signal handling via sigdelayed even if the handler address is NULL.
This doesn't have any impact on sigwaitinfo scenarios (or at least, I
wasn't able to come up with a reproducer) but it breaks signalfd
scenarios, where eventually a call to call_signal_handler from
sigdelayed will try to call the NULL function.
Takashi Yano [Mon, 12 Aug 2019 13:48:45 +0000 (22:48 +0900)]
Cygwin: console: Fix cursor position restore after screen alternation.
- If screen is alternated on console, cursor position is not restored
correctly in the case of xterm compatible mode is enabled. For example,
the shell prompt is shown at incorrect position after using vim.
This patch fixes this problem.
Takashi Yano [Mon, 12 Aug 2019 13:47:42 +0000 (22:47 +0900)]
Cygwin: console: Add workaround for windows xterm compatible mode bug.
- The horizontal tab positions are broken after resizing console window.
This seems to be a bug of xterm compatible mode of windows console.
This workaround fixes this problem.
Cygwin: build_env: fix off-by-one bug when re-adding PATH
Adding default winvar 'PATH=C:\cygwin64\binZ' to an environment that is
already allocated for 'SYSTEMROOT=ZWINDIR=Z', we need to count that
trailing (Z)ero as well. Otherwise we trigger this assertion failure:
Cygwin: exec: check execute bit prior to evaluating script
When the exec family of functions is called for a script-like
file, the av::setup function handles the exec[vl]p case as
well. The execve case for files not starting with a she-bang
is handled first by returning ENOEXEC. Only after that, the
file's executability is checked.
This leads to the problem that ENOEXEC is returned for non-executable
files as well. A calling shell interprets this as a file it should try
to run as script. This is not desired for non-executable files.
Fix this problem by checking the file for executability first. Only
after that, follow the other potential code paths.
When simulating arm code, the target program startup code (crt0) uses
semihosting invocations to get the command line from the simulator. The
simulator returns the command line and its size into the area passed in
parameter. (ARM 32-bit specifications :
http://infocenter.arm.com/help/topic/com.arm.doc.dui0058d/DUI0058.pdf
chapter "5.4.19 SYS_GET_CMDLINE").
The memory area pointed by the semihosting register argument is located
in .text section (usually not writtable (RX)).
If we run this code on a simulator that respects this rights properties
(qemu user-mode for instance), the command line will not be written to
the .text program memory, in particular the length of the string. The
program runs with an empty command line. This problem hasn't been seen
earlier probably because qemu user-mode is not so much used, but this can
happen with another simulator that refuse to write in a read-only segment.
With this modification, the command line can be correctly passed to the
target program.
Changes:
- newlib/libc/sys/arm/crt0.S : Arguments passed to the
AngelSWI_Reason_GetCmdLine semihosting invocation are placed into .data
section instead of .text
Mark Geisert [Sun, 4 Aug 2019 22:45:46 +0000 (15:45 -0700)]
Cygwin: Implement CPU_SET(3) macros
This patch supplies an implementation of the CPU_SET(3) processor
affinity macros as documented on the relevant Linux man page.
There is a mostly superset implementation of cpusets under newlib's
libc/sys/RTEMS/include/sys that has Linux and FreeBSD compatibility
and is built on top of FreeBSD bitsets. This Cygwin implementation
and the RTEMS one could be combined if desired at some future point.
Do not attach to the child before it was successfully initialized, or we
would need more sophisticated cleanup on child initialization failure,
like suppressing SIGCHILD delivery with multiple threads ("waitproc")
involved.
Improves "Cygwin: fork: Remember child not before success.",
commit f03ea8e1c57bd5cea83f6cd47fa02870bdfeb1c5, which leads to fork
problems if cygserver is running:
During fork, the child process requires the process table to be
initialized for fixup_shms_after_fork, while still allowing subsequent
dlls.load_after_fork to fail silently (for when the "forkable" hardlinks
are not created yet).
pinfo::remember not performing reattach anymore requires explicit
pinfo::reattach now where appropriate.
Prepares to improve "Cygwin: fork: Remember child not before success."
commit f03ea8e1c57bd5cea83f6cd47fa02870bdfeb1c5, which leads to fork
problems if cygserver is running:
The _end marker must be aligned to 4-bytes to ensure that the last
element written does not reach beyond the address of _end. This is
also necessary as the termination condition is an equality test
instead of an ordered test so (_end - _fbss) must be a multiple of
4-bytes. The alignment is already correct for mti*.ld files, fix
it for all remaining MIPS scripts that don't already align to at
least 4.
Richard Earnshaw [Fri, 26 Jul 2019 15:08:55 +0000 (16:08 +0100)]
[arm] remove libc/sys/arm/sys/param.h
The Arm sys/param.h does not define anything differently to the
generic sys/param.h, but fails to define some things that that file
provides. There does not appear to be any reason to keep this version
and we should revert to using the common version.
Introducing an independent Cygwin PID introduced a regression:
The expectation is that the myself pinfo pointer always points to a
specific address right in front of the loaded Cygwin DLL.
However, the independent Cygwin PID changes broke this. To create
myself at the right address requires to call init with h0 set to
INVALID_HANDLE_VALUE or an existing address:
void
pinfo::init (pid_t n, DWORD flag, HANDLE h0)
{
[...]
if (!h0 || myself.h)
[...]
else
{
shloc = SH_MYSELF;
if (h0 == INVALID_HANDLE_VALUE) <-- !!!
h0 = NULL;
}
The aforementioned commits changed that so h0 was always NULL, this way
creating myself at an arbitrary address.
This patch makes sure to set the handle to INVALID_HANDLE_VALUE again
when creating a new process, so init knows that myself has to be created
in the right spot. While at it, fix a potential uninitialized handle
value in child_info_spawn::handle_spawn.
Fixes: b5e1003722cb ("Cygwin: processes: use dedicated Cygwin PID rather than Windows PID") Fixes: 88605243a19b ("Cygwin: fix child getting another pid after spawnve") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Cygwin: Don't change pgid to ctty pgid under debugger
_pinfo::set_ctty sets myself's pgid to the ctty pgid if the process has
been started from a non-Cygwin process. This isn't the right thing to
do when started from GDB. GDB starts the application via standard
Windows means, not via Cygwin fork/exec, so it's treated as being
a non-Cygwin parent.
But we want the app running in it's own process group. So skip this
step when running under a debugger
The .init/.fini sections are not required for msp430-elf, and add unnecessary
code bloat to the CRT library. These sections are specified as "unused" by
the MSP430 EABI.
.init existed to call __crt0_run_{init,preinit}_array which run through
the functions in .{init,preinit}_array.
__crt0_run_{init,preinit}_array are already dynamically included like the
other crt0 functions, so these can be placed before the call to main,
which ensures they are still called if needed.
With these functions moved, .init has no purpose and can be removed.
.fini existed to call __crt0_run_fini_array.
However, the "__msp430_fini" symbol which marks the start of .fini has
never been used, so no termination routines have ever been run for
msp430. On returning from main(), _exit() is called which just loops
forever.
So there is no current expectation that __crt0_run_fini_array will
get called by the CRT code. Further work is to ensure functions
registered with atexit can be optionally called during program termination,
and then __crt0_run_fini_array can be registered with atexit during
program initialization.
The mechanisms for supporting the "-minrt" option have also been removed.
"-minrt" enabled a "minimum runtime environment" by removing calls to
functions which run global static initializers and constructors. Since
this behaviour is now dynamic, and these functions are only included
when needed, the minrt versions of the CRT object files are no longer
required.
Ken Brown [Wed, 24 Jul 2019 15:29:53 +0000 (11:29 -0400)]
Cygwin: fhandler_termios::tcsetpgrp: check that argument is non-negative
Return -1 with EINVAL if pgid < 0.
Previously tcsetpgrp() would blindly go ahead and set the pgid of the
controlling terminal to a negative value, causing later calls to
various functions to fail.
For example, gdb has code like the following:
tcsetpgrp (0, getpgid (inf->pid));
If getpgid (inf->pid) fails (returns -1), then this code would set the
pgid of fd 0 to -1, so that some later calls to getpgid() would also
return -1. This caused the problem reported here: