Commit Graph

9452 Commits

Author SHA1 Message Date
Corinna Vinschen 25937aa1d0 Cygwin: /proc/<PID>/status: fix format specifier
The format specifier used for the signal masks is incorrectly
assuming 32 bit values.  Fix it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-03-01 16:23:24 +01:00
Takashi Yano aec053c60c Cygwin: pty: Rename some functions/variables with the name *pcon*.
- With this patch, some pty functions/variables have been renamed
  so that the name *pcon* is not used for those that are called
  even when the pseudo console is not active.
2022-03-01 22:09:01 +09:00
Corinna Vinschen 3e11a002b3 Cygwin: sysconf: _SC_TZNAME_MAX: return -1 as valid value
sysconf incorrectly sets errno to EINVAL for _SC_TZNAME_MAX.
Don't do that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-03-01 11:43:52 +01:00
Takashi Yano 1e6c51d741 Cygwin: pty: Reorganize the code path of setting up and closing pcon.
- This patch reorganizes the code path of setting-up and cleaning-up
  of the pseudo console to improve readability and maintainability
  of pty code.
2022-03-01 19:40:55 +09:00
Takashi Yano fbfea31dd9 Cygwin: pty: Avoid cutting the branch the pty master is sitting on.
- When Ctrl-C terminates a non-cygwin process on a pseudo console,
  pty master attaches to the pseudo console first, and send
  CTRL_C_EVENT. If the non-cygwin process closes the pseudo console
  before the pty master calls FreeConsole(), the pty master process
  will crash. With this patch, pty master process takes over the
  ownership of the pseudo console, and closes it by myself.
2022-03-01 19:40:46 +09:00
Takashi Yano 95a28b1f9e Cygwin: pty: Isolate CTRL_C_EVENTs between ptys.
- With this patch, unique invisible consoles are created for each pty
  to isolate CTRL_C_EVENTs between ptys. This is necessary by Ctrl-C
  handling in fhandler_termios::process_sigs() for non-cygwin apps
  started in pty if the pseudo console is disabled.
2022-02-28 20:25:09 +09:00
Takashi Yano 8ff9f216fd Cygwin: console: Improve the code to avoid typeahead key swapping.
- The commit "Cygwin: console: Prevent the order of typeahead input
  from swapped." did not fully resolve the issue. If keys are typed
  during input buffer fix, the order of key event may be swapped.
  This patch fixes the issue again.
2022-02-28 20:17:12 +09:00
Takashi Yano f6db6f52ae Cygwin: pinfo: Fix exit code for non-cygwin apps which reads console.
- The recent commit "Cygwin: pinfo: Fix exit code when non-cygwin app
  exits by Ctrl-C." did not fix enough the issue. If a non-cygwin app
  is reading the console, it will not return STATUS_CONTROL_C_EXIT
  even if it is terminated by Ctrl-C. As a result, the previous patch
  does not take effect.
  This patch solves this issue by setting sigExeced to SIGINT in
  ctrl_c_handler(). In addition, sigExeced will be cleared if the app
  does not terminated within predetermined time period. The reason is
  that the app does not seem to be terminated by the signal sigExeced.
2022-02-28 20:10:02 +09:00
Takashi Yano 15a35758d8 Cygwin: termios: Ensure detection of GDB inferior in process_sigs().
- In some situations, some cygwin processes might wrongly identified
  as GDB inferior. This patch ensures the detection of GDB inferior.
2022-02-28 08:00:16 +09:00
Takashi Yano 33d8578feb Cygwin: termios: Add comments to the code refactored recently.
- This patch adds some comments to the source code whose intent may
  not be clear enough from the code which is refactored recently.
2022-02-27 20:50:53 +09:00
Takashi Yano d857df6f08 Cygwin: console: Correct the past fix for apps which open pty.
- The commit "Cygwin: console: Fix issues of apps which open pty."
  did not fix the second problem correctly. That commit looked to
  fix the issue, but the actual problem was that ctrl_c_handler()
  should be reregistered *AFTER* FreeConsole()/AttachConsole().
  This patch correct that.
