]> sourceware.org Git - newlib-cygwin.git/log
newlib-cygwin.git
5 years agoCygwin: FIFO: stop the listen_client thread before fork/exec
Ken Brown [Sat, 20 Apr 2019 15:41:12 +0000 (11:41 -0400)]
Cygwin: FIFO: stop the listen_client thread before fork/exec

Add methods need_fixup_before, init_fixup_before, and
fixup_before_fork_exec to accomplish this.  Stopping the thread makes
sure that the client handler lists of the parent and child remain in
sync while the forking/execing is in progress.

5 years agoCygwin: FIFO: close connect_evt handles as soon as possible
Ken Brown [Sat, 20 Apr 2019 15:31:08 +0000 (11:31 -0400)]
Cygwin: FIFO: close connect_evt handles as soon as possible

Keeping them open too long can cause an attempt to close them twice
after a fork or exec.

5 years agoCygwin: FIFO: avoid WFMO error in listen_client_thread
Ken Brown [Sat, 20 Apr 2019 15:22:29 +0000 (11:22 -0400)]
Cygwin: FIFO: avoid WFMO error in listen_client_thread

Don't set lct_termination_evt to NULL too early in
fhandler_fifo::stop_listen_client.  Doing so leads to an "Invalid
Handle" error in WFMO.

5 years agoCygwin: FIFO: duplicate the i/o handle when opening a duplexer
Ken Brown [Sat, 20 Apr 2019 15:49:35 +0000 (11:49 -0400)]
Cygwin: FIFO: duplicate the i/o handle when opening a duplexer

Don't use the same i/o handle for the first client handler as is used
for the fhandler itself; this can lead to a later attempt to close the
same handle twice.  Instead use a duplicate.

5 years agoCygwin: FIFO: stop the listen_client thread on an opening error
Ken Brown [Sat, 20 Apr 2019 15:44:01 +0000 (11:44 -0400)]
Cygwin: FIFO: stop the listen_client thread on an opening error

Don't just close the thread handle.

5 years agoCygwin: drop unsupported Windows 10 versions
Corinna Vinschen [Fri, 19 Apr 2019 16:01:44 +0000 (18:01 +0200)]
Cygwin: drop unsupported Windows 10 versions

* Pre-release version still reporting kernel version 6.4.
* Windows 10 1511 is out of support since 2017-10-10.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: FIFO: avoid hang after exec
Ken Brown [Thu, 18 Apr 2019 15:39:52 +0000 (15:39 +0000)]
Cygwin: FIFO: avoid hang after exec

Define fhandler:fifo::fixup_after_exec, which sets listen_client_thr
and lct_termination_evt to NULL.  This forces the listen_client thread
to restart on the first attempt to read after an exec.  Previously the
exec'd process could hang in fhandler_fifo::raw_read.

5 years agoMSP430: Make the inclusion of run_*_array fns depend on defined assembler symbols
Jozef Lawrynowicz [Wed, 17 Apr 2019 12:17:38 +0000 (13:17 +0100)]
MSP430: Make the inclusion of run_*_array fns depend on defined assembler symbols

Many of the MSP430 crt functions (e.g. to initialize bss) are linked
"dynamically", based on symbols defined in the program.
The GNU assembler defines the symbols corresponding to the crt
functions by examining the section names in the input file.

If GCC has been configured with --enable-initfini-array, then
.init_array and .fini_array will hold pointers to global
constructors/destructors. These sections can also hold functions that
need to be executed for other purposes.

The attached patch puts the __crt0_run_{preinit,init,fini}_array and
__crt0_run_array functions in their own object files, so they will
only be linked when needed.

Successfully regtested the DejaGNU GCC testsuite using the binutils and
newlib changes together with GCC trunk configured with
--enable-initfini-array.

5 years agoFix incorrect assembly code in _msp430_run_array
Jozef Lawrynowicz [Mon, 15 Apr 2019 17:06:09 +0000 (18:06 +0100)]
Fix incorrect assembly code in _msp430_run_array

5 years agoCygwin: FIFO: fix and simplify listen_client_thread
Ken Brown [Sun, 14 Apr 2019 19:16:04 +0000 (19:16 +0000)]
Cygwin: FIFO: fix and simplify listen_client_thread

Remove fifo_client_handler::connect and move its code into
listen_client_thread.  That way we can check the return status when a
client handler's connect_evt is signaled.  Previously we incorrectly
assumed there was a successful connection.

Also simplify listen_client_thread in the following ways:

- Replace fhandler_fifo::disconnect_and_reconnect by a new
  delete_client_handler method.  Now we just delete invalid client
  handlers rather than trying to re-use them.

- Try to maintain a client handler list that consists of connected
  client handlers and exactly one that is listening for a connection.
  This allows us to call WaitForMultipleObjects with only two wait
  objects.

- Remove 'dummy_evt' from the fifo_client_handler struct; it is no
  longer needed.

- On exit from listen_client_thread, delete the "extra" (listening)
  client handler.  Otherwise there could be a connection that doesn't
  get recorded in the client handler list.  This could happen when a
  file descriptor is being duplicated.

5 years agoCygwin: FIFO: improve raw_write
Ken Brown [Mon, 15 Apr 2019 15:43:57 +0000 (15:43 +0000)]
Cygwin: FIFO: improve raw_write

Don't set the write end of the pipe to non-blocking mode if the FIFO
is opened in blocking mode.

In fhandler_fifo::raw_write in blocking mode, wait for the write to
complete rather than returning -1 with EAGAIN.

If the amount to write is large, write in smaller chunks (of size
determined by a new data member max_atomic_write), as in
fhandler_base_overlapped.

For convenience, add two new NTSTATUS codes, STATUS_THREAD_SIGNALED
and STATUS_THREAD_CANCELED, to ntdll.h.

