]> sourceware.org Git - newlib-cygwin.git/log
newlib-cygwin.git
23 months agoCygwin: fix TIOCMBIS/TIOCMBIC not working when using usbser.sys
Carlo Bramini [Fri, 11 Nov 2022 10:15:27 +0000 (11:15 +0100)]
Cygwin: fix TIOCMBIS/TIOCMBIC not working when using usbser.sys

In winsup/cygwin/fhandler/serial.cc, the function
fhandler_serial::switch_modem_lines() is called when TIOCMBIS/TIOCMBIC
are used in an ioctl() call.

This function uses EscapeCommFunction() for setting and resetting RTS
and DTR signals of a serial port.  Unfortunately, this function does not
work on USB CDC devices.

This is not a true bug of CYGWIN but an issue of the usbser.sys driver,
from Windows 2000 to the latest Windows 11.  Both 32bit and 64bit
versions of the operating system are affected.  Actually, I tested
EscapeCommFunction() also when using a real UART, based on the
traditional 16550 driver and it works fine.  Using thirdy party CDC
drivers, like the one provided by FTDI for their USB bridge chips,
probably also works.

However, it is also possible to drive the RTS/DTR signals by writing
their state with SetCommState(), which proved to be working fine all
types of connection.  This is also a better solution for handling these
signals since RTS/DTR can be set at the same time rather than having two
separate calls with a visible delay between them.

23 months agopowerpc/setjmp: Fix 64-bit buffer alignment
Sebastian Huber [Mon, 7 Nov 2022 13:33:42 +0000 (14:33 +0100)]
powerpc/setjmp: Fix 64-bit buffer alignment

The rlwinm is a word-size instruction which clears the remaining 32 bits of a
64-bit register.  Use clrrdi in 64-bit configurations.

23 months agoCygwin: Correct /proc/*/stat for processes without ctty
Andy Koppe [Wed, 9 Nov 2022 20:34:30 +0000 (20:34 +0000)]
Cygwin: Correct /proc/*/stat for processes without ctty

Report 0 instead of 268435455 (i.e. 0xFFFFFFF) in the tty field of
/proc/*/stat for processes without a controlling terminal. This is what
the procps utility expects when selecting or excluding such processes.

23 months agoGenerally make all 'long double complex' methods available in <complex.h>
Thomas Schwinge [Wed, 5 Oct 2022 20:11:41 +0000 (22:11 +0200)]
Generally make all 'long double complex' methods available in <complex.h>

..., not just '#if defined(__CYGWIN__)'.  (Exception: 'clog10l' which currently
indeed is for Cygwin only.)

This completes 2017-07-05 commit be3ca3947402827aa52709e677369bc7ad30aa1d
"Fixed warnings for some long double complex methods" after Aditya Upadhyay's
work on importing "Long double complex methods" from NetBSD.

For example, this changes GCC/nvptx libgfortran 'configure' output as follows:

    [...]
    checking for ccosf... yes
    checking for ccos... yes
    checking for ccosl... [-no-]{+yes+}
    [...]

..., and correspondingly GCC/nvptx 'nvptx-none/libgfortran/config.h' as
follows:

    [...]
     /* Define to 1 if you have the `ccosl' function. */
    -/* #undef HAVE_CCOSL */
    +#define HAVE_CCOSL 1
    [...]

Similarly for 'ccoshl', 'cexpl', 'cpowl', 'csinl', 'csinhl', 'ctanl', 'ctanhl',
'cacoshl', 'cacosl', 'casinhl', 'catanhl'.  ('conjl', 'cprojl' are not
currently being used in libgfortran.)

This in turn simplifies GCC/nvptx 'libgfortran/intrinsics/c99_functions.c'
compilation such that this files doesn't have to provide its own
"Implementation of various C99 functions" for those, when in fact they're
available in newlib libm.

23 months agoCygwin: Improve FAQ on early breakpoint for ASLR
Jon Turney [Tue, 1 Nov 2022 16:52:57 +0000 (16:52 +0000)]
Cygwin: Improve FAQ on early breakpoint for ASLR

gdb supports the 'disable-randomization' setting on Windows since [1]
(included in gdb 13).