2022-02-27 12:46:05 +09:00
Takashi Yano 696a713bf2 Cygwin: console: Revert experimental code mixed accidentally.
- The commit "Cygwin: console: Restore CTRL_BREAK_EVENT handling."
  was accidentally mixed with experimental code in exceptions.cc.
  Due to this, non-cygwin app receives CTRL_C_EVENT twice in the
  following scenario.
   1) Run 'sleep 10 | <non-cygwin app>'
   2) Hit Ctrl-C.
   3) The non-cygwin app receives CTRL_C_EVENT twice.
  This patch reverts the code with the problem.
2022-02-27 00:34:30 +09:00
Takashi Yano 95a60b7fdd Cygwin: console: Prevent the order of typeahead input from swapped.
- If a lot of keys are typed very quickly in the app which does
  not read console, the order of input keys in console input buffer
  occasionally swapped. Although this extremely rarely happens,
  is obviously a bug of cons_master_thread. This patch fixes the
  issue.
2022-02-26 15:59:54 +09:00
Takashi Yano e9d4341677 Cygwin: pty: Stop to send CTRL_C_EVENT if pcon activated.
- The commit "Cygwin: console: Redesign handling of special keys."
  removes special treatment for pty in with pseudo console activated,
  however, it is necessary on second thought. This is because sending
  CTRL_C_EVENT to non-cygwin apps will be done in pseudo console,
  therefore, sending it in fhandler_pty_master::write() duplicates
  that event for non-cygwin apps.
2022-02-26 15:59:32 +09:00
Takashi Yano 32401ad98e Cygwin: console: Fix issues of apps which open pty.
- After some recent changes for special keys handling break the
  apps which open pty (such as script command). If the app which
  opens pty is executed in console, the following issues occur.
    1) If the script command was started from non-cygwin shell
       (such as cmd.exe), another cygwin app started in pty slave
       cannot receive Ctrl-C.
    2) If non-cygwin app is executed in pty slave, the app which
       opened the pty (e.g. script command) crashes by Ctrl-C.
  This patch fixes these issues.
2022-02-26 15:59:20 +09:00
Takashi Yano 3a6b11c697 Cygwin: pinfo: Fix exit code when non-cygwin app exits by Ctrl-C.
- Previously, if non-cygwin app exits by Ctrl-C, exit code was
  0x00007f00. With this patch, the exit code will be 0x00000002,
  which means process exited by SIGINT.
2022-02-25 17:29:28 +09:00
Takashi Yano 5c4a0824e7 Cygwin: console: Restore CTRL_BREAK_EVENT handling.
- The recent change by the commit "Cygwin: console: Redesign handling
  of special keys." breaks the handling of CTRL_BREAK_EVENT. The login
  shell in console exits on Ctrl-Break key. This patch fixes the issue.
2022-02-24 17:35:21 +09:00
Takashi Yano 2f2b915505 Cygwin: pty, console: Add a workaround for GDB SIGINT handling.
- The inferior of the GDB cannot be continued after SIGINT even
  though nopass option is set. This seems because cygwin GDB does
  not support hooking cygwin signal. Therefore, a workaround for
  GDB is added. With this patch, only CTRL_C_EVENT is sent to the
  GDB inferior by Ctrl-C and sending SIGINT is omitted. Note that
  "handle SIGINT (no)pass" command does not take effect even with
  or without this patch.
2022-02-24 02:17:32 +09:00
Takashi Yano d2b14c303c Cygwin: console: Redesign handling of special keys.
- This patch rearranges the cooperation between cons_master_thread,
  line_edit, and ctrl_c_handler so that only one of them operates
  at the same time. Since these handle Ctrl-C individually, so the
  signal may be sent multiple times to the process. This patch fixes
  the issue.
2022-02-24 01:38:08 +09:00
Corinna Vinschen f2dc492df0 Cygwin: unlink: filter out virtual files and devices early on
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-22 13:33:06 +01:00
Johannes Schindelin 4ec08891a0 Cygwin: Implicitly support the /dev/fd symlink and friends
Bash has a very convenient feature that is called process substitution
(e.g. `diff -u <(seq 0 10) <(seq 1 11)`). To make this work, Bash
requires the `/dev/fd` symlink to exist, and Cygwin therefore creates
this symlink (together with the `stdin`, `stdout` and `stderr` ones)
upon start-up.