5 years agoCygwin: FIFO: start the listen_client thread when duping a reader
Ken Brown [Sun, 14 Apr 2019 19:16:03 +0000 (19:16 +0000)]
Cygwin: FIFO: start the listen_client thread when duping a reader

Otherwise it doesn't get started until the dup'd fd tries to read,
which delays client connections.

5 years agoCygwin: FIFO: fix clone
Ken Brown [Sun, 14 Apr 2019 19:16:02 +0000 (19:16 +0000)]
Cygwin: FIFO: fix clone

After copyto is called, make the new fhandler's pipe_name point to the
new fhandler's pipe_name_buf, which is a *copy* of the old fhandler's
pipe_name_buf.  Previously, get_pipe_name would return the wrong
result after a clone/dup, causing create_pipe_instance and open_pipe
to fail.

Also, stop the listen_client thread when cloning.  Otherwise the
thread can keep accepting connections that the cloned fhandler won't
know about.

Do this via a new method fhandler_fifo::stop_listen_client, extracted
from fhandler_fifo::close.

5 years agoCygwin: FIFO: use a retry loop when opening a writer
Ken Brown [Sun, 14 Apr 2019 19:16:02 +0000 (19:16 +0000)]
Cygwin: FIFO: use a retry loop when opening a writer

There may be short periods when there's no pipe instance available.
Keep trying.

5 years agoCygwin: FIFO: fix the use of the read_ready event
Ken Brown [Sun, 14 Apr 2019 19:16:01 +0000 (19:16 +0000)]
Cygwin: FIFO: fix the use of the read_ready event

Make read_ready a manual reset event.  It should always be set shortly
after startup of the listen_client thread and remain set until the
thread terminates.  (We don't want writers to connect without being
recorded in the client handler list.)

Remove the unnecessary code that checks for read_ready when a reader
is opening.

5 years agoCygwin: FIFO: fix fifo_client_handler::close
Ken Brown [Sun, 14 Apr 2019 19:16:00 +0000 (19:16 +0000)]
Cygwin: FIFO: fix fifo_client_handler::close

Make sure that fhandler_base::close rather than fhandler_fifo::close
is called on the fhandler.  Also, delete the fhandler, since we
allocated it.

5 years agoCygwin: FIFO: code simplification: don't overload get_handle
Ken Brown [Sun, 14 Apr 2019 19:16:00 +0000 (19:16 +0000)]
Cygwin: FIFO: code simplification: don't overload get_handle

Rename fhandler_fifo::get_handle(int) to get_fc_handle(int), and
remove fhandler_fifo::get_handle(void).

5 years agoCygwin: check for STATUS_PENDING in fhandler_base::raw_read
Ken Brown [Sun, 14 Apr 2019 19:15:59 +0000 (19:15 +0000)]
Cygwin: check for STATUS_PENDING in fhandler_base::raw_read

If NtReadFile returns STATUS_PENDING, wait for the read to complete.
This can happen, for instance, in the case of a FIFO opened with
O_RDRW.

5 years agoCygwin: FIFO: fix the error checking in raw_read
Ken Brown [Sun, 14 Apr 2019 19:15:58 +0000 (19:15 +0000)]
Cygwin: FIFO: fix the error checking in raw_read

If the pipe is empty, we can get either ERROR_NO_DATA or
ERROR_PIPE_LISTENING.

5 years agoCygwin: FIFO: fix a thinko in listen_client_thread
Ken Brown [Sun, 14 Apr 2019 19:15:58 +0000 (19:15 +0000)]
Cygwin: FIFO: fix a thinko in listen_client_thread

5 years agoCygwin: FIFO: remember the type of the fhandler
Ken Brown [Sun, 14 Apr 2019 19:15:57 +0000 (19:15 +0000)]
Cygwin: FIFO: remember the type of the fhandler

Add data members 'reader', 'writer', and 'duplexer' to the
fhandler_fifo class.  Set them in fhandler_fifo::open.  ('duplexer'
replaces the previous '_duplexer'.)

This will be useful in later commits.

5 years agoCygwin: FIFO: hit_eof: add a call to fifo_client_lock
Ken Brown [Sun, 14 Apr 2019 19:15:56 +0000 (19:15 +0000)]
Cygwin: FIFO: hit_eof: add a call to fifo_client_lock

The second check of nconnected needs to be protected by a lock as well
as the first.

5 years agoCygwin: FIFO: rename client[] to fc_handler[]
Ken Brown [Sun, 14 Apr 2019 19:15:56 +0000 (19:15 +0000)]
Cygwin: FIFO: rename client[] to fc_handler[]

The word "client" suggests something that holds a handle to the client
side of the pipe (in Windows terminology).  But our
fifo_client_handlers hold a handle the server side of the pipe, and
they *connect* to clients.

5 years agoImplement reduced code size "tiny" printf and puts
Jozef Lawrynowicz [Fri, 12 Apr 2019 11:08:22 +0000 (12:08 +0100)]
Implement reduced code size "tiny" printf and puts

"tiny" printf is derived from _vfprintf_r in libc/stdio/nano-vfprintf.c.
"tiny" puts has been implemented so that it just calls write, without
any other processing.
Support for buffering, reentrancy and streams has been removed from
these functions to achieve reduced code size.

This reduced code size implementation of printf and puts can be enabled
in an application by passing "--wrap printf" and "--wrap puts" to the
GNU linker. This will replace references to "printf" and "puts" in user
code with "__wrap_printf" and "__wrap_puts" respectively.
If there is no implementation of these __wrap* functions in user code,
these "tiny" printf and puts implementations will be linked into the
final executable.

The wrapping mechanism is supposed to be invisible to the user:
- A GCC wrapper option such as "-mtiny-printf" will be added to alias
  these wrap commands.
