]> sourceware.org Git - newlib-cygwin.git/log
newlib-cygwin.git
2 years agoCygwin: pty: Fix handle leak regarding attach_mutex.
Takashi Yano [Sun, 10 Oct 2021 00:49:53 +0000 (09:49 +0900)]
Cygwin: pty: Fix handle leak regarding attach_mutex.

- If the process having master pty opened is forked, attach_mutex
  fails to be closed when master is closed. This patch fixes the
  issue.

2 years agoCygwin: pty: Fix master closing error regarding attach_mutex.
Takashi Yano [Fri, 8 Oct 2021 16:28:54 +0000 (01:28 +0900)]
Cygwin: pty: Fix master closing error regarding attach_mutex.

- If two or more pty masters are opened in a process, closing master
  causes error when closing attach_mutex. This patch fixes the issue.

Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-October/012418.html

2 years agosys/tree.h: Red child with black sibling rotations
Sebastian Huber [Tue, 5 Oct 2021 13:53:47 +0000 (15:53 +0200)]
sys/tree.h: Red child with black sibling rotations

Add specialized rotations RB_RED_ROTATE_LEFT() and RB_RED_ROTATE_RIGHT() which
may be used if we rotate a red child which has a black sibling.  Such a red
node must have at least two child nodes so that the following red-black tree
invariant is fulfilled:

  Every path from a given node to any of its descendant NULL nodes goes through
  the same number of black nodes.

      PARENT
     /      \
  BLACK     RED
           /   \
        BLACK BLACK

2 years agosys/tree.h: Add parent rotations
Sebastian Huber [Tue, 5 Oct 2021 13:43:34 +0000 (15:43 +0200)]
sys/tree.h: Add parent rotations

Add specialized rotations RB_PARENT_ROTATE_LEFT() and RB_PARENT_ROTATE_RIGHT()
which may be used if the parent node exists and the direction of the child is
known.  The specialized rotations are derived from RB_ROTATE_LEFT() and
RB_ROTATE_RIGHT() where the RB_SWAP_CHILD() was replaced by a simple
assignment.

2 years agosys/tree.h: Simplify chain of conditions
Sebastian Huber [Tue, 5 Oct 2021 13:39:10 +0000 (15:39 +0200)]
sys/tree.h: Simplify chain of conditions

In RB_GENERATE_REMOVE_COLOR() simplify a chain of conditions of the following
pattern

if (x) {
  ...
} else if (!x) {
  ...
}

to

if (x) {
  ...
} else {
  ...
}

2 years agosys/tree.h: Simplify loop condition
Sebastian Huber [Tue, 5 Oct 2021 13:31:22 +0000 (15:31 +0200)]
sys/tree.h: Simplify loop condition

We have

  #define RB_ISRED(elm, field) \
    ((elm) != NULL && RB_COLOR(elm, field) == RB_RED)

So, the RB_ISRED() contains an implicit check for NULL.  In
RB_GENERATE_REMOVE_COLOR() the "elm" pointer cannot be NULL in the while
condition.  Use RB_COLOR(elm) == RB_BLACK instead.

2 years agoCygwin: pipe: Use ProcessHandleInformation if available.
Takashi Yano [Thu, 23 Sep 2021 14:33:55 +0000 (23:33 +0900)]
Cygwin: pipe: Use ProcessHandleInformation if available.

- The commit b531d6b0 introduced temporary_query_hdl() which uses
  SystemHandleInformation. With this patch, ProcessHandleInformation
  rather than SystemHandleInformation is used if it is available.
  This request is faster, however, is only available since Windows 8,
  therefore, SystemHandleInformation is used for Windows Vista and 7
  as before.

2 years agoCygwin: pipe: Introduce temporary query_hdl.
Takashi Yano [Mon, 20 Sep 2021 23:02:43 +0000 (08:02 +0900)]
Cygwin: pipe: Introduce temporary query_hdl.

- The commit f79a4611 introduced query_hdl, which is the read pipe
  handle kept in the write pipe instance in order to determine if
  the pipe is ready to write in select().  This implementation has
  a potential risk that the write side fails to detect the closure
  of the read side if more than one writer exists and one of them
  is a non-cygwin process.

  With this patch, the strategy of commit f79a4611 is used only if
  the process is running as a service.  For a normal process,
  instead of keeping query_hdl in the write pipe instance, it is
  retrieved temporarily when select() is called.  Actually, we
  want to use tenporary query_hdl for all processes, however, it
  does not work for service processes due to OpenProcess()
  failure.

2 years agoCygwin: pipes: remove unnecessary NULL checks for hdl_cnt_mtx
Ken Brown [Sat, 18 Sep 2021 13:25:20 +0000 (09:25 -0400)]
Cygwin: pipes: remove unnecessary NULL checks for hdl_cnt_mtx

In view of the previous changes to open_setup, we can always assume
that hdl_cnt_mtx is non-NULL.

2 years agoCygwin: make callers of open_setup check for failure
Ken Brown [Sat, 18 Sep 2021 13:10:23 +0000 (09:10 -0400)]
Cygwin: make callers of open_setup check for failure

open_setup is called by dtable::init_std_file_from_handle and
fhandler_base::open_with_arch.  In both cases, failure of open_setup
is now a fatal error.

Currently this can only happen in the following situation: A Cygwin
process is started by a non-Cygwin process, one of the standard IO
handles is a pipe handle, and Cygwin is unable to create a required
mutex (read_mtx or hdl_cnt_mtx).

2 years agoCygwin: fhandler_pipe::open_setup: fail on error creating mutexes
Ken Brown [Sat, 18 Sep 2021 12:34:04 +0000 (08:34 -0400)]
Cygwin: fhandler_pipe::open_setup: fail on error creating mutexes

2 years agoCygwin: allow open_setup to fail
Ken Brown [Sat, 18 Sep 2021 12:13:55 +0000 (08:13 -0400)]
Cygwin: allow open_setup to fail

Convert fhandler_base::open_setup to a (virtual) method that returns a
bool result.  For the moment, it and its overrides always return true.