https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=bcb9251f029da8dcf360a4f5acfa3b4211c87bb0;hp=8fea1a81c7d9279a6f91e49ebacfb61e0f8ce008

23 months agoCygwin: Handle out of order modules for module offsets in stackdump
Jon Turney [Tue, 1 Nov 2022 14:01:08 +0000 (14:01 +0000)]
Cygwin: Handle out of order modules for module offsets in stackdump

Improve address to module+offset conversion, to work correctly in the
presence of out-of-order elements in InMemoryOrderModuleList.

Fixes: d59651d4
2 years agostrftime/wcsftime: use STRLEN, not strlen
Corinna Vinschen [Sat, 29 Oct 2022 18:15:58 +0000 (20:15 +0200)]
strftime/wcsftime: use STRLEN, not strlen

Commit 737e2004a3bb accidentally introduced a call to strlen in
code used with wide character strings in case of wcsftime.  Use
STRLEN instead.

Fixes: 737e2004a3bb ("strftime.c(__strftime): add %q, %v, tests; tweak %Z doc")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agomakedocbook: Add explicit locking for PLY parser table generation
Jon Turney [Fri, 28 Oct 2022 16:56:09 +0000 (17:56 +0100)]
makedocbook: Add explicit locking for PLY parser table generation

Drop 'makedocbook --cache' (any dependency on the man-cache rule which
invokes that was dropped by the non-recursive make changes)

Instead, add some explicit locking which prevents processes colliding
over the file containing generated python code for the parser table.

2 years agoCygwin: Add loaded module base address list to stackdump
Jon Turney [Fri, 28 Oct 2022 12:35:13 +0000 (13:35 +0100)]
Cygwin: Add loaded module base address list to stackdump

This adds an extra section to the stackdump, which lists the loaded
modules and their base address.  This is perhaps useful as it makes it
immediately clear if RandomCrashInjectedDll.dll is loaded...

Future work: It seems like the 'InMemoryOrder' part of
'InMemoryOrderModuleList' is a lie?

> Loaded modules
000100400000 segv-test.exe
7FFF2AC30000 ntdll.dll
7FFF29050000 KERNEL32.DLL
7FFF28800000 KERNELBASE.dll
000180040000 cygwin1.dll
7FFF28FA0000 advapi32.dll
7FFF29F20000 msvcrt.dll
7FFF299E0000 sechost.dll
7FFF29B30000 RPCRT4.dll
7FFF27C10000 CRYPTBASE.DLL
7FFF28770000 bcryptPrimitives.dll

2 years agoCygwin: Add addresses as module offsets in .stackdump file
Jon Turney [Fri, 28 Oct 2022 11:26:56 +0000 (12:26 +0100)]
Cygwin: Add addresses as module offsets in .stackdump file

This adds an additional column to the stack trace in a .stackdump file,
which gives the stack frame return address as a module name+offset. This
makes it a possible to convert the address to a function name without
having to guess what module the address belongs to.

> Stack trace:
> Frame         Function     Args
0007FFFFCC30  0001004010E9 (000180048055000180046FA000000000000200018031E160) segv-test.exe+0x10E9
0007FFFFCD30  0001800480C1 (000000000000000000000000000000000000000000000000) cygwin1.dll+0x80C1
0007FFFFFFF0  000180045C86 (000000000000000000000000000000000000000000000000) cygwin1.dll+0x5C86
0007FFFFFFF0  000180045D34 (000000000000000000000000000000000000000000000000) cygwin1.dll+0x5D34
> End of stack trace

Loosely based on this patch [1] by Brian Dessent.

[1] https://cygwin.com/pipermail/cygwin-patches/2008q1/006306.html

2 years agoCygwin: Tidy up formatting of stackdump
Jon Turney [Fri, 28 Oct 2022 12:43:54 +0000 (13:43 +0100)]
Cygwin: Tidy up formatting of stackdump

Resize stackdump headers for b9e97f58
Consistently use \r\n line endings

2 years agoCygwin: cygheap: make bucket_val a static const array
Corinna Vinschen [Fri, 28 Oct 2022 15:02:05 +0000 (17:02 +0200)]
Cygwin: cygheap: make bucket_val a static const array

Every time the cygheap is initialized, that is, on each fork
or exec, cygheap_init() *again* computes the bucket size values
and stores them in the cgyheap, albeit they are always the
same values anyway.