This strategy is incompatible with the idea of providing a subset of
Cygwin in a `.zip` file (because there is no standard way to represent
symlinks in `.zip` files, and besides, older Windows versions would
potentially lack support for them anyway).

That type of `.zip` file is what Git for Windows wants to use, though,
bundling a minimal subset for third-party applications in MinGit (see
https://github.com/git-for-windows/git/wiki/MinGit for details).

Let's side-step this problem completely by creating those symlinks
implicitly, similar to the way `/dev/` is populated with special
devices.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2022-02-22 13:33:00 +01:00
Corinna Vinschen 8bb6821c7a Cygwin: Adjust path to newlib libc.a, too
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-22 12:49:33 +01:00
Jon Turney 56ec1fcb0d Cygwin: Adjust path to newlib libm.a in builddir
Adjust path to newlib libm.a in builddir, changed by ac9f8c46
2022-02-22 12:49:33 +01:00
Matt Joyce 44b60f0c4b Make __sdidinit unused
Remove dependency on __sdidinit member of struct _reent to check
object initialization. Like __sdidinit, the __cleanup member of
struct _reent is initialized in the __sinit() function. Checking
initialization against __cleanup serves the same purpose and will
reduce overhead in the __sfp() function in a follow up patch.
2022-02-22 12:38:46 +01:00
Takashi Yano 054b00d96a Cygwin: pty: Encapsulate pty code in tty::setpgid().
- This patch hides complex pty codes in tty::setpgid() to transfer
  input into the class fhandler_pty_slave by encapsulating it.
2022-02-22 07:33:09 +09:00
Takashi Yano 0ddf19d6ca Cygwin: pty, console: Fix handle leak which occurs on exec() error.
- This patch fixes the handle leak which occurs when exec() fails
  with an error. The duplicated handles will be closed when the
  exec'ed process is terminated. However, if exec() fails, the code
  path does not reach to the code closing the duplicated handles.
  To implement this fix more appropriately, the setup, cleanup and
  closing pty codes which was previously located in spawn.cc are
  encapsulated into the fhandler_pty_slave class functions.
2022-02-22 07:26:34 +09:00
Takashi Yano fc26624377 Cygwin: console: Call fix_tab_position() only if having broken tabs.
- Calling fix_tab_position() is necessary in Windows 10 with xterm
  compatible mode enabled, because it has a problem that the tab
  positions will be broken when the window size is changed. Fortunately,
  this problem has been fixed in Windows 11. Therefore, with this patch,
  necessity of fix_tab_position() call is determined by referring to
  wincap.has_con_broken_tabs(), which is recently introduced.
2022-02-20 19:22:09 +09:00
Takashi Yano 29d8a83008 Cygwin: console: Rearrange set_(in|out)put_mode() calls.
- With this patch, all set_(in|out)put_mode() calls are rearranged
  as follows.

  1) Setup for cygwin apps, started from non-cygwin app, is done
     in fhandler_console::post_open_setup(), which overrides
     fhandler_base::post_open_setup() called from dtable.cc.
  2) Cleanup for cygwin app is done in fhandler_console::close().
  3) Setup for cygwin apps is also in fhandler_console::bg_check(),
     which overrides fhandler_termios::bg_check(). This is called
     on read(), write() and select() for console. It is necessary
     if cygwin and non-cygwin apps are started simultaneously in
     the same process group.
  4) Setup for non-cygwin apps is done in spawn.cc via
     fhandler_console::setup_console_for_non_cygwin_app().
  5) Cleanup for non-cygwin app is done in spawn.cc vid
     fhandler_console::cleanup_console_for_non_cygwin_app().
  6) Setup for non-cygwin app started by GDB is done in
     fhandler_console::set_console_mode_to_native().
  7) No explicit cleanup for non-cygwin app started by GDB, because
     console mode is automatically reset to tty::cygwin on read()/
     write() in GDB thanks to 3).
2022-02-20 19:22:02 +09:00
Takashi Yano 2cab4d0bb4 Cygwin: pty, console: Refactor the code processing special keys.
- This patch commonize the code which processes special keys in pty
  and console to improve maintanancibility. As a result, some small
  bugs have been fixed.