2 years agoCygwin: statically link the tools in winsup/utils/mingw
Ken Brown [Sat, 18 Sep 2021 01:38:07 +0000 (21:38 -0400)]
Cygwin: statically link the tools in winsup/utils/mingw

This fixes the problem reported here:

  https://cygwin.com/pipermail/cygwin-developers/2021-September/012375.html

2 years agoCygwin: fix typos in release notes
Ken Brown [Fri, 17 Sep 2021 20:16:14 +0000 (16:16 -0400)]
Cygwin: fix typos in release notes

2 years agoCygwin: pipe, fifo: Move query_hdl and hdl_cnt_mtx to fhandler_pipe.
Takashi Yano [Thu, 16 Sep 2021 19:23:12 +0000 (04:23 +0900)]
Cygwin: pipe, fifo: Move query_hdl and hdl_cnt_mtx to fhandler_pipe.

- query_hdl and hdl_cnt_mtx are moved from fhandler_pipe_fifo to
  fhandler_pipe. Then reader_closed() is changed to virtual and
  overridden in fhandler_pipe.

2 years agoCygwin: pipe: Fix race issue regarding handle count.
Takashi Yano [Thu, 16 Sep 2021 14:21:57 +0000 (23:21 +0900)]
Cygwin: pipe: Fix race issue regarding handle count.

- This patch fixes the race issue in the handle counting to detect
  closure of read pipe, which is introduced by commit f79a4611.
  A mutex hdl_cnt_mtx is introduced for this issue.

2 years agoCygwin: pipe: Fix error handling in fhandler_pip::create().
Takashi Yano [Thu, 16 Sep 2021 14:15:17 +0000 (23:15 +0900)]
Cygwin: pipe: Fix error handling in fhandler_pip::create().

- Currently, error handling in fhandler_pipe::create() is broken.
  This patch fixes that.

2 years agoCygwin: close_all_files: Do not duplicate stderr for write pipe.
Takashi Yano [Thu, 16 Sep 2021 11:50:54 +0000 (20:50 +0900)]
Cygwin: close_all_files: Do not duplicate stderr for write pipe.

- Currently, the stderr handle is duplicated in close_all_files().
  This interferes the handle counting for detecting closure of read
  pipe, which is introduced by commit f79a4611. This patch stops
  duplicating stderr handle if it is write pipe.

2 years agoCygwin: select: check for negative return from pipe_data_available
Ken Brown [Wed, 15 Sep 2021 16:56:34 +0000 (12:56 -0400)]
Cygwin: select: check for negative return from pipe_data_available

Make sure except_ready is set (if except_selected) on a negative
return from pipe_data_available.

2 years agonewlib: sig2str: use __restrict
Mike Frysinger [Wed, 15 Sep 2021 05:04:14 +0000 (01:04 -0400)]
newlib: sig2str: use __restrict

This matches the header prototype style and most of newlib, and fixes
building with older versions of gcc which only accept the __ form.

2 years agolibgloss: add missing aclocal.m4 files
Mike Frysinger [Wed, 15 Sep 2021 04:27:13 +0000 (00:27 -0400)]
libgloss: add missing aclocal.m4 files

These subdirs were missing aclocal.m4 files pulling in macros from
../acinclude.m4 which caused some macros to not be expanded.  For
example, autoconf complains:

configure.ac:25: error: possibly undefined macro: LIB_AC_PROG_CC
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.

These were generated with aclocal-1.9 as that seems to be what was
used in these dirs previously, and with whatever version of autoconf
the specific subdir was using.  This should minimize diffs.

2 years agolibgloss: epiphany: rename symbol prefix cache var
Mike Frysinger [Wed, 15 Sep 2021 04:20:58 +0000 (00:20 -0400)]
libgloss: epiphany: rename symbol prefix cache var

Autoconf emits a warning for this:
configure.ac:75: warning: AC_CACHE_VAL(libc_symbol_prefix, ...): suspicious cache-id, must contain _cv_ to be cached

Rename the variable to match the naming in libnosys/ subdir.

2 years agolibgloss: fix AC_LANG_SOURCE warnings w/newer autoconf
Mike Frysinger [Wed, 15 Sep 2021 04:18:55 +0000 (00:18 -0400)]
libgloss: fix AC_LANG_SOURCE warnings w/newer autoconf

When running autoconf-2.69 in here, we get:
configure.ac:57: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2503: _AC_PREPROC_IFELSE is expanded from...
../../lib/autoconf/general.m4:2518: AC_PREPROC_IFELSE is expanded from...
configure.ac:57: the top level
configure.ac:61: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2503: _AC_PREPROC_IFELSE is expanded from...
../../lib/autoconf/general.m4:2518: AC_PREPROC_IFELSE is expanded from...
configure.ac:61: the top level

Add AC_LANG_PROGRAM wrappings to fix these.

2 years agoCygwin: pipes: don't call NtQueryInformationFile on read side of pipes
Corinna Vinschen [Wed, 15 Sep 2021 12:17:59 +0000 (14:17 +0200)]
Cygwin: pipes: don't call NtQueryInformationFile on read side of pipes

NtQueryInformationFile hangs if it's called on the read side handle of
a pipe while another thread or process is performing a blocking read.

Avoid select potentially hanging by calling NtQueryInformationFile
only on the write side of the pipe and using PeekNamedPipe otherwise.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop useless method fhandler_base::has_ongoing_io
Corinna Vinschen [Wed, 15 Sep 2021 11:58:36 +0000 (13:58 +0200)]
Cygwin: drop useless method fhandler_base::has_ongoing_io

This was a remnant of the fhandler_base_overlapped class.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Do not call PeekNamedPipe() if it is not necessary.
Takashi Yano [Wed, 15 Sep 2021 00:55:57 +0000 (09:55 +0900)]
Cygwin: pipe: Do not call PeekNamedPipe() if it is not necessary.

- In pipe_data_available() in select.cc, PeekNamedPipe() call is
  not needed if WriteQuotaAvailable is non-zero because we already
  know the write pipe has a space. Therefore, with this patch,
  PeekNamedPipe() is called only when WriteQuotaAvailable is zero.
  This makes select() on pipe faster a bit.

