Commit Graph

21041 Commits

Author SHA1 Message Date
Brian Inglis 7f7e4e5bc5 strptime.cc(__strptime): add %q GNU quarter 2022-10-24 14:09:07 +02:00
Brian Inglis d6a26e542d strptime.c(strptime_l): add %q GNU quarter 2022-10-24 14:07:23 +02:00
Takashi Yano 7589034cc3 Cygwin: pty: Fix 'Bad address' error when running 'cmd.exe /c dir'
- If the command executed is 'cmd.exe /c [...]', runpath in spawn.cc
  will be NULL. In this case, is_console_app(runpath) check causes
  access violation. This case also the command executed is obviously
  console app., therefore, treat it as console app to fix this issue.

  Addresses: https://github.com/msys2/msys2-runtime/issues/108
2022-10-22 14:21:15 +09:00
Simon Cook 8c87ffd372 libgloss: riscv: Install machine/syscall.h
A recent change to the Makefile.in for riscv resulted in the
machine/syscall.h header not being installed. This updates the file
to install this file again.

Signed-off-by: Simon Cook <simon.cook@embecosm.com>
2022-10-20 16:53:06 +02:00
Ken Brown 5781871775 Cygwin: select: don't report read ready on a FIFO never opened for writing
According to POSIX and the Linux man page, select(2) is supposed to
report read ready if a file is at EOF.  In the case of a FIFO, this
means that the pipe is empty and there are no writers.  But there
seems to be an undocumented exception, observed on Linux and other
platforms:  If no writer has ever been opened, then select(2) does not
report read ready.  This can happen if a reader is opened with
O_NONBLOCK before any writers have opened.

This commit makes Cygwin consistent with those other platforms by
introducing a special EOF test, fhandler_fifo::select_hit_eof, which
returns false if there's never been a writer opened.

To implement this we use a new variable '_writer_opened' in the FIFO's
shared memory, which is set to 1 the first time a writer opens.  New
methods writer_opened() and set_writer_opened() are used to test and
set this variable.

Addresses: https://cygwin.com/pipermail/cygwin/2022-September/252223.html
2022-10-19 08:17:50 -04:00
Szabolcs Nagy 0b6342c97f Rerun automake in newlib/
newlib/libc/sys/arm/Makefile.inc was modified but automake was not rerun in

  commit 5230eb7f8c
  Implement sysconf for Arm

on arm-none-eabi target this caused

  ld: B/arm-none-eabi/lib/libg.a(libc_a-mallocr.o): in function `malloc_extend_top':
  S/newlib-cygwin/newlib/libc/stdlib/_mallocr.c:2161: undefined reference to `sysconf'
2022-09-28 10:49:53 -04:00
Markus B. Moessner 01f6251c09 Fix missing extern C statement 2022-09-26 13:44:21 -04:00
Sebastian Huber d9dc88048a powerpc/setjmp: Add 64-bit support
Use 64-bit store/load instructions to save/restore the general-purpose
registers.
2022-09-24 08:39:29 +02:00
Jeff Johnston 5230eb7f8c Implement sysconf for Arm
- add support for using sysconf to get page size in _mallocr.c via
  HAVE_SYSCONF_PAGESIZE flag set in configure.host
- set flag in configure.host for arm and add a default sysconf implementation
  in libc/sys/arm that returns the page size
- the default implementation can be overridden outside newlib to allow a
  different page size to improve malloc on devices with a small footprint
  without needing to rebuild newlib