- If the user is unaware of the "tiny" implementation, and chooses to
  implement their own __wrap_printf and __wrap_puts, their own
  implementation will be automatically chosen over the "tiny" printf and
  puts from the library.

Newlib must be configured with --enable-newlib-nano-formatted-io for
the "tiny" printf and puts functions to be built into the library.

Code size reduction examples:
printf("Hello World\n")
  baseline - msp430-elf-gcc gcc-8_3_0-release
     text    data     bss
   5638     214      26
  "tiny" puts enabled
    text    data     bss
     714      90      20

printf("Hello %d\n", a)
  baseline - msp430-elf-gcc gcc-8_3_0-release
    text    data     bss
   10916     614      28

  "tiny" printf enabled
    text    data     bss
    4632     280      20

5 years agoCopy prerequisite file for "tiny" printf implementation
Jozef Lawrynowicz [Fri, 12 Apr 2019 10:57:59 +0000 (11:57 +0100)]
Copy prerequisite file for "tiny" printf implementation

Use newlib/libc/stdio/nano-vfprintf.c as baseline for tiny-printf.c

5 years agoFix definition of write() to use const char * for the type of the buffer
Jozef Lawrynowicz [Fri, 12 Apr 2019 10:49:11 +0000 (11:49 +0100)]
Fix definition of write() to use const char * for the type of the buffer

5 years agoCygwin: use win pid+threadid for forkables dirname
Michael Haubenwallner [Fri, 12 Apr 2019 13:32:56 +0000 (15:32 +0200)]
Cygwin: use win pid+threadid for forkables dirname

Rather than newest last write time of all dlls loaded, use the forking
process' windows pid and windows thread id as directory name to create
the forkable hardlinks into.  While this may create hardlinks more
often, it does avoid conflicts between dlls not having the newest last
write time.

5 years agoAlign comments and spaces in libgloss/arm/crt0.S and newlib/libc/sys/arm/crt0.S to...
Alexander Fedotov [Thu, 11 Apr 2019 12:28:05 +0000 (15:28 +0300)]
Align comments and spaces in libgloss/arm/crt0.S and newlib/libc/sys/arm/crt0.S to ease further code alignment.

5 years agoInclude code in trap.S for APCS only.
Christophe Lyon [Wed, 10 Apr 2019 15:04:13 +0000 (15:04 +0000)]
Include code in trap.S for APCS only.

The code in trap.S is to support the old APCS chunked stack variant,
which dates back to the Acorn days, so put it under #ifndef
__ARM_EABI__.

* libgloss/arm/trap.S: Use __ARM_EABI rather than PREFER_THUMB.
* newlib/libc/sys/arm/trap.S: Use __ARM_EABI rather than
__thumb2__.

5 years agoMake more macro checks ARMv8-M baseline proof.
Christophe Lyon [Mon, 1 Apr 2019 17:30:53 +0000 (17:30 +0000)]
Make more macro checks ARMv8-M baseline proof.

Commit 69f4c4029183fb26d2fcae00790881620c1978a3 improved most
macro checks to be ARMv8-M baseline proof, but missed a few
occurrences which otherwise fail to build when using a CPU setting
such as cortex-m0 or cortex-m23. This patch brings the same
changes as the ones that were committed to libgloss at that time.

newlib:
* libc/sys/arm/crt0.S: Use THUMB1_ONLY rather than
__ARM_ARCH_6M__.

5 years agoImprove error handling in /proc/[pid]/ virtual files.
Erik M. Bray [Wed, 10 Apr 2019 15:05:22 +0000 (17:05 +0200)]
Improve error handling in /proc/[pid]/ virtual files.

* Changes error handling to allow /proc/[pid]/ virtual files to be
  empty in some cases (in this case the file's formatter should return
  -1 upon error, not 0).

* Better error handling of /proc/[pid]/stat for zombie processes:
  previously trying to open this file on zombie processes resulted
  in an EINVAL being returned by open().  Now the file can be read,
  and fields that can no longer be read are just zeroed.

* Similarly for /proc/[pid]/statm for zombie processes.