2 years agoCygwin: document the recent pipe changes
Ken Brown [Tue, 14 Sep 2021 18:59:28 +0000 (14:59 -0400)]
Cygwin: document the recent pipe changes

2 years agoCygwin: pipe: Fix handling of EPIPE and SIGPIPE in raw_write().
Takashi Yano [Tue, 14 Sep 2021 11:59:08 +0000 (20:59 +0900)]
Cygwin: pipe: Fix handling of EPIPE and SIGPIPE in raw_write().

2 years agoCygwin: pipe, fifo: Release select_sem semaphore as much as needed.
Takashi Yano [Tue, 14 Sep 2021 09:50:49 +0000 (18:50 +0900)]
Cygwin: pipe, fifo: Release select_sem semaphore as much as needed.

- Currently, raw_read(), raw_write() and close() release select_sem
  unconditionally even if no waiter for select_sem exists. With this
  patch, only the minimum number of semaphores required is released.

2 years agoCygwin: pipe: Use read pipe handle for select() on write pipe.
Takashi Yano [Tue, 14 Sep 2021 10:10:48 +0000 (19:10 +0900)]
Cygwin: pipe: Use read pipe handle for select() on write pipe.

- Usually WriteQuotaAvailable retrieved by NtQueryInformationFile()
  on the write side reflects the space available in the inbound buffer
  on the read side. However, if a pipe read is currently pending,
  WriteQuotaAvailable on the write side is decremented by the number
  of bytes the read side is requesting. So it's possible (even likely)
  that WriteQuotaAvailable is 0, even if the inbound buffer on the
  read side is not full. This can lead to a deadlock situation:
  The reader is waiting for data, but select on the writer side
  assumes that no space is available in the read side inbound buffer.

  Currently, to avoid this stuation, read() does not request larger
  block than pipe size - 1. However, this mechanism does not take
  effect if the reader side is non-cygwin app.

  The only reliable information is available on the read side, so
  fetch info from the read side via the pipe-specific query handle
  (query_hdl) introduced.

  If the query_hdl (read handle) is kept in write side, writer can
  not detect closure of read pipe. Therefore, raw_write() counts
  write handle and query_hdl. If they are equal, only the pairs of
  write handle and query_hdl are alive. In this case, raw_write()
  returns EPIPE and raises SIGPIPE.

- Nonblocking pipes (PIPE_NOWAIT) are not well handled by non-Cygwin
  tools, so convert pipe handles to PIPE_WAIT handles when spawning
  a non-Cygwin process.

2 years agoCygwin: pipe, fifo: Call set_no_inheritance() for adjunct handles.
Takashi Yano [Tue, 14 Sep 2021 03:49:35 +0000 (12:49 +0900)]
Cygwin: pipe, fifo: Call set_no_inheritance() for adjunct handles.

- Currntly, set_no_inheritance() is not called for the adjunct handles
  such as select_sem. This patch fixes the issue.

2 years agoCygwin: fhandler_base::dup Reflect O_CLOEXEC to inheritance flag.
Takashi Yano [Tue, 14 Sep 2021 03:48:03 +0000 (12:48 +0900)]
Cygwin: fhandler_base::dup Reflect O_CLOEXEC to inheritance flag.

- Currently fhandler_base::dup duplicates handles with bInheritHandle
  TRUE unconditionally. This patch reflects O_CLOEXEC flag to that
  parameter.

2 years agoCygwin: pipes: do not duplicate sec_none{_nih} locally when creating objects
Corinna Vinschen [Mon, 13 Sep 2021 20:02:51 +0000 (22:02 +0200)]
Cygwin: pipes: do not duplicate sec_none{_nih} locally when creating objects

We already fetched the correct SECURITY_ATTRIBUTES at the start of
fhandler_pipe::create, so using another SECURITY_ATTRIBUTES object for
the mutex and semaphore objects doesn't make much sense.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: fix inheritence of select_sem on write side of pipe
Corinna Vinschen [Mon, 13 Sep 2021 17:33:56 +0000 (19:33 +0200)]
Cygwin: fix inheritence of select_sem on write side of pipe

select_sem gets created on the read side with inheritence settings
depending on the O_CLOEXEC flag.  Then it gets duplicated to the write
side with unconditional inheritence.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Fix deadlock if pipe is created by non-cygwin app.
Takashi Yano [Sun, 12 Sep 2021 06:06:05 +0000 (15:06 +0900)]
Cygwin: pipe: Fix deadlock if pipe is created by non-cygwin app.

2 years agoCygwin: fifo: Utilize select_sem for fifo as well as pipe.
Takashi Yano [Thu, 9 Sep 2021 23:43:59 +0000 (08:43 +0900)]
Cygwin: fifo: Utilize select_sem for fifo as well as pipe.

2 years agoCygwin: pipes: always signal select_sem if any bytes are read or written
Corinna Vinschen [Thu, 9 Sep 2021 09:35:54 +0000 (11:35 +0200)]
Cygwin: pipes: always signal select_sem if any bytes are read or written

Fold all code branches potentially having read or written data into
a single if branch, so signalling select_sem catches all cases.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Fix notification timing of select_sem.
Takashi Yano [Thu, 9 Sep 2021 03:08:39 +0000 (12:08 +0900)]
Cygwin: pipe: Fix notification timing of select_sem.

- Make select_sem notify even when read/write partially.

2 years agoCygwin: select: Introduce select_sem semaphore for pipe.
Takashi Yano [Wed, 8 Sep 2021 08:18:35 +0000 (17:18 +0900)]
Cygwin: select: Introduce select_sem semaphore for pipe.

- This patch introduces select_sem semaphore which notifies pipe status
  change.

2 years agoRevert "Cygwin: select: Improve select/poll response."
Takashi Yano [Wed, 8 Sep 2021 10:22:40 +0000 (19:22 +0900)]
Revert "Cygwin: select: Improve select/poll response."

... because this commit (23bb19ef) causes high CPU load.

