Commit Graph

13605 Commits

Author SHA1 Message Date
Corinna Vinschen a25730119c Cygwin: use .S suffix for assembler files
Automake generates different recipies for .s.o vs. .S.o rules.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-20 10:13:59 +01:00
Corinna Vinschen fd3ce87f73 Cygwin: check_reparse_point_target: fix comment format
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-20 10:13:59 +01:00
Jon Turney 8fdc201ec3
Cygwin: Update 3.4.3 release note
(cherry picked from commit 5366b3403c)
2022-12-16 13:36:22 +00:00
Jon Turney 242a2a5971
Revert "Cygwin: x86_64: add wmemset assembler entry point"
This reverts commit 188d5f6c9a.

(cherry picked from commit 98fa366cb6)
2022-12-16 13:36:06 +00:00
Corinna Vinschen 489300c89d Cygwin: add release message for latest path handling patch
5ba5e09b9d ("Cygwin: path handling: never substitute virtual drive with target path")

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-14 11:58:08 +01:00
Corinna Vinschen 90236c3a2c Cygwin: Makefile: build new-cygwin1.dll in a single step
The complicated build routine was only required because we needed
the .cygheap section at the end of the file, and the debug sections
broke this.  Now that the cygheap is out of the way, we really don't
have to do this anymore, and the build can just generate a DLL with
integrated debug info.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-13 14:16:13 +01:00
Corinna Vinschen f34db341fc Cygwin: Makefile: only regenerate cygwin_version.c if it changes
Make sure to create a new cygwin_version.c if it either doesn't
exist yet, or if it would be different from the former file.
This avoids unnecessary DLL rebuilding.

Fixes: 97eb64b909 ("Cygwin: uname: generate default release string from git as well")
Fixes: 4949a82cde ("Cygwin: uname: fix building in non-git source dir")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-13 14:16:13 +01:00
Corinna Vinschen 5ba5e09b9d Cygwin: path handling: never substitute virtual drive with target path
Move the drive substitution code after the call to
GetFinalPathNameByHandleW into a local function revert_virtual_drive
and add code to handle non-remote virtual drives, i. e., those
created with the subst command.  (Try to) make sure that virtual
drives are never treated like symlinks.

Fixes: 19d59ce75d ("Cygwin: path_conv: Rework handling native symlinks as inner path components")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-12 21:56:14 +01:00
Corinna Vinschen 45794e0d66 Cygwin: add 3.4.2 release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-11 11:45:36 +01:00
Takashi Yano faac79783c Cygwin: pty: Use GetTickCount64() instead of GetTickCount().
Suggested-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2022-12-09 21:01:42 +09:00
Takashi Yano be635ebc2f Cygwin: pipe: Fix performance degradation for non-cygwin pipe.
https://cygwin.com/pipermail/cygwin/2022-December/252628.html

After the commit 9e4d308cd5, the performance of read from non-cygwin
pipe has been degraded. This is because select_sem mechanism does not
work for non-cygwin pipe. This patch fixes the issue.