- this patch is based on a contribution from Torbjorn Svensson and
  Niklas Dahlquist (https://ecos.sourceware.org/ml/newlib/current/017616.html)
2022-09-19 15:35:55 -04:00
tb eb5c631ead upstream OpenBSD: arc4random: fix indent 2022-09-10 21:00:38 +02:00
djm 52a410f9bd upstream OpenBSD: arc4random: Randomise the rekey interval a little.
Previously, the chacha20 instance would be rekeyed every 1.6MB. This
makes it happen at a random point somewhere in the 1-2MB range.

Feedback deraadt@ visa@, ok tb@ visa@

newlib port: Make REKEY_BASE depend on SIZE_MAX
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-09-10 20:59:01 +02:00
dtucker f5fece2838 upstream OpenBSD: arc4random: Remove unused ivbits argument from chacha_keysetup
to match other instances in the tree. ok deraadt@
2022-09-10 20:58:03 +02:00
deraadt db5e07368c upstream OpenBSD: arc4random: replace abort() with _exit()
In the incredibly unbelievable circumstance where _rs_init() fails to
allocate pages, don't call abort() because of corefile data leakage
concerns, but simply _exit(). The reasoning is _rs_init() will only fail
if someone finds a way to apply specific pressure against this failure
point, for the purpose of leaking information into a core which they can
read. We don't need a corefile in this instance to debug that. So take
this "lever" away from whoever in the future wants to do that.
2022-09-10 20:58:03 +02:00
Corinna Vinschen dd22053fee upstream OpenBSD: arc4random: bump file versions
This hides a patch not required in newlib
2022-09-10 20:58:01 +02:00
bcook ef76759d7f upstream OpenBSD: arc4random: Add support for building arc4random with MSVC.
By default, MSVC's stdlib.h defines min(), so we need to spell out something
less common to avoid picking it up.

ok deraadt@ beck@ miod@
2022-09-10 20:56:25 +02:00
Corinna Vinschen 783133b753 Cygwin: cygtls: drop useless alignment directives
The patch fixing the alignment of _cygtls::context accidentally
pushed the desperate attempt to automate the alignment by using
another, non-working variation of attribute((aligned)).  Drop it.

Fixes: dcab768cb9 ("Cygwin: cygtls: fix context alignment")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-09-05 19:52:28 +02:00
Torbjörn SVENSSON a68e99f883 Don't allocate another header when merging chunks
In the nano version of malloc, when the last chunk is to be extended,
there is no need to acount for the header again as it's already taken
into account in the overall "alloc_size" at the beginning of the
function.

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2022-09-01 15:39:10 -04:00
Torbjörn SVENSSON 0455ea28ce Used chunk needs to be removed from free_list
When using nano malloc and the remaning heap space is not big enough to
fullfill the allocation, malloc will attempt to merge the last chunk in
the free list with a new allocation in order to create a bigger chunk.
This is successful, but the chunk still remains in the free_list, so
any later call to malloc can give out the same region without it first
being freed.

Possible sequence to verify:

void *p1 = malloc(3000);
void *p2 = malloc(4000);
void *p3 = malloc(5000);
void *p4 = malloc(6000);
void *p5 = malloc(7000);
free(p2);
free(p4);
void *p6 = malloc(35000);
free(p6);
void *p7 = malloc(42000);
void *p8 = malloc(32000);

Without the change, p7 and p8 points to the same address.
Requirement, after malloc(35000), there is less than 42000 bytes
available on the heap.

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2022-09-01 14:40:27 -04:00
Jeff Johnston d92d3a3c4a Fix some Coverity Scan errors. 2022-08-31 15:18:08 -04:00
Torbjörn SVENSSON dd1122e21c Restore _lock initialization in non-single threaded mode
When __SINGLE_THREAD__ is not defined, stdin, stdout and stderr needs
to have their _lock instance initialized. The __sfp() method is not
invoked for the 3 mentioned fds thus, the std() method needs to handle
the initialization of the lock.

This is more or less a revert of 382550072b

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2022-08-31 10:02:53 +02:00
Jon Turney b4561c2363
Cygwin: testsuite: Add x86_64 code to "dynamically load cygwin" test
This still needs some more voudou to actually work.

Also update how-cygtls-works.txt a bit
2022-08-29 17:53:48 +01:00
Jon Turney 6e843f7750
Cygwin: testsuite: In pathconf01 use the temporary directory instead of "/tmp"
In pathconf01 use the temporary directory, instead of "/tmp" (which may not exist).
2022-08-29 17:53:46 +01:00
Jon Turney f1d7ef46f7
Cygwin: testsuite: Fix size of write to temporary file to be mmap()ed
See ltp commit 91361378
2022-08-29 17:53:45 +01:00
Jon Turney 19b3b814bc
Cygwin: testsuite: Fix TEST_RETURN for 64-bit
The result of a function call won't fit in an int if it's e.g. a pointer.
2022-08-29 17:53:44 +01:00
Jon Turney 6ca056eec9
Cygwin: testsuite: Remove passing tests from XFAIL list
Remove ltp/fcntl05.c from XFAIL list, since it now PASSes.
Remove ltp/dup03.c from XFAIL list, since it now PASSes.
2022-08-29 17:53:42 +01:00
Jon Turney 5cea46d309
Cygwin: testsuite: Don't write coredump in a child which is expected to segfault 2022-08-29 17:53:41 +01:00
Corinna Vinschen dcab768cb9 Cygwin: cygtls: fix context alignment
A hang was encountered, apparently triggered by commit 63b503916d,
changing tls_pathbufs from malloc'ed to HeapAlloc'ed memory.  After
lengthy debugging it transpired that adding the heap handle to the
tls_pathbuf struct added 8 bytes to the cygtls area, thus moving
the "context" member by 8 bytes, too, so it was suddently unaligned.

Fix this for now by changing the alignment.

Fix this once and for all, by adding code to the gentls_offsets script
to check if the alignment of the "context" member is 16 bytes.  If not,
print a matching error message, remove the just generated file, and exit
with error.

FIXME: It would be really nice to find a way to auomate the correct
alignment of the "context" member, but I don't see any way to use
alignment attributes to get what we need here.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-29 15:18:53 +02:00
Corinna Vinschen 717c36c0a4 Cygwin: fork: fix a potential hang in fork
while debugging a problem introduced in commit
63b503916d ("Cygwin: tls_pathbuf: Use Windows heap")
a hang in fork was encountered using the original implementation
of tls_pathbuf:

Using tmp_pathbuf inside the code block guarded by __malloc_trylock
may call malloc from tmp_pathbuf::w_get and thus trying to lock an
exclusive SRW lock recursively, which results in a deadlock.

Allocate a small SECURITY_ATTRIBUTES block on the stack rather than
allocating a 64K tmp_pathbuf.  This avoids the potential malloc call.

Drop the __malloc_trylock call entirely.  There must not be a malloc
call inside the frok::parent block guarded by __malloc_lock, and
just trying to lock is too dangerous inside fork while other threads
might actually chage the content of the heap.  Additionally, add a
comment frowning on malloc usage inside tis code block.

Fixes: 44a79a6eca ("Cygwin: convert malloc lock to SRWLOCK")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-29 12:25:24 +02:00
Palmer Dabbelt f59ff93046 libgloss: riscv: Convert to non-recursive automake
PR 29515 points out our documentation builds are broken, let's just move
over to the new non-recursive builds.

Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2022-08-26 16:47:48 +02:00
Corinna Vinschen 0819679a7a Cygwin: cwd: use SRWLOCK instead of muto
To reduce thread contention, use reader/writer locks as required.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-23 12:09:44 +02:00
Corinna Vinschen ee54cabad9 Cygwin: mmap: use SRWLOCK instead of muto
To reduce thread contention, use reader/writer locks as required.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-23 12:09:44 +02:00
Corinna Vinschen 63b503916d Cygwin: tls_pathbuf: Use Windows heap
Rather than using malloc/free for the buffers, we're now using
HeapAlloc/HeapFree on a HEAP_NO_SERIALIZE heap created for this
thread.

Advantages:
- Less contention. Our malloc/free doesn't scale well in
  multithreaded scenarios
- Even faster heap allocation by using a non serialized heap.
- Internal, local, temporary data not cluttering the user heap.
- Internal, local, temporary data not copied over to child process
  at fork().

Disadvantage:
- A forked process has to start allocating temporary buffers from
  scratch.  However, this should be alleviated by the fact that
  buffer allocation usually reaches its peak very early in process
  runtime, so the longer the proceess runs, the less buffers have
  to allocated, and, only few processes don't exec after fork
  anyway.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-23 12:09:44 +02:00
Jeff Johnston 64a11fded1 Fix problem with _newlib_version.h not being filled in correctly 2022-08-22 17:55:23 -04:00
Corinna Vinschen c3e92052bb Cygwin: smallprint.cc: Drop HEAP_ZERO_MEMORY
Leftover from testing.

Reported-by: Noel Grandin <noelgrandin@gmail.com>
Fixes: 07ec40170a ("Cygwin: smallprint.cc: Convert tmpbuf to lockless")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 17:58:53 +02:00
Corinna Vinschen 88e2f2aad1 Cygwin: posix_timer: fix formatting
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 14:53:30 +02:00
Corinna Vinschen 74983727c0 Cygwin: push missing change to debug.h
Fixes: 48a210a457 ("Cygwin: debugging: convert muto to SRWLOCK")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 14:53:30 +02:00
Corinna Vinschen 48a210a457 Cygwin: debugging: convert muto to SRWLOCK
this avoids having to call debug_init, because the SRWLOCK
is statically initialized.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 14:38:49 +02:00
Corinna Vinschen d6c50e630a Cygwin: shm: Convert muto into SRWLOCK and avoid overlocking
shmat may call shmget.  shmget locks by itself as necessary,
so there's no reason to keep the lock active and recurse into
the lock.  Use SRWLOCK and only lock  as required.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 14:28:11 +02:00
Corinna Vinschen 2e03e5a040 Cygwin: authz: Use dedicated locks per datastructure
So far we use a single muto to guard three different datastructures
inside class authz_ctx: the authz HANDLE, the user context HANDLE
and the context cache list.  Split the single muto into three
independent SRWLOCKs and guard all datastrcutures as necessary to
avoid thread contention.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 14:25:05 +02:00
Corinna Vinschen e0cc4ea929 Cygwin: spawn: don't overallocate SECURITY_ATTRIBUTES buffer
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 12:37:31 +02:00
Corinna Vinschen 07ec40170a Cygwin: smallprint.cc: Convert tmpbuf to lockless
The old technique was from a time when we had to reduce stack pressure
by moving 64K buffers elsewhere.  It was implemented using a static
global buffer, guarded by a muto. However, that adds a lock which may
unnecessarily serialize threads.

Use Windows heap buffers per invocation instead.  HeapAlloc/HeapFree are
pretty fast, scale nicely in multithreaded scenarios and don't serialize
threads unnecessarily.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 12:01:15 +02:00
Corinna Vinschen 1b3a0effd4 Cygwin: profiler: Fix linking when building with -DDEBUGGING
CloseHandle gets redefined to a macro calling an internal function
in debug.h when building with -DDEBUGGING, but profiler has no access
to that function.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-20 21:14:57 +02:00
Corinna Vinschen c1f8a7b502 Cygwin: wchar.h: Fix comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-20 20:27:37 +02:00
Corinna Vinschen 2ec96890db Cygwin: sigproc.cc: drop Static macro, use explicit NO_COPY instead
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-19 21:55:09 +02:00
Corinna Vinschen 1b2d3d1f94 Cygwin: drop __fastcall calling convention specifiers
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-19 21:52:45 +02:00
Corinna Vinschen 2b9d98d083 Cygwin: miscfuncs.h: fix comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-19 15:51:49 +02:00
Yilin Sun via Newlib b7109cf82e SH: Do not build syscalls if option provided
This patch makes syscalls for SH architecture respecting the global option
"--disable-newlib-supplied-syscalls". This is useful when a bare-metal
toolchain is needed.

Signed-off-by: Yilin Sun <imi415@imi.moe>
2022-08-15 15:12:19 -04:00
Corinna Vinschen 85be74f295 newlocale: fix crash when trying to write to __C_locale
This simple testcase:

  locale_t st = newlocale(LC_ALL_MASK, "C", (locale_t)0);
  locale_t st2 = newlocale(LC_CTYPE_MASK, "en_US.UTF-8", st);

is sufficient to reproduce a crash in _newlocale_r.  After the first call
to newlocale, `st' points to __C_locale, which is const.  When using `st'
as locale base in the second call, _newlocale_r tries to set pointers
inside base to NULL.  This is bad if base is __C_locale, obviously.

Add a test to avoid trying to overwrite pointer values inside base if
base is __C_locale.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-12 12:29:26 +02:00
Corinna Vinschen bf1d972d5c Cygwin: move POSIX semaphore API functions to posix_ipc.cc
This way, the sem API is all in the same place, even if the
underlying semaphore class is still in thread.cc.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-10 18:11:57 +02:00
Corinna Vinschen 782ef53619 Cygwin: rename CygwinCreateThread to create_posix_thread
Rename CygwinCreateThread to create_posix_thread and move
from miscfuncs.cc to create_posix_thread.cc, inbcluding all
related functions.  Analogue for the prototypes.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-10 18:06:28 +02:00