2 years agoCygwin: set buffer size for pipes created by non-Cygwin processes
Ken Brown [Tue, 7 Sep 2021 21:40:21 +0000 (17:40 -0400)]
Cygwin: set buffer size for pipes created by non-Cygwin processes

Rename fhandler_pipe_and_fifo::max_atomic_write to pipe_buf_size.
This reflect its actual meaning better.  The fhandler_pipe_and_fifo
constructor initializes it to DEFAULT_PIPEBUFSIZE (== 64K), which is
the buffer size for the windows pipes created by fhandler_pipe and
fhandler_fifo.  But if we inherit a stdio pipe handle from a
non-Cygwin process, the buffer size could be different.

To remedy this, add a method fhandler_pipe::set_pipe_buf_size that
queries the OS for the pipe buffer size, and use it in
dtable::init_std_file_from_handle.

2 years agoCygwin: pipes: drop "tiny pipe" handling
Corinna Vinschen [Tue, 7 Sep 2021 10:56:48 +0000 (12:56 +0200)]
Cygwin: pipes: drop "tiny pipe" handling

Given we return 1 already if WriteQuotaAvailable is > 0, the condition
for tiny pipes is never true.  Fix the comments.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: handle signals and thread cancellation in blocking mode only
Corinna Vinschen [Tue, 7 Sep 2021 09:14:09 +0000 (11:14 +0200)]
Cygwin: pipes: handle signals and thread cancellation in blocking mode only

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: always terminate async IO in blocking mode
Corinna Vinschen [Tue, 7 Sep 2021 08:50:47 +0000 (10:50 +0200)]
Cygwin: pipes: always terminate async IO in blocking mode

In blocking mode, the underlying IO must always be terminated,
one way or the other, to make sure the application knows the exact
state after returning from the IO function.  Therefore, always call
CancelIo in blocking mode.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: cancel async IO if thread cancellation is in progress
Corinna Vinschen [Mon, 6 Sep 2021 12:35:05 +0000 (14:35 +0200)]
Cygwin: pipes: cancel async IO if thread cancellation is in progress

Just cancelling a thread doesn't cancel async IO started by this thread.
Fix this by returning from cygwait and calling CancelIo before canceling
self.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Stop counting reader and read all available data.
Takashi Yano [Mon, 6 Sep 2021 11:12:16 +0000 (20:12 +0900)]
Cygwin: pipe: Stop counting reader and read all available data.

- By guarding read with read_mtx, no more than one ReadFile can
  be called simultaneously. So couting read handles is no longer
  necessary.
- Make raw_read code as similar as possible to raw_write code.

2 years agoCygwin: new class fhandler_pipe_fifo
Ken Brown [Fri, 3 Sep 2021 23:41:52 +0000 (19:41 -0400)]
Cygwin: new class fhandler_pipe_fifo

This is a parent of fhandler_pipe and fhandler_fifo for code that is
common between the two classes.  Currently it just contains
max_atomic_write and raw_write().  The latter is identical to what
used to be fhandler_pipe::raw_write().

2 years agoCygwin: FIFO: open pipes with FILE_READ_ATTRIBUTES access
Ken Brown [Fri, 3 Sep 2021 18:23:47 +0000 (14:23 -0400)]
Cygwin: FIFO: open pipes with FILE_READ_ATTRIBUTES access

This is needed by NtQueryInformationFile, which is used by select.

2 years agoCygwin: pipes: minor code cleanup
Ken Brown [Fri, 3 Sep 2021 13:42:00 +0000 (09:42 -0400)]
Cygwin: pipes: minor code cleanup

Clarify a comment in raw_read, and remove a useless line from
raw_write.

2 years agoCygwin: pipes: nt_create: set read handle to NULL in error case
Corinna Vinschen [Fri, 3 Sep 2021 08:59:02 +0000 (10:59 +0200)]
Cygwin: pipes: nt_create: set read handle to NULL in error case

Fix accidentally setting read handle to INVALID_HANDLE_VALUE in a
single error case.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: call nt_create with handle references
Corinna Vinschen [Fri, 3 Sep 2021 08:57:21 +0000 (10:57 +0200)]
Cygwin: pipes: call nt_create with handle references

...to avoid potential pointer mishandling.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: workaround unrelibale system info
Corinna Vinschen [Fri, 3 Sep 2021 08:48:40 +0000 (10:48 +0200)]
Cygwin: pipes: workaround unrelibale system info

FILE_PIPE_LOCAL_INFORMATION::WriteQuotaAvailable is unreliable.

Usually WriteQuotaAvailable on the write side reflects the space
available in the inbound buffer on the read side.  However, if a
pipe read is currently pending, WriteQuotaAvailable on the write side
is decremented by the number of bytes the read side is requesting.
So it's possible (even likely) that WriteQuotaAvailable is 0, even
if the inbound buffer on the read side is not full.  This can lead to
a deadlock situation: The reader is waiting for data, but select
on the writer side assumes that no space is available in the read
side inbound buffer.

This patch implements a workaround by never trying to read more than
half the buffer size blocking if the read buffer is empty.  This first
cut tries to take the number of open readers into account by reducing
the amount of requested bytes accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: fix POSIX requirement for non-blocking pipe writes
Corinna Vinschen [Fri, 3 Sep 2021 08:45:49 +0000 (10:45 +0200)]
Cygwin: pipes: fix POSIX requirement for non-blocking pipe writes

POSIX requires atomicity for non-blocking writes <= PIPE_BUF bytes
and writing of at least 1 byte if any buffer space is left.
Windows NtWriteFile returns STATUS_SUCCESS and "0 bytes written"
if the write doesn't match buffer space.  Fix this discrepancy.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: create pipes with synchronization enabled
Corinna Vinschen [Fri, 3 Sep 2021 08:32:30 +0000 (10:32 +0200)]
Cygwin: pipes: create pipes with synchronization enabled