* Similarly for /proc/[pid]/maps for zombie processes (in this case the
  file can be read but is zero-length, which is consistent with observed
  behavior on Linux.

5 years agoCygwin: add latest signal handling fixes to release notes
Corinna Vinschen [Sat, 6 Apr 2019 16:03:22 +0000 (18:03 +0200)]
Cygwin: add latest signal handling fixes to release notes

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: signals: setcontext: fix setting sigmask
Corinna Vinschen [Fri, 5 Apr 2019 10:13:44 +0000 (12:13 +0200)]
Cygwin: signals: setcontext: fix setting sigmask

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: follow context if changed inside SA_SIGINFO signal handler
Corinna Vinschen [Fri, 5 Apr 2019 09:25:19 +0000 (11:25 +0200)]
Cygwin: follow context if changed inside SA_SIGINFO signal handler

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: signals: make setcontext work from signal handlers
Corinna Vinschen [Thu, 4 Apr 2019 19:25:47 +0000 (21:25 +0200)]
Cygwin: signals:  make setcontext work from signal handlers

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: console: fix key input for native console application
Takashi Yano [Wed, 3 Apr 2019 16:25:31 +0000 (01:25 +0900)]
Cygwin: console: fix key input for native console application

- After 24 bit color support patch, arrow keys and function keys
  do not work properly in native console applications if they
  are started in cygwin console. This patch fixes this issue.

5 years agoCygwin: signals: restore sigmask from context given to signal handler
Corinna Vinschen [Wed, 3 Apr 2019 16:14:30 +0000 (18:14 +0200)]
Cygwin: signals: restore sigmask from context given to signal handler

In case SA_SIGINFO flag is given, the signal handler may change
the context and the application is supposed to pick up from the
changed context.  So far we don't do that, so the context given
to the signal handler is basically read-only, unless the signal
handler calls setcontext or swapcontext.

For a start, restore the thread's signal mask from the uc_sigmask
value of the context given to the signal handler.

If that's feasible for Cygwin, we restore the entire context from
the context changed by the signal handler in a followup patch.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoAdd a dummy interrupt handler to nios2 crt0.s.
Sandra Loosemore [Wed, 3 Apr 2019 15:59:36 +0000 (09:59 -0600)]
Add a dummy interrupt handler to nios2 crt0.s.

The location of the handler at offset 0x20 from the start of memory,
immediately after the 32-byte reset vector, matches the expectations
of real hardware (e.g., a 3c120 board).

5 years agoCygwin: winpids: Fix getting process multiple times, take 2
Corinna Vinschen [Tue, 2 Apr 2019 11:00:22 +0000 (13:00 +0200)]
Cygwin: winpids: Fix getting process multiple times, take 2

commit d1be0a59d48222d8ea6261ee3e59de2bc3d149e4,
"Cygwin: winpids: Fix getting process multiple times"
fixed duplicate processes in ps -W output, but it fixed
the symptom, not the cause.  It also didn't fix the problem
that the `ps' process itself may show up twice in its own
output.

This patch fixes it.  The spawn worker only deleted the
"winpid.PID" symlink of the current process if the child is
a non-Cygwin process, under the assumption that the exec'ing
process exits anyway.  However, the Window in which both
winpid.PID symlinks point to the same cygpid.PID area is just
too long.  The spawn worker now also deletes its own winpid.PID
symlink if the exec'ed process is a Cygwin process.

Additionally the fix from d1be0a59d48222d8ea6261ee3e59de2bc3d149e4
is now performed on the calling process, too.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Add console patches to release notes
Corinna Vinschen [Sun, 31 Mar 2019 17:36:23 +0000 (19:36 +0200)]
Cygwin: Add console patches to release notes

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: console: Make I/O functions thread-safe
Takashi Yano [Sun, 31 Mar 2019 15:47:48 +0000 (00:47 +0900)]
Cygwin: console: Make I/O functions thread-safe

- POSIX states I/O functions shall be thread-safe, however, cygwin
  console I/O functions were not. This patch makes console I/O
  functions thread-safe.

5 years agoCygwin: console: fix select() behaviour
Takashi Yano [Sun, 31 Mar 2019 15:47:47 +0000 (00:47 +0900)]
Cygwin: console: fix select() behaviour

- Previously, select() would return when only one key is typed even
  in canonical mode. With this patch, it returns after one line is
  completed.

5 years agoCygwin: console: support 24 bit color
Takashi Yano [Sun, 31 Mar 2019 15:47:46 +0000 (00:47 +0900)]
Cygwin: console: support 24 bit color

- Add 24 bit color support using xterm compatibility mode in
  Windows 10 1703 or later.
- Add fake 24 bit color support for legacy console, which uses
  the nearest color from 16 system colors.

5 years agoCygwin: document ps -W duplication bug fix
Corinna Vinschen [Sun, 31 Mar 2019 10:49:26 +0000 (12:49 +0200)]
Cygwin: document ps -W duplication bug fix

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: [gs]et_io_handle(): renamed to [gs]et_handle().
Takashi Yano [Sat, 30 Mar 2019 07:12:02 +0000 (16:12 +0900)]
Cygwin: [gs]et_io_handle(): renamed to [gs]et_handle().

- Unify get_io_handle() and get_handle() to get_handle().
  Both of them returned same value; io_handle.
- Rename set_io_handle() to set_handle().

5 years agoCygwin: fork: reserve dynloaded dll areas earlier
Michael Haubenwallner [Tue, 26 Mar 2019 16:38:36 +0000 (17:38 +0100)]
Cygwin: fork: reserve dynloaded dll areas earlier

In dll_crt0_0, both threadinterface->Init and sigproc_init allocate
windows object handles using unpredictable memory regions, which may
collide with dynamically loaded dlls when they were relocated.

5 years agoCygwin: FIFO: implement clear_readahead
Ken Brown [Wed, 27 Mar 2019 21:29:21 +0000 (21:29 +0000)]
Cygwin: FIFO: implement clear_readahead

Make fhandler_base::clear_readahead virtual, and implement
fhandler_fifo::clear_readahead.  This is called by
dtable::fixup_after_exec; it clears the readahead in each client.

5 years agoCygwin: document the recent FIFO changes
Ken Brown [Wed, 27 Mar 2019 18:10:18 +0000 (18:10 +0000)]
Cygwin: document the recent FIFO changes

5 years agoCygwin: fix: seteuid32() must return EPERM if privileges are not held.
J.H. van de Water [Wed, 27 Mar 2019 16:01:03 +0000 (17:01 +0100)]
Cygwin: fix: seteuid32() must return EPERM if privileges are not held.

Starting w/ the intro of S4U, seteuid32() calls lsaprivkeyauth(), then
s4uauth(). s4uauth calls LsaRegisterLogonProcess().
LsaRegisterLogonProcess fails w/ STATUS_PORT_CONNECTION_REFUSED, if the
proper privileges are not held.
Because of RtlNtStatusToDosError(), this status would be mapped to
ERROR_ACCESS_DENIED, which in turn would map to EACCES. Therefore it is
useless to add this status to errmap[] (errno.cc), as s4auauth() should
return EPERM as errno here (i.e. if process is not privileged).

Hence the kludge.

Before the intro of S4U, seteuid32() called lsaprivkeyauth(), then
lsaauth(), then create_token(). Before the intro of Vista, the latter
would have called NtCreateToken().
NtCreateToken() would have failed w/ STATUS_PRIVILEGE_NOT_HELD for a
process w/o the proper privileges. In that case, calling seteuid32()
would have returned EPERM (as required).

Since the intro of Vista, and if the process had been started from an
UNelevated shell, create_token() does NOT reach NtCreateToken()!
As create_token() failed to properly set errno in that case, calling
seteuid32() would return errno as set by lsaauth(), i.e. EACCES, not
in agreement w/ Posix (a bug which was present for years).
(lsaauth() called LsaRegisterLogonProcess() which would fail)

5 years agoCygwin: FIFO: add support for the duplex case
Ken Brown [Mon, 25 Mar 2019 23:06:10 +0000 (23:06 +0000)]
Cygwin: FIFO: add support for the duplex case

If a FIFO is opened with O_RDWR access, create the pipe with
read/write access, and make the first client have the handle of that
pipe as its I/O handle.

Adjust fhandler_fifo::raw_read to account for the result of trying to
read from that client if there's no data.

5 years agoCygwin: FIFO: avoid crashes when cloning a client
Ken Brown [Mon, 25 Mar 2019 23:06:09 +0000 (23:06 +0000)]
Cygwin: FIFO: avoid crashes when cloning a client

fhandler_fifo::clone called fhandler_base::clone on each client
fhandler.  But those fhandlers are actually fhandler_fifo objects, so
when fhandler_base::clone calls copyto, it's actually
fhandler_fifo::copyto that gets called.  This can lead to mysterious
crashes.

Fix this by simply calling clone (which translates to
fhandler_fifo::clone) on each client fhandler.

5 years agoCygwin: FIFO: update select
Ken Brown [Fri, 22 Mar 2019 19:30:41 +0000 (19:30 +0000)]
Cygwin: FIFO: update select

Add static functions peek_fifo, thread_fifo, start_thread_fifo, and
fifo_cleanup to select.cc.  These are based on the corresponding pipe
functions, the main difference being that peek_fifo loops through the
connected clients to see if any of them have data available for
reading.

Add the fhandler_fifo methods select_read, select_write, and
select_except.

Add accessor methods get_nclients, get_handle, and is_connected that
are needed by peek_fifo.

5 years agoCygwin: FIFO: update set_close_on_exec
Ken Brown [Fri, 22 Mar 2019 19:30:40 +0000 (19:30 +0000)]
Cygwin: FIFO: update set_close_on_exec

Deal with each client.

5 years agoCygwin: FIFO: update fixup_after_fork
Ken Brown [Fri, 22 Mar 2019 19:30:40 +0000 (19:30 +0000)]
Cygwin: FIFO: update fixup_after_fork

Fixup each client.  Reset listen_client_thr and lct_termination_evt.

5 years agoCygwin: FIFO: update clone and dup
Ken Brown [Fri, 22 Mar 2019 19:30:39 +0000 (19:30 +0000)]
Cygwin: FIFO: update clone and dup

Deal with all clients.

5 years agoCygwin: FIFO: improve EOF detection
Ken Brown [Fri, 22 Mar 2019 19:30:38 +0000 (19:30 +0000)]
Cygwin: FIFO: improve EOF detection

Add a hit_eof method that tries to detect whether any clients are
connected.  Before concluding that there are none, it gives the
listen_client thread time to update the client data.

5 years agoCygwin: FIFO: add a spinlock
Ken Brown [Fri, 22 Mar 2019 19:30:38 +0000 (19:30 +0000)]
Cygwin: FIFO: add a spinlock

Don't let listen_client_thread and raw_read access the client list
simultaneously.

5 years agoCygwin: FIFO: allow multiple writers
Ken Brown [Fri, 22 Mar 2019 19:30:37 +0000 (19:30 +0000)]
Cygwin: FIFO: allow multiple writers

Introduce a 'fifo_client_handler' structure that can be used by a
reader to communicate with a writer using an instance of the named
pipe.  An fhandler_fifo opened for reading creates a thread that does
the following:

 - maintains a list of fifo_client_handlers
 - listens for_clients trying to connect
 - creates new pipe instances as needed so that there's always at
   least one available for connecting.

The pipe instances are initially created in blocking mode, but they
are set to be non-blocking after a connection is made.

fhandler_fifo::raw_read now loops through the connected clients and
reads from the first one that has data available.

New fhandler_fifo methods: add_client, listen_client,
listen_client_thread, check_listen_client_thread.

Replace the create_pipe method by create_pipe_instance, which allows
unlimited pipe instances.

New helper functions: create_event, set_pipe_non_blocking.

5 years agoCygwin: FIFO: stop using overlapped I/O
Ken Brown [Fri, 22 Mar 2019 19:30:36 +0000 (19:30 +0000)]
Cygwin: FIFO: stop using overlapped I/O

Make fhandler_fifo a derived class of fhandler_base instead of
fhandler_base_overlapped.

Replace the create_pipe macro, which is based on
fhandler_pipe::create, by new create_pipe and open_pipe methods.
These use NT functions instead of Win32 functions.  Replace fifo_name
by get_pipe_name, which returns a pointer to a UNICODE_STRING.

Remove the fnevent macro, which would now be needed only once.

Add a raw_write method, adapted from fhandler_base::raw_write.

Adapt all functions to the changes above.

5 years agoCygwin: Bump DLL version to 3.1
Corinna Vinschen [Wed, 27 Mar 2019 13:01:17 +0000 (14:01 +0100)]
Cygwin: Bump DLL version to 3.1

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: winpids: Fix getting process multiple times
Corinna Vinschen [Wed, 27 Mar 2019 12:53:32 +0000 (13:53 +0100)]
Cygwin: winpids: Fix getting process multiple times

Switching to Cywin-only PIDs introduced a new problem when collecting
Cygwin processes for `ps -W': A process can show up multiple times
again, if the Cygwin procinfo has been opened for a just execing
process.  The execed process then shows up twice, once as Cygwin
process, but with the wrong Windows PID of the execing process,
once as Windows-only process.

The mechanism used to exclude these stray processes didn't work with
the new Cygwin pid handling anymore.  To fix this

* check if the incoming Windows PID is the same as the PID in the
  procinfo.  If not, we have the PID of the execing process while
  procinfo was already changed,
* always check if the process has already been handled, not only
  for processes we got a procinfo for,
* simplify adding pid to pidlist since pid is now always correct.

While at it, fix comments and comment formatting.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoAdd missing includes.
Andrew Stubbs [Mon, 25 Mar 2019 15:33:53 +0000 (15:33 +0000)]
Add missing includes.

These missing includes were causing build warnings, but also a real bug in
which the "size" parameter to "write" was being passed in 32-bit, whereas it
ought to be 64-bit.  This led to intermittent bad behaviour.

5 years agoget and convert boot time once and use as needed
Brian Inglis [Sun, 24 Mar 2019 02:22:39 +0000 (20:22 -0600)]
get and convert boot time once and use as needed

5 years agodefault ps -W process start time to system boot time when inaccessible, 0, -1
Brian Inglis [Sun, 24 Mar 2019 02:22:38 +0000 (20:22 -0600)]
default ps -W process start time to system boot time when inaccessible, 0, -1

5 years agoCygwin: ctrl_c_handler: Use 64 bit timer
Corinna Vinschen [Sun, 24 Mar 2019 21:13:00 +0000 (22:13 +0100)]
Cygwin: ctrl_c_handler: Use 64 bit timer

Just don't use GetTickCount for obvious reasons

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: sys/cygwin.h: fix formatting
Corinna Vinschen [Sat, 23 Mar 2019 16:50:47 +0000 (17:50 +0100)]
Cygwin: sys/cygwin.h: fix formatting

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: strace: print windows and cygwin pid in event output
Corinna Vinschen [Sat, 23 Mar 2019 16:50:00 +0000 (17:50 +0100)]
Cygwin: strace: print windows and cygwin pid in event output

strace only printed the Windows PID in event output so far.

Especially now that Windows and Cygwin PID are decoupled, the
strace user might like to see the Cygwin pid in event output as
well.  However, at process startup, the process might not have
a Cygwin PID yet.

To mitigate this, always print the Windows PID and only add the
Cygwin pid if it exists.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: wcsxfrm_l: Only byte swap if dest size is > 0
Corinna Vinschen [Tue, 19 Mar 2019 19:56:11 +0000 (20:56 +0100)]
Cygwin: wcsxfrm_l: Only byte swap if dest size is > 0

commit c0d7d3e1a2fa96db15613cbd68a68c96966bc402 removed the usage of the
LCMAP_BYTEREV flag in the call to LCMapStringW to workaround a strange
bug in LCMapStringW.  This patch didn't take a userspace call of
wcsxfrm{_l} with NULL buffer and 0 size to evaluate the required buffer
size into account.  This introduced a crash trying to byte swap the
NULL buffer.  This patch fixes that problem.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoAMD GCN: Implement circular buffering.
Andrew Stubbs [Mon, 18 Mar 2019 16:18:09 +0000 (16:18 +0000)]
AMD GCN: Implement circular buffering.

The GCN port outputs stdout and stderr via a shared-memory interface.
Previously the buffer was limited to 1000 write operations, which was enough
for testing purposes, but easy to exhaust.

This patch implements a new circular buffering system allowing a greater
amount of output.  The interface must allow hundreds of hardware threads to
output simultaneously.  The new limit is UINT32_MAX write operations.

Unfortunately, there's no way to tell if the host side has also been updated.
This code will misbehave unless the gcn-run from GCC is also updated (although
it's fine the other way around), but that patch has already been committed.

OK?

Andrew Stubbs
Mentor Graphics / CodeSourcery

5 years agoCygwin: proc: fix /proc/version output after uname change
Corinna Vinschen [Mon, 18 Mar 2019 10:34:00 +0000 (11:34 +0100)]
Cygwin: proc: fix /proc/version output after uname change

3.0.0 changed uname but missed to align /proc/version
which then used the old uname function on the new uname
struct.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: bump version to 3.0.5
Corinna Vinschen [Mon, 18 Mar 2019 10:29:00 +0000 (11:29 +0100)]
Cygwin: bump version to 3.0.5

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoAdd semihosting docs for nios2 and m68k cygwin-3_0_4-release
Jeff Johnston [Thu, 14 Mar 2019 14:23:25 +0000 (10:23 -0400)]
Add semihosting docs for nios2 and m68k

Author: Sandra Loosemore <sandra@codesourcery.com>
Date:   Wed Mar 13 20:22:16 2019 -0700

    Add semihosting documentation for nios2 and m68k.

    QEMU maintainers have asked for a specification of the nios2
    semihosting interface.  Since it's essentially a copy of the m68k
    implementation, this patch adds a document for that target as well.

5 years agoCygwin: acls: allow converting empty acl to text
Corinna Vinschen [Wed, 13 Mar 2019 11:06:48 +0000 (12:06 +0100)]
Cygwin: acls: allow converting empty acl to text

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: proc: add missing LF to /proc/<PID>/stat output
Corinna Vinschen [Wed, 13 Mar 2019 10:26:58 +0000 (11:26 +0100)]
Cygwin: proc: add missing LF to /proc/<PID>/stat output

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: ps: simplify code
Corinna Vinschen [Tue, 12 Mar 2019 20:21:13 +0000 (21:21 +0100)]
Cygwin: ps: simplify code

Always use NtQuerySystemInformation(SystemProcessIdInformation).
This drops two code paths calling NtQueryInformationProcess or
GetModuleFileNameExW and only requires to open the process
to fetch system time info.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: ps: show *all* processes in ps -W output
Corinna Vinschen [Tue, 12 Mar 2019 19:55:24 +0000 (20:55 +0100)]
Cygwin: ps: show *all* processes in ps -W output

There's a long-standing bug in ps -W.  It only shows processes which ps
can open with PROCESS_QUERY_LIMITED_INFORMATION permissions.  However,
that fails for a lot of system processes. Due to that, output is
basically restricted to processes in the same session, as well as Cygwin
processes... which isn't *quite* what ps -W was supposed to do.

Basically we only need to open the process to fetch the image name.  If
that fails, utilize the undocumented SystemProcessIdInformation info
class introduced with Windows Vista, which allows to fetch the image
name by specifying the PID.  Restructure the code a bit.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: ntdll.h: Add SystemProcessIdInformation
Corinna Vinschen [Tue, 12 Mar 2019 19:11:38 +0000 (20:11 +0100)]
Cygwin: ntdll.h: Add SystemProcessIdInformation

Add SystemProcessIdInformation to SYSTEM_INFORMATION_CLASS
and define struct _SYSTEM_PROCESS_ID_INFORMATION.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: loadavg: improve debugging of load_init
Corinna Vinschen [Tue, 12 Mar 2019 16:09:42 +0000 (17:09 +0100)]
Cygwin: loadavg: improve debugging of load_init

When logging in via ssh with an unprivileged account,
PdhAddEnglishCounter returns with status 0x800007D0,
PDH_CSTATUS_NO_MACHINE.  We didn't find any workaround
but the changes to improve debugging output may help
in future.  Using UNICODE instead of ANSI functions is
a result of trying to fix this problem.

Also drop the prototype workaround for PdhAddEnglishCounterA.
It's not required anymore since Mingw-w64's pdh.h catched up.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: add /proc changes to release notes
Corinna Vinschen [Tue, 12 Mar 2019 10:47:31 +0000 (11:47 +0100)]
Cygwin: add /proc changes to release notes

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: fork/exec: Allow all users PROCESS_QUERY_LIMITED_INFORMATION
Corinna Vinschen [Tue, 12 Mar 2019 10:41:35 +0000 (11:41 +0100)]
Cygwin: fork/exec: Allow all users PROCESS_QUERY_LIMITED_INFORMATION

Create process with standard rights, plus
PROCESS_QUERY_LIMITED_INFORMATION for authenticated users.  This
allows to fetch basic process information and thus /proc/<PID>/stat
to succeed on foreign processes.

While at it, fix formatting in CreateProcess calls.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: proc: let stat info always succeed
Corinna Vinschen [Tue, 12 Mar 2019 10:34:50 +0000 (11:34 +0100)]
Cygwin: proc: let stat info always succeed

There's no good reason to return blank if some of the info
couldn't be collected.  Drop useless call collecting
SystemProcessorPerformanceInformation.  Always return some
valid start_time, even if we couldn't collect ProcessTimes.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: proc: don't request PROCESS_VM_READ perms for stat
Corinna Vinschen [Tue, 12 Mar 2019 10:20:42 +0000 (11:20 +0100)]
Cygwin: proc: don't request PROCESS_VM_READ perms for stat

The OpenProcess call to generate /proc/<PID>/stat info requests
PROCESS_VM_READ, but that's not required.  Drop it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: proc: return more useful cmdline
Corinna Vinschen [Tue, 12 Mar 2019 10:17:11 +0000 (11:17 +0100)]
Cygwin: proc: return more useful cmdline

Creating /proc/<PID>/cmdline requires permissions to communicate
with the target process via its signal pipe.  If that fails, the
output is "<defunct>" which doesn't make sense most of the time.
Rather, call format_process_exename in this case to get more useful
process name info, albeit not the full cmdline.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: fix permissions of winpid symlinks
Corinna Vinschen [Mon, 11 Mar 2019 20:40:04 +0000 (21:40 +0100)]
Cygwin: fix permissions of winpid symlinks

The winpid symlinks got created with no query permissions, so
only admins could see all Cygwin processes.  Create symlinks
so everyone has query permissions instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: bump version to 3.0.4
Corinna Vinschen [Sat, 9 Mar 2019 19:13:50 +0000 (20:13 +0100)]
Cygwin: bump version to 3.0.4

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: posix timers: fix a deadlock cygwin-3_0_3-release
Corinna Vinschen [Fri, 8 Mar 2019 11:51:10 +0000 (12:51 +0100)]
Cygwin: posix timers: fix a deadlock

Canceling the timer thread runs under lock.  The thread uses the same
lock to guard its timer_tracker struct access.  If the timing is bad,
timer_settime or timer_delete grab the lock at the same time, the timer
expires.  In the end, cancel waits for the thread sync while the thread
waits for ther lock to be released.

Fix this by not waiting for the thread sync under lock.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: posix timers: fix resource leak
Corinna Vinschen [Wed, 6 Mar 2019 21:17:32 +0000 (22:17 +0100)]
Cygwin: posix timers: fix resource leak

On setting the timer, the thread is accidentally only canceled when
disarming the timer.  This leaks one thread per timer_settimer call.
Move the thread cancellation where it belongs.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: bump version to 3.0.3
Corinna Vinschen [Tue, 5 Mar 2019 19:00:30 +0000 (20:00 +0100)]
Cygwin: bump version to 3.0.3

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: seteuid: do not verify lsaprivkeyauth token cygwin-3_0_2-release
Corinna Vinschen [Mon, 4 Mar 2019 19:30:37 +0000 (20:30 +0100)]
Cygwin: seteuid: do not verify lsaprivkeyauth token

We don't support setting groups via /etc/groups anymore.  Also, the
initgroups group list is created via S4U, so we have "Interactive" vs.
"Network" token, an artificial and entirely irrelevant difference.

So,  "verifying" the lsaprivkeyauth token may lead to rejecting a prefectly
valid token.  Just remove the verify_token call.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoRevert "Cygwin: load_user_profile: temporarily extend debug output"
Corinna Vinschen [Mon, 4 Mar 2019 13:58:45 +0000 (14:58 +0100)]
Revert "Cygwin: load_user_profile: temporarily extend debug output"

This reverts commit 6aef5a46d7f22841e6a859103bb3f8acea060b84.

5 years agoCygwin: Revert attempting to unload user profile after use
Corinna Vinschen [Mon, 4 Mar 2019 16:07:31 +0000 (17:07 +0100)]
Cygwin: Revert attempting to unload user profile after use

Revert "Cywin: user profile: unload impersonation user profile on exit"
Revert "Cygwin: seteuid: allow inheriting impersonation user profile handle"
Revert "Cygwin: user profile: add debug output to unload_user_profile"
Revert "Cygwin: user profile: Make an effort to unload unused user profiles"

This reverts commit bcb33dc4f0552e749dcb6c44e1ef7815b5db75a1.
This reverts commit dd3730ed9c1c78176f1aab1b429bb5a105d90a44.
This reverts commit 8eee25241e86fc596acde25c7c53723b75afee30.
This reverts commit 71b8777a7140b79942d6e5079818cad2c3f5f07f.

This patchset actually results in the following problem:

- After a couple of ssh logon/logoff attempts, an interactive session
  of the same user loging in, is broken.

Apparently UnloadUserProfile manages to unload the user's profile
even while a parallel interactive session still uses the user's
profile.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: update 3.0.2 release file
Corinna Vinschen [Mon, 4 Mar 2019 13:14:15 +0000 (14:14 +0100)]
Cygwin: update 3.0.2 release file

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: doc: update case-sensitive dirs description
Corinna Vinschen [Mon, 4 Mar 2019 13:03:32 +0000 (14:03 +0100)]
Cygwin: doc: update case-sensitive dirs description

Since we have to disable automatic case-sensitive mkdir again,
change documentation accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: fork: fix child process permissions, take 3
Corinna Vinschen [Sun, 3 Mar 2019 09:59:13 +0000 (10:59 +0100)]
Cygwin: fork: fix child process permissions, take 3

Per MSDN VirtualQueryEx requires PROCESS_QUERY_INFORMATION.
Testing showed that PROCESS_QUERY_LIMITED_INFORMATION is sufficient
since Windows 8.1.  The assumption that Windows 8 is the same as
Windows 8 was not correct, it requires PROCESS_QUERY_INFORMATION
as well.

Fix that by splitting the Windows 8 wincaps into one for Windows 8
and one for Windows 8.1.  Set needs_query_information for Windows 8.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: load_user_profile: Don't give primary domain to ldap
Corinna Vinschen [Sat, 2 Mar 2019 11:47:54 +0000 (12:47 +0100)]
Cygwin: load_user_profile: Don't give primary domain to ldap

If the user domain is the primary domain, LDAP is supposed to
use the default naming context.  This is accomplished by setting
domain name to NULL in the call to cyg_ldap::fetch_ad_account.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: ldap: Fix overwriting domain when creating naming context
Corinna Vinschen [Sat, 2 Mar 2019 11:43:34 +0000 (12:43 +0100)]
Cygwin: ldap: Fix overwriting domain when creating naming context

cyg_ldap::fetch_ad_account creates a naming context from the
incoming domain, if it's not NULL.  The algorithm overwrites
dots with \0 in domain while creating the naming context, but
neglects to restore the dots.

Fix that by never overwriting the incoming domain name.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: fenv.h: Add feature test macros, fix values
Corinna Vinschen [Thu, 28 Feb 2019 14:05:13 +0000 (15:05 +0100)]
Cygwin: fenv.h: Add feature test macros, fix values

- feenableexcept,fedisableexcept, fegetexcept are GNU-only
- fegetprec, fesetprec are Solaris, use __MISC_VISIBLE
- _feinitialise is Cygwin-internal only
- Replace self-named FP precision values to values from
  http://www.open-std.org/jtc1/sc22//WG14/www/docs/n752.htm
  as used by Solaris.
- Change return value of fesetprec to adhere to the above document
  and Solaris.
- Document fegetprec, fesetprec as Solaris functions, not as GNU
  functions

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: authentication: Always initialize domain info
Corinna Vinschen [Fri, 1 Mar 2019 20:08:09 +0000 (21:08 +0100)]
Cygwin: authentication: Always initialize domain info

...before calling any of its method.  It's no safe bet that
it's already initialized when calling s4uauth and adding it
to load_user_profile certainly doesn't hurt.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: load_user_profile: use local pointer when appropriate
Corinna Vinschen [Fri, 1 Mar 2019 20:05:23 +0000 (21:05 +0100)]
Cygwin: load_user_profile: use local pointer when appropriate

dnsdomain does not have to be a copy of the domain, a pointer into
cygheap is sufficient.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: load_user_profile: fix use-after-free issue
Corinna Vinschen [Fri, 1 Mar 2019 20:04:02 +0000 (21:04 +0100)]
Cygwin: load_user_profile: fix use-after-free issue

In case of a local machine account login, pi.lpProfilePath points
to the buffer returned by NetUserGetInfo, but NetApiBufferFree
is called prior to calling LoadUserProfileW.  Fix by copying over
usri3_profile to the local userpath buffer, just as in the AD case.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This page took 0.072774 seconds and 5 git commands to generate.