Make bucket_val a local const array, statically initialized
instead.

Fixes: 61522196c715 ("* Merge in cygwin-64bit-branch.)"
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: document ASLR support topic/aslr_support github/topic/aslr_support
Corinna Vinschen [Fri, 28 Oct 2022 08:01:02 +0000 (10:01 +0200)]
Cygwin: document ASLR support

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: Enable dynamicbase on the Cygwin DLL by default
Corinna Vinschen [Fri, 28 Oct 2022 08:00:48 +0000 (10:00 +0200)]
Cygwin: Enable dynamicbase on the Cygwin DLL by default

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: /proc/<PID>/maps: output cygheap info
Corinna Vinschen [Fri, 28 Oct 2022 08:00:17 +0000 (10:00 +0200)]
Cygwin: /proc/<PID>/maps: output cygheap info

Now that the cygheap isn't part of the CYgwin DLL anymore, we have a
known memory location which is not known in maps output.  Fix that by
checking for cygheap address (same in all processes) and add to output.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop objcopy .gnu_debuglink juggle
Corinna Vinschen [Thu, 27 Oct 2022 11:05:36 +0000 (13:05 +0200)]
Cygwin: drop objcopy .gnu_debuglink juggle

Prior to 591fec858d01 ("Cygwin: decouple cygheap from Cygwin DLL")
the .cygheap section was required to stay the last section in the
final binary.  That required some juggling with objcopy to make
sure the .gnu_debuglink section is prior to the .cygheap section
in the final DLL.

This isn't required anymore, so just drop it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: memory_layout.h: define absolute MMAP_STORAGE_HIGH values here
Corinna Vinschen [Wed, 26 Oct 2022 20:04:41 +0000 (22:04 +0200)]
Cygwin: memory_layout.h: define absolute MMAP_STORAGE_HIGH values here

Use the symbolic values in wincap.cc.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: memory_layout.h: fix comments
Corinna Vinschen [Wed, 26 Oct 2022 19:26:37 +0000 (21:26 +0200)]
Cygwin: memory_layout.h: fix comments

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: decouple shared mem regions from Cygwin DLL
Corinna Vinschen [Wed, 26 Oct 2022 19:22:19 +0000 (21:22 +0200)]
Cygwin: decouple shared mem regions from Cygwin DLL

Another reason ASLR may fail is the coupling of the standard shared
mem regions (global, userinfo, process info, shared console) to the
address of the Cygwin DLL.  They are always placed in fixed addresses
preceeding the Cygwin DLL's address.  With ASLR this is bound to fail.

Use a fixed, unused memory area to place the shared mem regions.
This also allows to simplify the shared memory creation.  There's
no reason anymore to rebase the regions and rather than offsets,
just use the addresses directly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: decouple cygheap from Cygwin DLL
Corinna Vinschen [Wed, 26 Oct 2022 19:16:35 +0000 (21:16 +0200)]
Cygwin: decouple cygheap from Cygwin DLL

One reason that ASLR is tricky is the fact that the cygheap
is placed at the end of the DLL and especially that it's expected
to be growable.  To support ASLR, this construct must go.

Define dedicated cygheap memory region and reserve entire region.
Commit 3 Megs, as was the default size of the cygheap before.

Fix linker script accordingly, drop a now useless version check
in get_cygwin_startup_info().

2 years agoCygwin: add memory_layout.h
Corinna Vinschen [Wed, 26 Oct 2022 19:06:54 +0000 (21:06 +0200)]
Cygwin: add memory_layout.h

Collect all info about memory layout in one header file, so
the mem layout is documented in one logical place and not
in heap.cc arbitrarily.

Use info from this file throughout.

This is to prepare for ASLR support.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: exceptions: print 48 bit addresses
Corinna Vinschen [Fri, 28 Oct 2022 14:24:00 +0000 (16:24 +0200)]
Cygwin: exceptions: print 48 bit addresses

Exception handling was *still* printing addresses as 44 bit values,
but Windows supports a 48 bit virtual address space since Windows
8.1.  Fix that.

Fixes: e1254add73b1 ("Cygwin: Allow accessing 48 bit address space in Windows 8.1 or later")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: add missing .com entry in new-features.xml
Corinna Vinschen [Fri, 28 Oct 2022 11:01:37 +0000 (13:01 +0200)]
Cygwin: add missing .com entry in new-features.xml

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agopowerpc/setjmp: Fix 64-bit support
Sebastian Huber [Mon, 24 Oct 2022 09:05:14 +0000 (11:05 +0200)]
powerpc/setjmp: Fix 64-bit support

The first attempt to support the 64-bit mode had two bugs:

1. The saved general-purpose register 31 value was overwritten with the saved
   link register value.

2. The link register was saved and restored using 32-bit instructions.

Use 64-bit store/load instructions to save/restore the link register.  Make
sure that the general-purpose register 31 and the link register storage areas
do not overlap.

2 years agoCygwin: stop handling files with .com suffix like .exe files
Corinna Vinschen [Fri, 28 Oct 2022 10:42:51 +0000 (12:42 +0200)]
Cygwin: stop handling files with .com suffix like .exe files

.com is a remnant from the past.  There are only five executables
left:

  chcp.com
  format.com
  mode.com
  more.com
  tree.com

Calling them on the command line already requires to use the
suffix anyway.  So drop useless .com test from the execve test
for scripts (they are handled earlier in the same function
as executables) and do not handle them like .exe suffixes in
other functions.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoRevert "Cygwin: pty: Fix 'Bad address' error when running 'cmd.exe /c dir'"
Corinna Vinschen [Fri, 28 Oct 2022 10:24:31 +0000 (12:24 +0200)]
Revert "Cygwin: pty: Fix 'Bad address' error when running 'cmd.exe /c dir'"

This reverts commit 7589034cc3151bfac8cc3d3af5e91402a78e160b.

The previous commit 14816de9af69 ("Cygwin: spawn: drop special handling
for cmd.exe and command.com") make this patch unnecessary.  The filename
argument (i. e., run_path in the caller) is now always non-NULL.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: spawn: drop special handling for cmd.exe and command.com
Corinna Vinschen [Fri, 28 Oct 2022 10:24:13 +0000 (12:24 +0200)]
Cygwin: spawn: drop special handling for cmd.exe and command.com

Apparently at one point handling cmd.exe and command.com special
made sense, but what that should be has never been documented.
There's also no clear reason why cmd.exe is different from any
other native executable.  Additionaly, checking for command.com
is entirely useless on 64 bit Windows anyway.

Just drop this code.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoFix warning during manpage generaton
Jon Turney [Thu, 27 Oct 2022 21:51:28 +0000 (22:51 +0100)]
Fix warning during manpage generaton

> ERROR: xref linking to Stubs has no generated link text.
> Error: no ID for constraint linkend: Stubs.

(Despite saying "ERROR", this is actually a warning, and manpages are
still generated)

Improve chapter-texi2docbook so it generates elements for texinfo
sections as well, so that a cross-reference to the "Stubs" section
contains a valid element ID.

2 years agoCygwin: utils: drop 32 bit considerations
Corinna Vinschen [Fri, 28 Oct 2022 09:37:02 +0000 (11:37 +0200)]
Cygwin: utils: drop 32 bit considerations

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: regtool: drop 32 bit hint from help output
Corinna Vinschen [Fri, 28 Oct 2022 09:01:56 +0000 (11:01 +0200)]
Cygwin: regtool: drop 32 bit hint from help output

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: document dropping 32 bit support
Corinna Vinschen [Thu, 27 Oct 2022 19:45:11 +0000 (21:45 +0200)]
Cygwin: document dropping 32 bit support

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoFix typo in faq-programming.xml
Hamish McIntyre-Bhatty [Wed, 26 Oct 2022 13:26:16 +0000 (14:26 +0100)]
Fix typo in faq-programming.xml

2 years agostrftime.c(__strftime): add %q, %v, tests; tweak %Z doc
Brian Inglis [Sat, 22 Oct 2022 05:13:52 +0000 (23:13 -0600)]
strftime.c(__strftime): add %q, %v, tests; tweak %Z doc

%q GNU quarter year 1-4
%v BSD/OSX/Ruby VMS/Oracle %e-%b-%Y
%Z change time zone *name* to *abbreviation*

2 years agostrptime.cc(__strptime): add %q GNU quarter
Brian Inglis [Sat, 22 Oct 2022 05:16:03 +0000 (23:16 -0600)]
strptime.cc(__strptime): add %q GNU quarter

2 years agostrptime.c(strptime_l): add %q GNU quarter
Brian Inglis [Sat, 22 Oct 2022 05:15:18 +0000 (23:15 -0600)]
strptime.c(strptime_l): add %q GNU quarter

2 years agoCygwin: pty: Fix 'Bad address' error when running 'cmd.exe /c dir'
Takashi Yano [Sat, 22 Oct 2022 05:05:40 +0000 (14:05 +0900)]
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

2 years agolibgloss: riscv: Install machine/syscall.h
Simon Cook [Tue, 18 Oct 2022 19:48:56 +0000 (21:48 +0200)]
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>
2 years agoCygwin: select: don't report read ready on a FIFO never opened for writing
Ken Brown [Fri, 23 Sep 2022 14:24:04 +0000 (10:24 -0400)]
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

2 years agoRerun automake in newlib/
Szabolcs Nagy [Wed, 28 Sep 2022 14:32:53 +0000 (15:32 +0100)]
Rerun automake in newlib/

newlib/libc/sys/arm/Makefile.inc was modified but automake was not rerun in

  commit 5230eb7f8c6b43c71d7e38d138935c48de930b76
  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'

2 years agoFix missing extern C statement
Markus B. Moessner [Mon, 26 Sep 2022 17:20:08 +0000 (19:20 +0200)]
Fix missing extern C statement

2 years agopowerpc/setjmp: Add 64-bit support
Sebastian Huber [Thu, 22 Sep 2022 07:19:57 +0000 (09:19 +0200)]
powerpc/setjmp: Add 64-bit support

Use 64-bit store/load instructions to save/restore the general-purpose
registers.

2 years agoImplement sysconf for Arm
Jeff Johnston [Fri, 16 Sep 2022 20:04:21 +0000 (16:04 -0400)]
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)

2 years agoupstream OpenBSD: arc4random: fix indent
tb [Sun, 31 Jul 2022 13:41:45 +0000 (13:41 +0000)]
upstream OpenBSD: arc4random: fix indent

2 years agoupstream OpenBSD: arc4random: Randomise the rekey interval a little.
djm [Sun, 31 Jul 2022 05:10:36 +0000 (05:10 +0000)]
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>
2 years agoupstream OpenBSD: arc4random: Remove unused ivbits argument from chacha_keysetup
dtucker [Mon, 28 Feb 2022 21:56:29 +0000 (21:56 +0000)]
upstream OpenBSD: arc4random: Remove unused ivbits argument from chacha_keysetup

to match other instances in the tree. ok deraadt@

2 years agoupstream OpenBSD: arc4random: replace abort() with _exit()
deraadt [Sun, 24 Mar 2019 17:56:54 +0000 (17:56 +0000)]
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.

2 years agoupstream OpenBSD: arc4random: bump file versions
Corinna Vinschen [Sun, 13 Sep 2015 08:31:47 +0000 (08:31 +0000)]
upstream OpenBSD: arc4random: bump file versions

This hides a patch not required in newlib

2 years agoupstream OpenBSD: arc4random: Add support for building arc4random with MSVC.
bcook [Thu, 10 Sep 2015 18:53:50 +0000 (18:53 +0000)]
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@

2 years agoCygwin: cygtls: drop useless alignment directives
Corinna Vinschen [Mon, 5 Sep 2022 17:49:11 +0000 (19:49 +0200)]
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: dcab768cb93e ("Cygwin: cygtls: fix context alignment")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoDon't allocate another header when merging chunks
Torbjörn SVENSSON [Tue, 30 Aug 2022 13:56:26 +0000 (15:56 +0200)]
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>
2 years agoUsed chunk needs to be removed from free_list
Torbjörn SVENSSON [Tue, 30 Aug 2022 13:56:25 +0000 (15:56 +0200)]
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>
2 years agoFix some Coverity Scan errors.
Jeff Johnston [Wed, 31 Aug 2022 19:18:08 +0000 (15:18 -0400)]
Fix some Coverity Scan errors.

2 years agoRestore _lock initialization in non-single threaded mode
Torbjörn SVENSSON [Tue, 30 Aug 2022 13:54:53 +0000 (15:54 +0200)]
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 382550072b49430f8c69adee937a0ba07bd385e6

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2 years agoCygwin: testsuite: Add x86_64 code to "dynamically load cygwin" test
Jon Turney [Thu, 26 Nov 2020 16:50:43 +0000 (16:50 +0000)]
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

2 years agoCygwin: testsuite: In pathconf01 use the temporary directory instead of "/tmp"
Jon Turney [Fri, 27 Nov 2020 15:18:37 +0000 (15:18 +0000)]
Cygwin: testsuite: In pathconf01 use the temporary directory instead of "/tmp"

In pathconf01 use the temporary directory, instead of "/tmp" (which may not exist).

2 years agoCygwin: testsuite: Fix size of write to temporary file to be mmap()ed
Jon Turney [Thu, 26 Nov 2020 16:11:44 +0000 (16:11 +0000)]
Cygwin: testsuite: Fix size of write to temporary file to be mmap()ed

See ltp commit 91361378

2 years agoCygwin: testsuite: Fix TEST_RETURN for 64-bit
Jon Turney [Thu, 26 Nov 2020 15:33:44 +0000 (15:33 +0000)]
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.

2 years agoCygwin: testsuite: Remove passing tests from XFAIL list
Jon Turney [Wed, 25 Nov 2020 14:27:28 +0000 (14:27 +0000)]
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.

2 years agoCygwin: testsuite: Don't write coredump in a child which is expected to segfault
Jon Turney [Sat, 17 Oct 2020 20:47:48 +0000 (21:47 +0100)]
Cygwin: testsuite: Don't write coredump in a child which is expected to segfault

2 years agoCygwin: cygtls: fix context alignment
Corinna Vinschen [Mon, 29 Aug 2022 13:18:53 +0000 (15:18 +0200)]
Cygwin: cygtls: fix context alignment

A hang was encountered, apparently triggered by commit 63b503916d42,
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>
2 years agoCygwin: fork: fix a potential hang in fork
Corinna Vinschen [Mon, 29 Aug 2022 10:25:24 +0000 (12:25 +0200)]
Cygwin: fork: fix a potential hang in fork

while debugging a problem introduced in commit
63b503916d42 ("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: 44a79a6eca3d ("Cygwin: convert malloc lock to SRWLOCK")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agolibgloss: riscv: Convert to non-recursive automake
Palmer Dabbelt [Tue, 23 Aug 2022 23:12:56 +0000 (16:12 -0700)]
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>
2 years agoCygwin: cwd: use SRWLOCK instead of muto
Corinna Vinschen [Tue, 23 Aug 2022 09:58:38 +0000 (11:58 +0200)]
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>
2 years agoCygwin: mmap: use SRWLOCK instead of muto
Corinna Vinschen [Tue, 23 Aug 2022 09:14:12 +0000 (11:14 +0200)]
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>
2 years agoCygwin: tls_pathbuf: Use Windows heap
Corinna Vinschen [Tue, 23 Aug 2022 08:59:18 +0000 (10:59 +0200)]
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>
2 years agoFix problem with _newlib_version.h not being filled in correctly
Jeff Johnston [Mon, 22 Aug 2022 21:54:43 +0000 (17:54 -0400)]
Fix problem with _newlib_version.h not being filled in correctly

2 years agoCygwin: smallprint.cc: Drop HEAP_ZERO_MEMORY
Corinna Vinschen [Mon, 22 Aug 2022 15:58:53 +0000 (17:58 +0200)]
Cygwin: smallprint.cc: Drop HEAP_ZERO_MEMORY

Leftover from testing.

Reported-by: Noel Grandin <noelgrandin@gmail.com>
Fixes: 07ec40170a32 ("Cygwin: smallprint.cc: Convert tmpbuf to lockless")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: posix_timer: fix formatting
Corinna Vinschen [Mon, 22 Aug 2022 12:50:54 +0000 (14:50 +0200)]
Cygwin: posix_timer: fix formatting

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: push missing change to debug.h
Corinna Vinschen [Mon, 22 Aug 2022 12:53:11 +0000 (14:53 +0200)]
Cygwin: push missing change to debug.h

Fixes: 48a210a457c5 ("Cygwin: debugging: convert muto to SRWLOCK")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: debugging: convert muto to SRWLOCK
Corinna Vinschen [Mon, 22 Aug 2022 12:38:49 +0000 (14:38 +0200)]
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>
2 years agoCygwin: shm: Convert muto into SRWLOCK and avoid overlocking
Corinna Vinschen [Mon, 22 Aug 2022 12:28:11 +0000 (14:28 +0200)]
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>
2 years agoCygwin: authz: Use dedicated locks per datastructure
Corinna Vinschen [Mon, 22 Aug 2022 12:25:05 +0000 (14:25 +0200)]
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>
2 years agoCygwin: spawn: don't overallocate SECURITY_ATTRIBUTES buffer
Corinna Vinschen [Mon, 22 Aug 2022 10:37:31 +0000 (12:37 +0200)]
Cygwin: spawn: don't overallocate SECURITY_ATTRIBUTES buffer

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: smallprint.cc: Convert tmpbuf to lockless
Corinna Vinschen [Mon, 22 Aug 2022 10:01:15 +0000 (12:01 +0200)]
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>
2 years agoCygwin: profiler: Fix linking when building with -DDEBUGGING
Corinna Vinschen [Sat, 20 Aug 2022 19:14:57 +0000 (21:14 +0200)]
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>
2 years agoCygwin: wchar.h: Fix comment
Corinna Vinschen [Sat, 20 Aug 2022 18:27:37 +0000 (20:27 +0200)]
Cygwin: wchar.h: Fix comment

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: sigproc.cc: drop Static macro, use explicit NO_COPY instead
Corinna Vinschen [Fri, 19 Aug 2022 19:55:09 +0000 (21:55 +0200)]
Cygwin: sigproc.cc: drop Static macro, use explicit NO_COPY instead

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop __fastcall calling convention specifiers
Corinna Vinschen [Fri, 19 Aug 2022 19:52:45 +0000 (21:52 +0200)]
Cygwin: drop __fastcall calling convention specifiers

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: miscfuncs.h: fix comment
Corinna Vinschen [Fri, 19 Aug 2022 13:46:27 +0000 (15:46 +0200)]
Cygwin: miscfuncs.h: fix comment

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoSH: Do not build syscalls if option provided
Yilin Sun via Newlib [Sat, 13 Aug 2022 16:22:50 +0000 (00:22 +0800)]
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>
2 years agonewlocale: fix crash when trying to write to __C_locale
Corinna Vinschen [Thu, 11 Aug 2022 17:27:48 +0000 (19:27 +0200)]
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>
2 years agoCygwin: move POSIX semaphore API functions to posix_ipc.cc
Corinna Vinschen [Wed, 10 Aug 2022 16:11:57 +0000 (18:11 +0200)]
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>
2 years agoCygwin: rename CygwinCreateThread to create_posix_thread
Corinna Vinschen [Wed, 10 Aug 2022 15:40:06 +0000 (17:40 +0200)]
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>
2 years agoCygwin: mm/malloc_wrapper.cc: fix a comment
Corinna Vinschen [Wed, 10 Aug 2022 14:56:07 +0000 (16:56 +0200)]
Cygwin: mm/malloc_wrapper.cc: fix a comment

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: move __caller_return_address to mm/malloc_wrapper.cc
Corinna Vinschen [Wed, 10 Aug 2022 15:07:52 +0000 (17:07 +0200)]
Cygwin: move __caller_return_address to mm/malloc_wrapper.cc

It's used in this file only anyway, so make it static inline.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: make import_address a static inline function
Corinna Vinschen [Wed, 10 Aug 2022 14:55:04 +0000 (16:55 +0200)]
Cygwin: make import_address a static inline function

It's used in malloc_init only and we never need it anywhere else,
hopefully.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: make check_invalid_virtual_addr a static inline function
Corinna Vinschen [Wed, 10 Aug 2022 16:03:05 +0000 (18:03 +0200)]
Cygwin: make check_invalid_virtual_addr a static inline function

move it to mm/mmap.cc which uses it exclusively.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: move memory management sources into mm subdir
Corinna Vinschen [Wed, 10 Aug 2022 14:09:39 +0000 (16:09 +0200)]
Cygwin: move memory management sources into mm subdir

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop building modelibs
Corinna Vinschen [Wed, 10 Aug 2022 14:28:12 +0000 (16:28 +0200)]
Cygwin: drop building modelibs

They never worked as desired anyway. Use the object files.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: fix return value of symlink_info::check
Ken Brown [Tue, 9 Aug 2022 19:14:07 +0000 (15:14 -0400)]
Cygwin: fix return value of symlink_info::check

Currently it is possible for symlink_info::check to return -1 in case
we're searching for foo and find foo.lnk that is not a Cygwin symlink.
This contradicts the new meaning attached to a negative return value
in commit 19d59ce75d.  Fix this by setting "res" to 0 at the beginning
of the main loop and not seting it to -1 later.

Also fix the commentary preceding the function definition to reflect
the current behavior.

Addresses: https://cygwin.com/pipermail/cygwin/2022-August/252030.html

2 years agoCygwin: pthreads: merge pthread.cc into thread.cc
Corinna Vinschen [Tue, 9 Aug 2022 20:48:43 +0000 (22:48 +0200)]
Cygwin: pthreads: merge pthread.cc into thread.cc

provide entire internal and external pthread API from inside the
same file.

While I dislike to have another even larger file, this is basically
cleaning up the source and grouping the external API into useful
chunks. Splitting the file cleanly is tricky due to usage of inline
methods is_good_object and verifyable_object_isvalid.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: stop exporting _alloca
Corinna Vinschen [Mon, 8 Aug 2022 16:16:09 +0000 (18:16 +0200)]
Cygwin: stop exporting _alloca

This is a remnant from 32 bit times, mindlessly copied into
the 64 bit export table.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: fold common.din and x86_64.din into cygwin.din
Corinna Vinschen [Mon, 8 Aug 2022 15:47:46 +0000 (17:47 +0200)]
Cygwin: fold common.din and x86_64.din into cygwin.din

We don't need a target-specific DEF file anymore

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: move mcountFunc.S to x86_64 target dir
Corinna Vinschen [Mon, 8 Aug 2022 14:48:57 +0000 (16:48 +0200)]
Cygwin: move mcountFunc.S to x86_64 target dir

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: x86_64: add wmemset assembler entry point
Corinna Vinschen [Mon, 8 Aug 2022 14:49:52 +0000 (16:49 +0200)]
Cygwin: x86_64: add wmemset assembler entry point

So far, wmemset used the C implemantation from newlib.  Let's use
the optimized assembler code instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: split out x86_64 memset/memcpy functions
Corinna Vinschen [Mon, 8 Aug 2022 14:25:41 +0000 (16:25 +0200)]
Cygwin: split out x86_64 memset/memcpy functions

move the assembler memset and memcpy functions into their own
assembler files.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: fhandler/null.cc: remove redundant includes topic/split_source_dir github/topic/split_source_dir
Corinna Vinschen [Fri, 5 Aug 2022 09:51:03 +0000 (11:51 +0200)]
Cygwin: fhandler/null.cc: remove redundant includes

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: update the "dirs" variable in Makefile.am
Ken Brown [Thu, 4 Aug 2022 20:59:16 +0000 (16:59 -0400)]
Cygwin: update the "dirs" variable in Makefile.am

Add the new fhandler and sec subdirs.

2 years agoCygwin: Reorganize cygwin source dir
Corinna Vinschen [Thu, 4 Aug 2022 14:58:50 +0000 (16:58 +0200)]
Cygwin: Reorganize cygwin source dir

Create subdirs and move files accordingly:

- DevDocs:  doc files
- fhandler: fhandler sources, split fhandler.cc into base.cc and null.cc
- local_includes: local include files
- scripts:  scripts called during build
- sec:      security sources

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: mount_info::get_mounts_here: alloc temp mountpoint info on cygheap
Corinna Vinschen [Fri, 5 Aug 2022 10:01:45 +0000 (12:01 +0200)]
Cygwin: mount_info::get_mounts_here: alloc temp mountpoint info on cygheap

That *should* be slightly faster than allocating on the user heap.

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