2022-02-20 19:21:51 +09:00
Takashi Yano 9f1930bf34 Cygwin: wincap: Add capabilities for Windows 11.
- The capability changes since Windows 11 have been reflected in
  wincap.cc. The capability has_con_broken_tabs is added, which is
  false since Windows 11.
2022-02-16 19:59:14 +09:00
Brian Inglis 97b8a93b3c fhandler_proc.cc(format_proc_cpuinfo): fix bad bits in last change
move Linux 5.16 Gobble Gobble flags to 5.17 Superb Owl correct positions:
0x00000007:1 Intel Advanced Matrix eXtensions:
		 EAX:22 amx_bf16 Brain Float 16 dot product
		 EAX:24 amx_tile Tile matrix multiply
		 EAX:25 amx_int8 Int 8 byte dot product
0x00000007:0 Intel Advanced Matrix eXtensions:
		 EDX:22 amx_bf16 Brain Float 16 dot product
		 EDX:24 amx_tile Tile matrix multiply
		 EDX:25 amx_int8 Int 8 byte dot product
2022-02-16 09:31:32 +01:00
Takashi Yano dd65342315 Cygwin: console: Set console mode even if stdin/stdout is redirected.
- When non-cygwin app is started in console, console mode is set to
  tty::native. However, if stdin is redirected, current code does not
  set the input mode of the console. In this case, if the app opens
  "CONIN$", the console mode will not be appropriate for non-cygwin
  app. This patch fixes the issue.

Addresses:
https://github.com/GitCredentialManager/git-credential-manager/issues/576
2022-02-13 23:55:59 +09:00
Takashi Yano cb0e392903 Cygwin: console: Fix console mode for non-cygwin inferior of GDB.
- Currently, there is no chance to change console mode for non-cygwin
  inferior of GDB. With this patch, the console mode is changed to
  tty::native in CreateProcess() and ContinueDebugEvent() hooked in
  fhandler_console.
2022-02-13 23:55:59 +09:00
Takashi Yano bed1add783 Cygwin: pty: Fix a bug in tty_min::segpgid().
- In tty_min::setpgid(), a pointer to fhandler instance is casted to
  fhandler_pty_slave and accessed even if terminal is not a pty slave.
  This patch fixes the issue.
2022-02-13 23:55:59 +09:00
Takashi Yano c4704c7c20 Cygwin: pty: Discard input in from_master_nat pipe on signal as well.
- Currently, pty discards input only in from_master pipe on signal.
  Due to this, if pty is started without pseudo console support and
  start a non-cygwin process from cmd.exe, type adhead input is not
  discarded on signals such as Ctrl-C. This patch fixes the issue.
2022-02-13 23:55:59 +09:00
Takashi Yano b958e1f03a Cygwin: pty: Revise the code to wait for completion of forwarding.
- With this patch, the code to wait for completion of forwarding of
  output from non-cygwin app is revised so that it can more reliably
  detect the completion.
2022-02-13 23:55:59 +09:00
Takashi Yano bddd9c1c41 Cygwin: pty: Prevent deadlock on echo output.
- If the slave process writes a lot of text output, doecho() can
  cause deadlock. This is because output_mutex is held in slave::
  write() and if WriteFile() is blocked due to pipe full, doecho()
  tries to acquire output_mutex and gets into deadlock. With this
  patch, the deadlock is prevented on the sacrifice of atomicity
  of doecho().
2022-02-13 23:55:59 +09:00
Takashi Yano b04aea00f1 Cygwin: pty: Pass Ctrl-Z (EOF) to non-cygwin apps with disable_pcon.
- Previously, non-cygwin app running in pty started without pseudo
  console support was suspended by Ctrl-Z rather than sending EOF.
  Even worse, suspended app could not be resumed by fg command. With
  this patch, Ctrl-Z (EOF for non-cygwin apps) is passed to non-cygwin
  app instead of suspending that app. This patch also handles Ctrl-\
  (QUIT) and Ctrl-D (EOF) as well.