This isn't used by Cygwin, but it might be used by Win32 processes
inheriting the handle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: use NtClose when file has been opened with an NtXxx function
Corinna Vinschen [Fri, 3 Sep 2021 08:31:27 +0000 (10:31 +0200)]
Cygwin: pipes: use NtClose when file has been opened with an NtXxx function

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: always close read side pipe handle in error case
Corinna Vinschen [Fri, 3 Sep 2021 08:25:29 +0000 (10:25 +0200)]
Cygwin: pipes: always close read side pipe handle in error case

Add missing CloseHandle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: fix a bug in raw_write
Corinna Vinschen [Fri, 3 Sep 2021 08:24:15 +0000 (10:24 +0200)]
Cygwin: pipes: fix a bug in raw_write

The buffer pointer is incremented by "chunk", which is what we
typically try to write, but this isn't what actually got written.
Increment the buffer pointer by what we actually wrote, as returned
by NtWriteFile.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: move get_obj_handle_count() to miscfuncs.cc
Corinna Vinschen [Fri, 3 Sep 2021 08:15:57 +0000 (10:15 +0200)]
Cygwin: move get_obj_handle_count() to miscfuncs.cc

get_obj_handle_count() is used in flock only so far, but pipe
handling might have a usage, too, soon.  Given that this function
might be generally useful and isn't restricted to flock usage,
move it to miscfuncs.cc and make it non-static.  Add a prototype
in miscfuncs.h.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: _pipe: add a comment
Corinna Vinschen [Tue, 31 Aug 2021 08:50:23 +0000 (10:50 +0200)]
Cygwin: _pipe: add a comment

I wasted valuable minutes of my life just to find out why we export
this weird version of pipe.  In the pre-2000 era the idea was Cygwin
could be used as drop-in replacement for msvcrt.dll, apparently.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoRevert "Cygwin: fhandler_pipe.cc:nt_select: fix flags"
Corinna Vinschen [Tue, 31 Aug 2021 09:39:52 +0000 (11:39 +0200)]
Revert "Cygwin: fhandler_pipe.cc:nt_select: fix flags"

This reverts commit a62f4d128505481c4c683e813a3b16da641af6ff.

2 years agoRevert "Cygwin: fhandler_pipe.cc:nt_select: fix flags again"
Corinna Vinschen [Tue, 31 Aug 2021 09:39:49 +0000 (11:39 +0200)]
Revert "Cygwin: fhandler_pipe.cc:nt_select: fix flags again"

This reverts commit c35db324efb5cdc6605eac947e0d4fdeb45e8b43.

2 years agoCygwin: fhandler_pipe.cc:nt_select: fix flags again
Ken Brown [Mon, 30 Aug 2021 15:54:04 +0000 (11:54 -0400)]
Cygwin: fhandler_pipe.cc:nt_select: fix flags again

2 years agoCygwin: fhandler_pipe.cc:nt_select: fix flags
Ken Brown [Mon, 30 Aug 2021 15:11:49 +0000 (11:11 -0400)]
Cygwin: fhandler_pipe.cc:nt_select: fix flags

2 years agoRevert "Cygwin: pipe: Revert to create() rather than nt_create()."
Ken Brown [Mon, 30 Aug 2021 13:53:06 +0000 (09:53 -0400)]
Revert "Cygwin: pipe: Revert to create() rather than nt_create()."

This reverts commit 5a7a0d34c74a55aa1e76644e61bf4889051cb640.

2 years agoCygwin: pipe: Revert to create() rather than nt_create().
Takashi Yano [Sun, 29 Aug 2021 08:23:57 +0000 (17:23 +0900)]
Cygwin: pipe: Revert to create() rather than nt_create().

2 years agoCygwin: select: Improve select/poll response.
Takashi Yano [Fri, 27 Aug 2021 10:54:41 +0000 (19:54 +0900)]
Cygwin: select: Improve select/poll response.

2 years agoCygwin: add fhandler_base::npfs_handle
Ken Brown [Thu, 26 Aug 2021 22:05:53 +0000 (18:05 -0400)]
Cygwin: add fhandler_base::npfs_handle

It replaces the three identical functions of the same name in the
classes fhandler_pipe, fhandler_fifo, and fhandler_socket_unix.

2 years agoCygwin: remove the fhandler_base_overlapped class
Ken Brown [Thu, 26 Aug 2021 22:00:27 +0000 (18:00 -0400)]
Cygwin: remove the fhandler_base_overlapped class

Also remove the 'was_nonblocking' flag, which was needed only for
fhandler_base_overlapped.

2 years agoCygwin: fhandler_pipe: fix permission problem
Ken Brown [Sat, 25 May 2019 14:27:38 +0000 (10:27 -0400)]
Cygwin: fhandler_pipe: fix permission problem

The read handles of pipes created by CreateNamedPipe don't have
FILE_WRITE_ATTRIBUTES access unless the pipe is created with
PIPE_ACCESS_DUPLEX.  This causes set_pipe_non_blocking to fail on such
handles.  To fix this, add a helper function nt_create, which uses
NtCreateNamedPipeFile instead of CreateNamedPipe and gives us more
flexibility in setting access rights.

Use this helper function in fhandler_pipe::create (fhandler_pipe *[2],
unsigned, int), which is the version of fhandler_pipe::create used by
the pipe and pipe2 system calls.

For convenience, also add a static member function
fhandler_pipe::npfs_handle similar to those used by fhandler_fifo and
fhandler_socket_unix.

2 years agoCygwin: fhandler_pipe: control blocking mode of the Windows pipe
Ken Brown [Sat, 25 May 2019 17:05:49 +0000 (13:05 -0400)]
Cygwin: fhandler_pipe: control blocking mode of the Windows pipe

Add methods 'set_pipe_non_blocking' and 'fcntl' to keep the blocking
mode of the Windows pipe in sync with that of the fhandler_pipe
object.  This applies to pipes created with the 'pipe' and 'pipe2'
system calls.

2 years agoCygwin: fhandler_pipe: add raw_read and raw_write
Ken Brown [Sat, 25 May 2019 17:03:08 +0000 (13:03 -0400)]
Cygwin: fhandler_pipe: add raw_read and raw_write