Fixes: 9e4d308cd5 ("Cygwin: pipe: Adopt FILE_SYNCHRONOUS_IO_NONALERT
flag for read pipe.")
Reported-by: tryandbuy <tryandbuy@proton.me>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2022-12-09 21:01:29 +09:00
Corinna Vinschen 3a910b624a Cygwin: improve release text for FILE issue
Add a note in terms of 3.4.0 compatibility.

Suggested-by: Markus Mützel <markus.muetzel@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-09 12:41:54 +01:00
Corinna Vinschen 55de3fdd0e Cygwin: define FILE as struct __sFILE64, not as __sFILE
Until Cygwin 3.3.6, we define __LARGE64_FILES unconditionally, so we
were using the type __sFILE64 even for 64 bit.  That was lazy and wrong.
so commit 2902b3a09e ("Cygwin: drop requirement to build newlib's
stdio64") tried to fix that.

Unfortunately this patch forgot to take the exposure of the typename
__sFILE64 in userspace into account.  This leads to trouble in C++ due
to name mangling.

Commit 0f376ae220 tried to fix this by just renaming __sFILE to
__sFILE64 by using a macro.  While __sFILE and __sFILE64 are the same
size, they are not exactly congruent.

To avoid backward compatibility problems, make sure to define FILE
as the  real __sFILE64, and make sure that __sFILE is not defined at
all on Cygwin.

Fixes: 0f376ae220 ("Cygwin: rename __sFILE to __sFILE64 for backward
compatibility")
Fixes: 2902b3a09e ("Cygwin: drop requirement to build newlib's stdio64")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-08 17:16:20 +01:00
Corinna Vinschen 6429a7a7f6 Cygwin: add __sFILE64 fix to 3.4.1 release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-08 14:19:22 +01:00
Corinna Vinschen 0f376ae220 Cygwin: rename __sFILE to __sFILE64 for backward compatibility
Until Cygwin 3.3.6, we define __LARGE64_FILES unconditionally, so we
were using the type __sFILE64 even for 64 bit.  That was lazy and wrong.
so commit 2902b3a09e ("Cygwin: drop requirement to build newlib's
stdio64") tried to fix that.

Unfortunately this patch forgot to take the exposure of the typename
__sFILE64 in userspace into account.  This leads to trouble in C++ due
to name mangling.

Fix this by redefining __sFILE to __sFILE64.  The type name is very much
internal, so it doesn't really matter, except for the fact that it needs
to stay backward compatible so as not to break building against C++ libs
built under older versions of Cygwin.

Fixes: 2902b3a09e ("Cygwin: drop requirement to build newlib's stdio64")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-08 13:58:37 +01:00
Corinna Vinschen 53ea7b2d5a Cygwin: drop unused local declaration of fopen64
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-08 13:04:03 +01:00
Corinna Vinschen 4949a82cde Cygwin: uname: fix building in non-git source dir
commit 97eb64b909 broke building outside of a git dir, because
the git describe command would fail.  Fix this by checking if
we're in a git tree at all and just generate an empty string
as version string.  Use this in uname_x to generate a fallback
version.

Fixes: 97eb64b909 ("Cygwin: uname: generate default release
string from git as well"
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-07 22:22:38 +01:00
Corinna Vinschen 97eb64b909 Cygwin: uname: generate default release string from git as well
When building a release with cygport, we get uname version info
from cygport, which in turn gets version info from `git describe'.

During development, the release info for local builds was not
that helpful yet.  Fix that, by creating version info from
`git describe' if CYGPORT_RELEASE_INFO isn't given.  Make sure to
always force rebuild of the version info to pick up source file
changes as well as git actions.

Rearrange code slightly to generate machine info first, release info
after that.  Use snprintf to generate release string safely.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-07 21:30:23 +01:00
Corinna Vinschen 792b1c6a6d Cygwin: add missing pragma
Add missing "#pragma GCC diagnostic push" to the pragma bracket
guarding the srandom call.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-07 21:18:24 +01:00
Corinna Vinschen 95f5b0a620 Cygwin: link mcountFunc.o to libgmon.a
Commit 188d5f6c9a erroneously moved the mcountFunc.S file to the
TARGET_FILES target, rather than keeping it in GMON_FILES.  The
result is that the __fentry__ entry point is now entirely undefined,
so `gcc -pg' is broken.

Create new target-specific GMON_TARGET_FILES and move mcountFunc.S
into it.  Add $(GMON_TARGET_FILES) to GMON_FILES.

Fixes: 188d5f6c9a ("Cygwin: x86_64: add wmemset assembler entry point")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-07 12:28:33 +01:00
Corinna Vinschen e9d843ec74 Cygwin: Add 3.5.0 release file
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-07 12:19:49 +01:00
Corinna Vinschen a3ae2a7348 Cygwin: don't autoload some kernel32 functions
DiscardVirtualMemory, PrefetchVirtualMemory and
GetSystemTimePreciseAsFileTime are available since
Windows 8.1.  Merge PseudoConsole functions into
kernel32 function block.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:03:07 +01:00
Corinna Vinschen 7d2c5efffa Cygwin: drop special handling for SID authority 18
This was only required up to Windows 8.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:03:02 +01:00
Corinna Vinschen df680fb62d Cygwin: flock: drop checking for artificial console handles
They have been used up to Windows 7 only.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen a3af720dee Cygwin: fix a few comments mentioning Windows 7 or 8
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen 6951d258eb Cygwin: simplify FAST_CWD access
Dropping Windows 7 and 8 also drops the need to handle three
different FAST_CWD structures.  Simplify code accordingly.

While at it, use dynamic allocation of the FAST_CWD structure
based on the length of the CWD path.  This may help in future
to enable working with systems and native apps with long paths
enabled (Win 10 1607 and later), see
https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen 21d098eab1 Cygwin: drop wincaps for Windows 7 and Windows 8
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen ef741db52b Cygwin: drop wincap::def_guard_pages
Only required for Windows 7.  Define constant value
DEFAULT_GUARD_PAGE_COUNT instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen ae2829a226 Cygwin: drop wincap::mmap_storage_high
Only required for Windows 7 and Windows 8.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen 8af023a357 Cygwin: drop wincap::cons_need_small_input_record_buf
Only required for Windows 7.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen 08cd9cfc5c Cygwin: drop wincap::has_broken_attach_console
Only required for Windows 7.

This in turn allows to drop the helper_pid and related
methods from fhandler_pty_common.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen 4e40b21464 Cygwin: drop wincap::has_query_process_handle_info
Only required for Windows 7.

This allows to remove fhandler_pipe::get_query_hdl_per_system(),
too.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen c3c71e39f9 Cygwin: drop wincap::has_broken_whoami
Unused for some time. Was only required for Windows 7 anyway.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen 5478c5a9ec Cygwin: drop wincap::has_microsoft_accounts
Only required for Windows 7.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen 70d77662f5 Cygwin: drop wincap::has_precise_system_time
Only required for Windows 7.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen 48953788b3 Cygwin: drop wincap::needs_query_information
Only required for Windows 7 and 8.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 14:01:41 +01:00
Corinna Vinschen b541558b7a Cygwin: bump DLL version to 3.5.0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04 13:51:30 +01:00
Corinna Vinschen 07a9a6c21a Cygwin: add release message for commit previous commit 8d138c3f66
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-03 16:36:49 +01:00
Corinna Vinschen b6fcdd03ed Cygwin: add latest primary group changes to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-03 16:12:49 +01:00
Corinna Vinschen cf65cbcea4 Cygwin: FAQ: convert ulinks to FAQ to xrefs
Using ulinks here makes the result work on cygwin.com only, while
xrefs to FAQs are creating realtive links.  Add xreflabel where
appropriate.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-02 22:38:47 +01:00
Corinna Vinschen 08f33e5b6a Cygwin: FAQ: describe test releases, deprecate developer snapshots
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-02 21:54:19 +01:00
Corinna Vinschen a5bcfe616c Cygwin: uinfo: don't special case current user
fetch_account_from_windows shortcuts the current user in that
it takes the user's domain SID and just adds the matching RID
from the token's primary group to create a group SID.

How wrong this is can be very simply reproduced:

Assuming you run a native process, like cmd, with primary group
set to the Administrators builtin group.  Run Cygwin's id(1) as
child process.  id(1) will print a non-existent group as primary
group and also add it to the group list.

This can only be avoided by not special casing the current user
and thus not creating a group SID from partial information.

Fixes: 6cc7c925ce ("(pwdgrp::fetch_account_from_windows): Default primary group for the
current user to primary group from user token.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-02 16:49:47 +01:00
Corinna Vinschen dc7b67316d Cygwin: uinfo: prefer token primary group
internal_getlogin overwrites the process token primary group if it
differs from the primary group as stored in the passwd DB.

However, this also overwrites the primary group of the process if
it has been deliberately changed by a former process (e. g., newgrp),
and the current process has a non-Cygwin process as parent.

Our docs claim we restrict overwriting the primary group to local,
non-domain user accounts anyway, and it was actually meant this way.

So check for exactly that before overwriting the primary group
in the token:  It's only allowed if the user is a local account
and the primary group in the token is still the default group
"None".

Fixes: 6cc7c925ce ("(internal_getlogin): Give primary group
from user token more weight.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-02 16:37:33 +01:00
Corinna Vinschen 3b37a11870 Cygwin: uinfo: Drop long disabled nss_prefix and nss_separator
Originally the code was written to allow three ways of prefixing
accounts and to freely define a domain/account separator.  This code
has been disabled even before being officially released, and it was
never re-enabled. Given there has been no complaints for eight years
now, drop this code eventually.  Just add a macro to define the
domain/account separator statically.

Fixes: cc332c9e27 ("(cygheap_pwdgrp::nss_init_line): Disable db_prefix
and db_separator settings.  Add comment")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-02 16:35:31 +01:00
Corinna Vinschen 30add3e6b3 Cygwin: exec: don't access cygheap before it's initialized
This is a long-standing thinko.

When you exec a process, dll_crt0_0 in the child process calls
child_info_spawn::handle_spawn().  handle_spawn() initialises the
cygheap.

Now consider calling strace.  Strace is a non-Cygwin process dynamically
loading cygwin1.dll via LoadLibrary.  This in turn initializes the DLL:

- dll_crt0_0 finds that the process it attaches to has been exec'd, so
  child_info_spawn::handle_spawn() is called.

- If the DLL is being dynamically loaded, handle_spawn() calls
  child_info_spawn::get_parent_handle().  This in turn tries to set
  the moreinfo->myself_pinfo value inside the cygheap to NULL.

- However, at this time, the cygheap has not yet been initialized.  This
  only occurs in the cygheap_fixup_in_child() call after get_parent_handle()
  returns.

--> SEGV

This thinko never had a negative side effect, because the cygheap was
pre-allocated at DLL load time until commit 2f9b8ff00c ("Cygwin:
decouple cygheap from Cygwin DLL").  With 2f9b8ff00c, the cygheap
actually doesn't exist until after the call to cygheap_fixup_in_child().

Fix this problem by moving the assignment after the call to
cygheap_fixup_in_child().

Fixes: 3de7be4c1d ("* DevNotes: Add entry cgf-000007. [...]")
Fixes: 2f9b8ff00c ("Cygwin: decouple cygheap from Cygwin DLL")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-01 22:34:53 +01:00
Corinna Vinschen e358f8d12f Cygwin: multiple_cygwin_problem: drop obsolete check for "cygheap"
After decoupling cygheap from the DLL loading address, the check
for a different _cygheap_start has gone.  So the matching string
check in multiple_cygwin_problem is obsolete now.

Fixes: 2f9b8ff00c ("Cygwin: decouple cygheap from Cygwin DLL")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-01 21:20:53 +01:00
Carlo Bramini a263fe0b26 Cygwin: serial: Fix a copy-paste error in DTR setup
In commit 2dab880c96 I did a mistake when
I copied the new fhandler_serial::switch_modem_lines() from my modified
3.3.6 branch to the current master and I left a copy paste error. This
patch fixes that error.

Fixes: 2dab880c96 ("Cygwin: fix TIOCMBIS/TIOCMBIC not working when using usbser.sys")
2022-11-29 11:47:27 +01:00
Jon Turney 17761a8ef4
Cygwin: Update some mentions of x86 in documentation 2022-11-28 15:55:42 +00:00
Jon Turney 8080c85630
Cygwin: Fix typo in FAQ
The consonant in 'debug' is doubled in 'debuggee' just as it is in
'debugger'.

Fixes: 8c68a8a4
2022-11-28 15:17:52 +00:00
Takashi Yano 2e4ecbb3f0 Cygwin: pty: Rename fhandler/tty.cc to fhandler/pty.cc.
- Previously, we have two tty.cc, one is winsup/cygwin/tty.cc and
  the other is winsup/cygwin/fhandler/tty.cc. This is somewhat
  confusing. This patch renames fhandler/tty.cc to fhandler/pty.cc.
2022-11-25 09:33:27 +09:00
Corinna Vinschen afa957ae5b Cygwin: uname: allow to specify external release info
When creating regular Cygwin test releases we need a way to
automate unambiguous version information based on the output
of `git describe'.  Allow to inject a release string via a
preprocessor macro CYGPORT__RELEASE_INFO.  Change the default
release info to recognize a local, non-distro build.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-11-24 20:49:35 +01:00
Corinna Vinschen 244be41a1f Cygwin: drop snapshot handling
We're going to switch to regular test releases, rather than the
old, handcrafted snapshots method.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-11-24 12:20:50 +01:00
Takashi Yano 32d6a6cb5f Cygwin: pty, console: Encapsulate spawn.cc code related to pty/console.
- The codes related to pty and console in spawn.cc have been moved
  into the new class fhandler_termios::spawn_worker, and make spawn.cc
  call them. The functionality has not been changed at all.
2022-11-20 10:37:37 +09:00
Corinna Vinschen bd4bed1254 Cygwin: document bugfix for USB CDC devices
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-11-11 13:09:45 +01:00
Carlo Bramini 2dab880c96 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.
2022-11-11 13:01:23 +01:00
Andy Koppe 59b8ee7d70 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.
2022-11-10 10:07:05 +01:00
Jon Turney 8c68a8a489
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
2022-11-04 13:25:56 +00:00
Jon Turney 564c88b898
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
2022-11-04 13:25:54 +00:00
Jon Turney 9b89811c9f
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
2022-10-29 18:22:40 +01:00
Jon Turney d59651d4da
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 (000180048055, 000180046FA0, 000000000002, 00018031E160) segv-test.exe+0x10E9
> 0007FFFFCD30  0001800480C1 (000000000000, 000000000000, 000000000000, 000000000000) cygwin1.dll+0x80C1
> 0007FFFFFFF0  000180045C86 (000000000000, 000000000000, 000000000000, 000000000000) cygwin1.dll+0x5C86
> 0007FFFFFFF0  000180045D34 (000000000000, 000000000000, 000000000000, 000000000000) 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
2022-10-28 16:04:49 +01:00
Jon Turney 4a67f89ced
Cygwin: Tidy up formatting of stackdump
Resize stackdump headers for b9e97f58
Consistently use \r\n line endings
2022-10-28 16:03:36 +01:00
Corinna Vinschen 3e80956d63 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: 61522196c7 ("* Merge in cygwin-64bit-branch.)"
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-28 17:02:05 +02:00
Corinna Vinschen 389f071f44 Cygwin: document ASLR support
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-28 16:26:53 +02:00
Corinna Vinschen 943433b00c Cygwin: Enable dynamicbase on the Cygwin DLL by default
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-28 16:26:53 +02:00
Corinna Vinschen a3f1eff388 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>
2022-10-28 16:26:53 +02:00
Corinna Vinschen ebbff10ae1 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>
2022-10-28 16:26:53 +02:00
Corinna Vinschen 49df152de7 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>
2022-10-28 16:26:53 +02:00
Corinna Vinschen 0508e11f88 Cygwin: memory_layout.h: fix comments
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-28 16:26:53 +02:00
Corinna Vinschen 60675f1a7e 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>
2022-10-28 16:26:53 +02:00
Corinna Vinschen 2f9b8ff00c 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().
2022-10-28 16:26:53 +02:00
Corinna Vinschen c0776fa7ba 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>
2022-10-28 16:26:53 +02:00
Corinna Vinschen b9e97f58aa 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: e1254add73 ("Cygwin: Allow accessing 48 bit address space in Windows 8.1 or later")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-28 16:24:00 +02:00
Corinna Vinschen eaa51ea459 Cygwin: add missing .com entry in new-features.xml
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-28 13:02:20 +02:00
Corinna Vinschen 339bb6e932 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>
2022-10-28 12:44:27 +02:00
Corinna Vinschen 213b53ed35 Revert "Cygwin: pty: Fix 'Bad address' error when running 'cmd.exe /c dir'"
This reverts commit 7589034cc3.

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>
2022-10-28 12:43:56 +02:00
Corinna Vinschen f33635ae60 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>
2022-10-28 12:43:56 +02:00
Corinna Vinschen 1fc3014728 Cygwin: utils: drop 32 bit considerations
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-28 11:37:02 +02:00
Corinna Vinschen f51e76da0a Cygwin: regtool: drop 32 bit hint from help output
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-28 11:01:56 +02:00
Corinna Vinschen 762dcfc658 Cygwin: document dropping 32 bit support
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-27 21:45:52 +02:00
Hamish McIntyre-Bhatty b563f5974f Fix typo in faq-programming.xml 2022-10-27 13:23:40 +02:00
Brian Inglis 7f7e4e5bc5 strptime.cc(__strptime): add %q GNU quarter 2022-10-24 14:09:07 +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
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
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
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
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
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