2022-02-13 23:55:59 +09:00
Takashi Yano c05c36a7c8 Cygwin: pty, console: Fix Ctrl-C handling for non-cygwin apps.
- Currently, if cat is started from cmd.exe which is started in cygwin
  console, Ctrl-C terminates not only cat but also cmd.exe. This also
  happens in pty in which pseudo console is disabled. This patch fixes
  the issue.
2022-02-13 23:55:59 +09:00
Mitchell Hentges 8a95249d73 Cygwin: console: Maintain ENABLE_(INSERT|QUICK_EDIT)_MODE flags.
- Currently, ENABLE_INSERT_MODE and ENABLE_QUICK_EDIT_MODE are cleared
  if cygwin is started in console. These flags will not be recovered
  even when exiting from cygwin. Also note that if ENABLE_EXTENDED_FLAGS
  is once unset, then the flag ENABLE_QUICK_EDIT_MODE it's associated
  with will no longer be preserved. Unfortunately, we're accidentally
  stepping on this in fhandler_console::set_input_mode().

  This patch solves this by carrying forward these flags in the place
  where it had been ignoring them. Since the previous behaviour of
  leaving these flags unset would essentially maintain their existing
  state, adding the carry-over of the flags now should not alter console
  behaviour.
2022-02-11 09:07:30 +09:00
Takashi Yano 7e6422fd2a Cygwin: wincap: Add capabilities for Windows 10 2004 and newer.
- The capability changes since Windows 10 2004 have been reflected
  in wincap.cc. (has_con_broken_il_dl has been changed to false.)
2022-02-05 19:28:34 +09:00
Corinna Vinschen c3efc81658 Cygwin: drop dllfixdbg script
On second thought, we don't actually need this script.
Express the entire action as sufficiently simple Makefile rule.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-05 10:42:27 +01:00
Takashi Yano 44d8704179 Cygwin: console: Remove unnecessary (redundant) code. 2022-02-05 16:55:12 +09:00
Corinna Vinschen 899cf3c952 Cygwin: fix dependency to dllfixdbg script
Only the files created from cygwin0.dll depend on the script, not
cygwin0.dll as well.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-04 18:27:14 +01:00
Corinna Vinschen 820c736785 Cygwin: dllfixdbg: improve readability
- formatting
- use array pointer as argument rather than variable arguments
- syntactical fixes
- add comments
- drop unnecessary recomputation of all section VMAs.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-04 18:27:14 +01:00
Corinna Vinschen 4aeba49016 Cygwin: dllfixdbg: honor Makefile verbositiy flag "V"
In Makefile.am, add the value of $(V) to the dllfixdbg call.
In dllfixdbg, if V=1, print what the script is doing.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-03 16:22:46 +01:00
Corinna Vinschen 7ae91f3b56 Cygwin: dllfixdbg: don't overwrite input DLL
Change dllfixdbg to keep the input DLL intact and just generate
a new DLL matching the debug file.  Fix Makefile rule accordingly.
The result is, cygwin0.dll is the original DLL created with full
debug sections and stays that way throughout the build process.
Only new-cygwin1.dll will become the stripped DLL matching with
the file containing the debug sections cygwin1.dbg.  This is ok,
because commit ba02fef995 ("Cygwin: Makefile.am: fix DLL build rule")
made new-cygwin1.dll the DLL to be installed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-03 16:22:46 +01:00
Takashi Yano 96646006a7 Cygwin: console: Fix IL/DL escape sequence on the last line.
- Currently, escape sequence IL/DL (CSI Ps L, CSI Ps M) does not
  work correctly at the last (bottom end) line. This patch fixes
  the issue.

Addresses:
  https://cygwin.com/pipermail/cygwin/2022-February/250736.html
2022-02-03 21:09:44 +09:00
Takashi Yano e5aca9ced9 Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive.
- If an UNC path is mounted to a drive using SMB3.11, accessing to
  the drive fails with error "Too many levels of symbolic links."
  This patch fixes the issue.
2022-02-03 12:21:21 +09:00
Corinna Vinschen 4a70041dfd Cygwin: silence dllfixdbg
There's no good reason to print the objcopy generation rules

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-02 21:30:20 +01:00