2 years agoCygwin: fhandler_pipe: derive from fhandler_base
Ken Brown [Thu, 26 Aug 2021 20:57:21 +0000 (16:57 -0400)]
Cygwin: fhandler_pipe: derive from fhandler_base

Previously fhandler_pipe was derived from fhandler_base_overlapped,
which we are going to remove in a future commit.  Make minimal changes
so that the build still succeeds.

2 years agoRegenerate Makefile.in after configure.in -> configure.ac change
Corinna Vinschen [Mon, 13 Sep 2021 15:25:46 +0000 (17:25 +0200)]
Regenerate Makefile.in after configure.in -> configure.ac change

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoAdd myself to sim & general write-after-approval maintainers
Mike Frysinger [Sat, 11 Sep 2021 21:52:38 +0000 (17:52 -0400)]
Add myself to sim & general write-after-approval maintainers

There are a few files that are tied to the GNU simulator, so add myself
to match the general sim project.

Also add myself to the general write-after-approval since I've been doing
that for a long time now anyways :).

2 years agolibgloss/newlib: rename configure.in to configure.ac
Mike Frysinger [Thu, 9 Sep 2021 20:49:49 +0000 (16:49 -0400)]
libgloss/newlib: rename configure.in to configure.ac

The .in name has been deprecated for a long time in favor of .ac.

2 years agoCygwin: fix initializing MEM_EXTENDED_PARAMETER, take 2
Corinna Vinschen [Wed, 8 Sep 2021 08:07:46 +0000 (10:07 +0200)]
Cygwin: fix initializing MEM_EXTENDED_PARAMETER, take 2

In https://cygwin.com/pipermail/cygwin/2021-September/249361.html
Brian pointed out that initializing the structure would be more
future proof, should the developers at Microsoft ever decide to
split the Reserved field and use some bits of the struct for
other purposes.

Fixes: 3d322ac930ca ("Cygwin: fix initializing MEM_EXTENDED_PARAMETER")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pty: Fix error handling of master write().
Takashi Yano [Tue, 7 Sep 2021 10:27:45 +0000 (19:27 +0900)]
Cygwin: pty: Fix error handling of master write().

- Currently, error handling of write() in pty master side is broken.
  This patch fixes that.

2 years agonano-malloc: Fix redefined compilation warning
Torbjorn SVENSSON via Newlib [Fri, 3 Sep 2021 15:54:10 +0000 (15:54 +0000)]
nano-malloc: Fix redefined compilation warning

When newlib is configured with --enable-newlib-reent-check-verify,
the assert macro is already defined in the nano-mallocr.c compile unit.

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
2 years agoCygwin: fix initializing MEM_EXTENDED_PARAMETER
Corinna Vinschen [Mon, 6 Sep 2021 18:15:43 +0000 (20:15 +0200)]
Cygwin: fix initializing MEM_EXTENDED_PARAMETER

MEM_EXTENDED_PARAMETER consists of a 64 bit bitfield which contains
the Type and the Reserved members.  The former usage of designated
initializer lists initialized Type, but not Reserved.  Since that's
not possible anymore due to a g++ 11.2 bug, Cygwin initializes the
MEM_EXTENDED_PARAMETER structs explicitely.  This results in a
random value in Reserved, which at least VirtualAlloc2 chokes on
(ERROR_INVALID_PARAMETER).

Set Reserved explicitely to 0 for a fix.

Fixes: bdb7991db38b ("Cygwin: workaround a g++ 11.2 initialization bug")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: fix declaration of RtlInitEmptyUnicodeString
Corinna Vinschen [Fri, 3 Sep 2021 11:16:48 +0000 (13:16 +0200)]
Cygwin: fix declaration of RtlInitEmptyUnicodeString

This avoids "-Werror=maybe-uninitialized" errors due to
using WCSTR accidentally.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoldexp/ldexpf: avoid assembler warning
Corinna Vinschen [Fri, 3 Sep 2021 10:52:47 +0000 (12:52 +0200)]
ldexp/ldexpf: avoid assembler warning

libm/machine/i386/f_ldexp.S:30: Warning: no instruction mnemonic suffix given and no register operands; using default for `fild'
libm/machine/i386/f_ldexpf.S:30: Warning: no instruction mnemonic suffix given and no register operands; using default for `fild'

fix this by adding the l mnemonic suffix

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agostrstr: avoid warnings
Corinna Vinschen [Fri, 3 Sep 2021 10:51:30 +0000 (12:51 +0200)]
strstr: avoid warnings

unused function warning for two_way_short_needle,
different char type warnings for standard string functions

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agonftw: fix thread cancellation support
Corinna Vinschen [Fri, 3 Sep 2021 10:25:44 +0000 (12:25 +0200)]
nftw: fix thread cancellation support

_STDIO_WITH_THREAD_CANCELLATION_SUPPORT was never defined.
Include ../stdio/local.h to get the right definition per target.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: testsuite: avoid "conflicting types" gcc warning
Corinna Vinschen [Fri, 3 Sep 2021 10:13:51 +0000 (12:13 +0200)]
Cygwin: testsuite: avoid "conflicting types" gcc warning

With gcc 11.2:

test.h:50:5: warning: conflicting types for built-in function ‘execve’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]
test.h:51:5: warning: conflicting types for built-in function ‘execv’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]
test.h:52:5: warning: conflicting types for built-in function ‘execvp’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]

Fix prototypes accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: dup: fix handle inheritence for disk file pread/pwrite handle
Corinna Vinschen [Mon, 30 Aug 2021 19:56:33 +0000 (21:56 +0200)]
Cygwin: dup: fix handle inheritence for disk file pread/pwrite handle

The handle is created non-inheritable but gets inheritable when
dup'ing the file descriptor.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agolibc/include/sys/signal.h: Change __STDINT_EXP() to __SIZEOF_INT__
Joel Sherrill [Fri, 27 Aug 2021 13:39:31 +0000 (08:39 -0500)]
libc/include/sys/signal.h: Change __STDINT_EXP() to __SIZEOF_INT__

__STDINT_EXP() is provided by newlib but not by stdint-gcc.h. stdint-gcc.h
is used when the GCC argument -ffreestanding is used and this results in this
file not compiling.

2 years agoCygwin: loader script: add DWARF 5 sections
Corinna Vinschen [Fri, 27 Aug 2021 12:26:42 +0000 (14:26 +0200)]
Cygwin: loader script: add DWARF 5 sections

Modern gcc's generate additional DWARF 5 debug sections, which were
still missing in our Cygwin loader script.  With ld from binutils 2.37,
this results in diagnostic output when linking the Cygwin DLL...

  ld: cygwin0.dll:/4: section below image base
  ld: cygwin0.dll:/20: section below image base
  ld: cygwin0.dll:/36: section below image base

...and the section addresses given to these sections (.debug_loclists,
.debug_rnglists, debug_line_str) will be wrong.

Fix this by adding the missing DWARF 5 sections to our linker script
template cygwin.sc.in.  Add a comment in terms of the deprecated
DWARF 4 section .debug_types.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
3 years agoCygwin: Allow using CFLAGS also for C++ files
Corinna Vinschen [Thu, 26 Aug 2021 20:21:21 +0000 (22:21 +0200)]
Cygwin: Allow using CFLAGS also for C++ files

This was used before switching to automake to allow easy tweaking
of optimization and debugging settings from the command line during
testing.  Reenable.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
3 years agoCygwin: workaround a g++ 11.2 initialization bug
Corinna Vinschen [Thu, 26 Aug 2021 20:19:20 +0000 (22:19 +0200)]
Cygwin: workaround a g++ 11.2 initialization bug

trying to use aggregate initialization syntax on a member of a
nameless union member failes in g++ 11.2.

Workaround this by using explicit initialization.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
3 years agoCygwin: dumper: fix up GCC pragma for g++ 11.2
Corinna Vinschen [Thu, 26 Aug 2021 20:15:49 +0000 (22:15 +0200)]
Cygwin: dumper: fix up GCC pragma for g++ 11.2

The GCC diagnostic ignored "-Wstringop-overflow" pragma doesn't work
as expected anymore.  Use the still working expression.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
3 years agoCygwin: C++17: register keyword is deprecated
Corinna Vinschen [Thu, 26 Aug 2021 20:14:11 +0000 (22:14 +0200)]
Cygwin: C++17: register keyword is deprecated

The register keyword was already deprecated with C++11, but
with C++17 it has been entirely removed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
3 years agonvptx: Emulate clock and other machine stubs.
Roger Sayle [Tue, 24 Aug 2021 16:24:19 +0000 (17:24 +0100)]
nvptx: Emulate clock and other machine stubs.

This patch to the libc/machine/nvptx port of newlib implements an
approximation of "clock" and provides some additional stub routines.
These changes not only reduce the number of (link) failures in the GCC
testsuite when targeting nvptx-none, but also allow the NIST scimark4
benchmark to compile and run without modification.

newlib already contains support for backends to provide their own
clock implementations via -DCLOCK_PROVIDED.  That functionality is
used here to return an approximate elapsed time based on the NVidia
GPU's clock64 cycle counter.  Although not great, this is better than
the current behaviour of link error from the unresolved symbol
_times_r.

The other part of the patch is to add a small number of stub functions
to nvptx's misc.c.  Adding isatty, for example, resolves linking
problems in libc from the dependency in __smakebuf_r, and the sync
stub, for example, fixes the failure with GCC's
testsuite/gfortran.dg/ISO_Fortran_binding_14.f90 [which simply tests
that gfortran can call a/any C function].

newlib/
        configure.host: Add -DCLOCK_PROVIDED to newlib_cflags on nvptx*.

newlib/libc/machine/nvptx
        Makefile.am: Add clock.c to lib_a_SOURCES.
        clock.c: New source file to implement/approximate clock().
        misc.c: Add stubs for fstat, isatty, open, sync and unlink.

3 years agofix race condition in List_insert
Aleksand Malikov [Mon, 23 Aug 2021 14:27:48 +0000 (17:27 +0300)]
fix race condition in List_insert

Revert mx parameter and mutex lock while operating the list.
Mutex was removed with 94d24160 informing that:
'Use InterlockedCompareExchangePointer to ensure race safeness
without using a mutex.'

But it does not.

Calling pthread_mutex_init and pthread_mutex_destroy from two or
more threads occasionally leads to hang in pthread_mutex_destroy.

To not change the behaviour of other cases where List_insert was called,
List_insert_nolock is added.

3 years agostdlib: conditionalize locale usage
Corinna Vinschen [Mon, 23 Aug 2021 07:56:22 +0000 (09:56 +0200)]
stdlib: conditionalize locale usage

_strtod_l as well as the gethex function both fetch the decimal point
from the current LC_NUMERIC locale info.  This pulls in _C_numeric_locale
unconditionally even on targets not supporting locales at all.

Another problem is that strtod.c and gdtoa-gethex.c are ELIX 1, while
locale information in general isn't.  This leads to potential build
breakage on bare metal targets.

Fix this by setting the decimal point to "." on all targets not
defining __HAVE_LOCALE_INFO__.

While at it, const'ify the entire local decimal point info in the
affected functions.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
3 years agoCygwin: fhandler_procsys::readdir: fix NtQueryDirectoryObject usage
Corinna Vinschen [Thu, 19 Aug 2021 19:17:11 +0000 (21:17 +0200)]
Cygwin: fhandler_procsys::readdir: fix NtQueryDirectoryObject usage

As outlined in the previous patch, the non-atomicity of iterating
over a directory in the NT namespace via NtQueryDirectoryObject
one entry each, results in potential duplication of directory entries.

Fix this for fhandler_procsys::readdir as well by fetching the entire
dir inside fhandler_procsys::opendir, storing it in a buffer, and just
return buffer content from fhandler_procsys::readdir.

Fixes: 43f65cdd7dae ("fhandler_procsys.cc: New file.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
3 years agoCygwin: fix all usages of NtQueryDirectoryObject
Corinna Vinschen [Thu, 19 Aug 2021 14:42:23 +0000 (16:42 +0200)]
Cygwin: fix all usages of NtQueryDirectoryObject

Due to reports on the Cygwin mailing list[1][2], it was uncovered
that a NtOpenDirectoryObject/NtQueryDirectoryObject/NtClose sequence
with NtQueryDirectoryObject iterating over the directory entries,
one entry per invocation, is not running atomically.  If new entries
are inserted into the queried directory, other entries may be moved
around and then accidentally show up twice while iterating.

Change (almost) all NtQueryDirectoryObject invocations so that it gets
a really big buffer (64K) and ideally fetches all entries at once.
This appears to work atomically.

"Almost" all, because fhandler_procsys::readdir can't be easily changed.

[1] https://cygwin.com/pipermail/cygwin/2021-July/248998.html
[2] https://cygwin.com/pipermail/cygwin/2021-August/249124.html

Fixes: e9c8cb31930bd ("(format_proc_partitions): Revamp loop over existing harddisks by scanning the NT native \Device object directory and looking for Harddisk entries.")
Fixes: a998dd7055766 ("Implement advisory file locking.")
Fixes: 3b7cd74bfdf56 ("(winpids::enum_processes): Fetch Cygwin processes from listing of shared cygwin object dir in the native NT namespace.")
Fixes: 0d6f2b0117aa7 ("syscalls.cc (sync_worker): Rewrite using native NT functions.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
3 years agoCygwin: return better inode numbers for block device entries in /proc/sys
Corinna Vinschen [Thu, 19 Aug 2021 14:08:34 +0000 (16:08 +0200)]
Cygwin: return better inode numbers for block device entries in /proc/sys

Commit 3434d35a64736f0b77a12f61784c2caa33ac44cf fixed a problem when
accessing block devices via their /proc/sys/Device entries.  This
changed the way stat info is generated for these devices, resulting
in identical inode numbers for all block devices under /proc/sys/Device.

This patch fixes that by faking a device number for these devices, just as
before.

Fixes: 3434d35a6473 ("Cygwin: Fix access to block devices below /proc/sys.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
3 years agosvfwscanf: Simplify _sungetwc_r to eliminate apparent buffer overflow
Keith Packard [Tue, 17 Aug 2021 18:51:52 +0000 (11:51 -0700)]
svfwscanf: Simplify _sungetwc_r to eliminate apparent buffer overflow

svfwscanf replaces getwc and ungetwc_r. The comments in the code talk
about avoiding file operations, but they also need to bypass the
mbtowc calls as svfwscanf operates on wchar_t, not multibyte data,
which is a more important reason here; they would not work correctly
otherwise.

The ungetwc replacement has code which uses the 3 byte FILE _ubuf
field, but if wchar_t is 32-bits, this field is not large enough to
hold even one wchar_t value. Building in this mode generates warnings
about array overflow:

In file included from ../../newlib/libc/stdio/svfiwscanf.c:35:
../../newlib/libc/stdio/vfwscanf.c: In function '_sungetwc_r.isra':
../../newlib/libc/stdio/vfwscanf.c:316:12: warning: array subscript 4294967295 is above array bounds of 'unsigned char[3]' [-Warray-bounds]
  316 |   fp->_p = &fp->_ubuf[sizeof (fp->_ubuf) - sizeof (wchar_t)];
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../../newlib/libc/stdio/stdio.h:46,
 from ../../newlib/libc/stdio/vfwscanf.c:82,
 from ../../newlib/libc/stdio/svfiwscanf.c:35:
../../newlib/libc/include/sys/reent.h:216:17: note: while referencing '_ubuf'
  216 |   unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
      |                 ^~~~~

However, the vfwscanf code *never* ungets data before the start of the
scanning operation, and *always* ungets data which matches the input
at that point, so the code always hits the block which backs up over
the input data and never hits the block which uses the _ubuf field.

In addition, the svfwscanf code will always start with the unget
buffer empty, so the ungetwc replacement never needs to support an
unget buffer at all.

Simplify the code by removing support for everything other than
backing up over the input data, leaving the check to make sure it
doesn't get underflowed in case the vfscanf code has a bug in it.

Signed-off-by: Keith Packard <keithp@keithp.com>
3 years agolibc: Added prototypes for new POSIX APIs
Matt Joyce [Fri, 6 Aug 2021 20:04:42 +0000 (22:04 +0200)]
libc: Added prototypes for new POSIX APIs

Added function prototypes to newlib/libc/include/pthread.h
for the following Issue 8 Standard APIs:
pthread_cond_clockwait()
pthread_mutex_clocklock()
pthread_rwlock_clockrdlock()
pthread_rwlock_clockwrlock()

3 years agoRISC-V: Reliably initialize t0 in _times()
Christoph Muellner [Mon, 2 Aug 2021 16:46:16 +0000 (18:46 +0200)]
RISC-V: Reliably initialize t0 in _times()

The current implementation does not reliably initialize t0 once.
Additionally the initialization requires two calls to _gettimeofday().
Let's sacrifice a byte to keep the initialization status
and reduce the maximum number of calls to _gettimeofday().

This has caused issues in an application that invokes clock().
The problematic situation is as follows:

1) The program calls clock() which calls _times().
2) _gettimeofday(&t0, 0) puts 0 in t0.tv_usec (because less than 1 us has
   elapsed since the beginning of time).
3) _gettimeofday(&t, 0) puts 1 in t.tv_usec (since now more than 1 us has
   elapsed since the beginning of time).
4) That call to clock() returns 1 (the value from step 3 minus the value in
   step 2).
5) The program does a second call to clock().
6) The code above still sees 0 in t0 so it tries to update t0 again and
   _gettimeofday(&t0, 0) puts 1 in t0.tv_usec.
7) The _gettimeofday(&t, 0) puts 1 in t.tv_usec (since less than 1us has
   elapsed since step 3).
8) clock() returns 0 (step 7 minus step 6) and indicates that time is
   moving backwards.

Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
This page took 0.073875 seconds and 5 git commands to generate.