4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-22 16:49:45 +08:00

14137 Commits

Author SHA1 Message Date
Corinna Vinschen
3858f07dd8 Cygwin: get_posix_access: fix id in default:user and default:group entry
Setting the a_id in the default:user and default:group entries to
the actual uid and gid of the current owner/group doesn't make
sense.  Change to ACL_UNDEFINED_ID.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
a238211828 Cygwin: get_posix_access: don't drop admin and system perms in default ACL
The permissions of entries for SYSTEM and the Administrators group
are not added to the CLASS_OBJ entry, so they don't set the class
perms to rwx all the time.

This shouldn't be done for default perms, otherwise the resulting
permissions when generating new files might be surprisingly restricted
for Admins and SYSTEM.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
97c3835a03 Cygwin: get_posix_access: accomodate owner==group in default:group perms
When generating a default:group (Windows: CREATOR GROUP) ACL entry,
make sure to copy over user perms to the new default group entry.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
662fc09013 Cygwin: get_posix_access: drop stray increment instruction
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:02 +01:00
Corinna Vinschen
8695b3a176 Cygwin: get_posix_access: Use correct type for local id variable
it's an id_t, not an int.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:26:53 +01:00
Corinna Vinschen
a1aa7462cd Cygwin: security.h: De-inline cygpsid::debug_print
This allows to use the function from GDB during debugging.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:26:53 +01:00
Takashi Yano
a22a0ad7c4 Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent
After the commit d243e51ef1d3, zsh sometimes hangs at startup. This
occurs because SIGCHLD, which should trigger sigsuspend(), is handled
in cygwait() that is used to wait for a wakeup event in sig_send(),
even when __SIGFLUSHFAST is sent. Despite __SIGFLUSHFAST being
required to return before handling the signal, this does not happen.
With this patch, if the signal currently being sent is __SIGFLUSHFAST,
do not handle the received signal and keep it asserted after the
cygwait() for the wakeup event.  Apply the same logic to the cygwait()
in the retrying loop for WriteFile() as well.

Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
Fixes: d243e51ef1d3 ("Cygwin: signal: Fix deadlock between main thread and sig thread")
Reported-by: Daisuke Fujimura <booleanlabel@gmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-01-14 20:35:58 +09:00
Ken Brown
74017d229d Cygwin: mmap: use 64K pages for bookkeeping
It was convenient to use pages of size 4K (Windows page size) for
bookkeeping when we were using filler pages.  But all references to
filler pages were removed in commit ceda26c9d35b ("Cygwin: mmap:
remove __PROT_FILLER and the associated methods"), so this is no
longer necessary.  Switch to using pages of size 64K (Windows
allocation granularity) for everything.

Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-13 11:12:54 -05:00
Corinna Vinschen
264544bf72 Cygwin: unlink/rename: fix skipping deletion with POSIX semantics
unlink_nt() and rename2 () both check for the FILE_SUPPORTS_OPEN_BY_FILE_ID
flag to use POSIX delete/rename semantics.  Both erroneously check the flag
against the file attributes using has_attributes().

Given that this flag is a filesystem flag, check using fs_flags() instead.

Fixes: fe2545e9faaf ("Cygwin: don't use unlink/rename POSIX semantics on certain NTFS")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-12 23:11:18 +01:00
Ken Brown
b42ac298bb Cygwin: remove winsup/cygwin/local_includes/mmap_helper.h
None of its macros and functions are used anymore.

Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-09 17:51:27 -05:00
Ken Brown
fb8681e4ca Cygwin: mmap_list::try_map: simplify
Save the result of mmap_record::find_unused pages, and then pass that
result to the appropriate version of mmap_record::map_pages.  Add a
new parameter of type off_t to the latter to make this possible, and
change its return type from off_t to bool.  This saves map_pages from
having to call find_unused_pages again.

Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-09 17:51:27 -05:00
Ken Brown
ceda26c9d3 Cygwin: mmap: remove __PROT_FILLER and the associated methods
This is left over from 32 bit Cygwin and is no longer used.

Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-09 17:51:27 -05:00
Ken Brown
edac7e5345 Cygwin: mmap: remove is_mmapped_region()
The last use was removed in commit 29a126322783 ("Simplify stack
allocation code in child after fork").

Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-09 17:51:27 -05:00
Ken Brown
5495179332 Cygwin: mmap: refactor mmap_record::match
Slightly simplify the code and add comments to explain what the
function does.  Add a version of this method with a new reference
parameter "contains" that is set to true if the chunk of this
mmap_record contains the given address range.

Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-09 17:51:27 -05:00
Corinna Vinschen
2e4db338ac Cygwin: access: Fix X_OK behaviour for backup operators and admins
After commit a0933cd17d19, access(_, X_OK) returns 0 if the user
holds SE_BACKUP_PRIVILEGE, even if the file's ACL denies execution
to the user.  This is triggered by trying to open the file with
FILE_OPEN_FOR_BACKUP_INTENT.

Fix check_file_access() so it checks for X_OK without specifying
the FILE_OPEN_FOR_BACKUP_INTENT flag if the file is not a directory.

Rearrange function slightly and add comments for easier comprehension.

Fixes: a0933cd17d19 ("Cygwin: access: Correction for samba/SMB share")
Reported-by: Bruno Haible <bruno@clisp.org>
Co-authored-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-08 16:13:14 +01:00
Ken Brown
ad8d3195cc Cygwin: mmap: allow remapping part of an existing anonymous mapping
Previously mmap with MAP_FIXED would fail with EINVAL on an attempt to
map an address range contained in the chunk of an existing mapping.
With this commit, mmap will succeed, provided the mappings are
anonymous, the MAP_SHARED/MAP_PRIVATE flags agree, and MAP_NORESERVE
is not set for either mapping.

Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256901.html
Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-07 16:45:19 -05:00
Ken Brown
8adc45fdec Cygwin: mmap: fix mmap_is_attached_or_noreserve
This commit fixes two problems.  The first is that
mmap_is_attached_or_noreserve would sometimes call VirtualAlloc with
MEM_COMMIT on address ranges that were not known to have MEM_RESERVE
status.  These calls could fail, causing SIGBUS to be raised
incorrectly.  See

  https://cygwin.com/pipermail/cygwin-developers/2024-December/012725.html

for details.  Fix this by calling VirtualAlloc only on the part of the
address range that's contained in the current mmap_record.

The second problem is that the code would sometimes break out of the
main loop without knowing whether attached mappings still occur later
in the mmap_list.  This could cause SIGBUS to not be raised when it
should be.  Fix this by using "continue" rather than "break".  For
efficiency, introduce a boolean variable "nocover" that's set to true
if we discover that the address range cannot be covered by noreserve
mmap regions.

Addresses:
https://cygwin.com/pipermail/cygwin-developers/2024-December/012725.html
Fixes: 70e476d27be8 ("* include/cygwin/version.h: Bump DLL version to
1.7.0")
Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-07 16:34:27 -05:00
Corinna Vinschen
363357c023 Cygwin: pinfo: raise MAX_PID to 4194304
Reportedly, the maximum pid of 65536 is much too small in bigger
environments.  Raise the maximum PID to 4194304, whihc is the maximum
pid on Linux (PID_MAX_LIMIT defined in include/linux/threads.h).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-19 20:08:18 +01:00
Ken Brown
67bef16f7e Cygwin: mmap_list::try_map: fix a condition in a test of an mmap request
In testing whether the requested area is contained in an existing
mapped region, an incorrect condition was used due to a
misinterpretation of the u_addr and u_len variables.

Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256913.html
Fixes: c68de3a262fe5 ("* mmap.cc (class mmap_record):
Declare new map_pages method with address parameter.")
Signed-off-by: Ken Brown <kbrown@cornell.edu>
2024-12-19 10:40:18 -05:00
Ken Brown
677e315090 Cygwin: mmap: fix protection when unused pages are recycled
Previously, when unused pages from an mmap_record were recycled, they
were given the protection of the mmap_record rather than the
protection requested in the mmap call.  Fix this by adding a
"new_prot" parameter to mmap_list::try_map() and
mmap_record::map_pages() to keep track of the requested protection.
Then use new_prot in the calls to VirtualProtect().

Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256911.html
Fixes: f90e23f2714cb ("*autoload.cc (NtCreateSection): Define.")
Signed-off-by: Ken Brown <kbrown@cornell.edu>
2024-12-19 10:25:53 -05:00
Christian Franke
efa5401ea9 Cygwin: /proc/<PID>/stat: set field (18) according to scheduling policy
If a realtime policy is selected, set the '(18) priority' field to the
negated sched_priority minus one.  If SCHED_IDLE is selected, set it to
the lowest priority 39.  Also set '(19) nice' to the originally requested
nice value.  Ensure consistence with the current Windows priority in all
cases.  Move the sched_priority from/to Windows priority mapping from
sched_get/setparam() to new functions in miscfuncs.cc.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-12-17 17:39:00 +01:00
Christian Franke
14dda1f598 Cygwin: doc: add SCHED_BATCH, SCHED_IDLE and SCHED_RESET_ON_FORK
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-12-16 12:26:28 +01:00
Takashi Yano
1f74e7e71a Cygwin: signal: Fix typo in the comment added by previous commit
Fixes: 1d1451ccd2a6 ("Cygwin: signal: Fix high load when retrying to process pending signal")
Reported-by: Jon Turney <jon.turney@dronecode.org.uk>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-13 20:56:52 +09:00
Takashi Yano
1d1451ccd2 Cygwin: signal: Fix high load when retrying to process pending signal
The commit e10f822a2b39 has a problem that CPU load gets high if
pending signal is not processed successfully for a long time.
With this patch, wait_sig() calls Sleep(1), rather than yield(),
if the pending signal has not been processed successfully for a
predetermined time to prevent CPU from high load.

Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256884.html
Fixes: e10f822a2b39 ("Cygwin: signal: Handle queued signal without explicit __SIGFLUSH")
Reported-by: 凯夏 <walkerxk@gmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-12 21:38:20 +09:00
Christian Franke
06952f41ff Cygwin: sched_setscheduler: accept SCHED_RESET_ON_FORK flag
Add SCHED_RESET_ON_FORK to <sys/sched.h>.  If this flag is set, SCHED_FIFO
and SCHED_RR are reset to SCHED_OTHER and negative nice values are reset to
zero in each child process created with fork(2).

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-12-12 10:32:00 +01:00
Christian Franke
a31a6fe5dd Cygwin: sched_setscheduler: accept SCHED_BATCH
Add SCHED_BATCH to <sys/sched.h>.  SCHED_BATCH is similar to SCHED_OTHER,
except that the nice value is mapped to a one step lower Windows priority.
Rework the mapping functions to ease the addition of this functionality.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-12-12 10:32:00 +01:00
Corinna Vinschen
a0527e3786 Cygwin: utils: cygpath: add -r option to emit paths with root-local prefix
cygpath automatically adds the root-local prefix \\?\ automatically
for paths exceeding 260 bytes.  However, it does not add the root-local
prefix if the path contains path components invalid in DOS paths, for
instance path components with trailing dots or spaces.

Add the -r option to always add the root-local prefix to the path.

Add the option to the documentation and improve the help text.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-11 00:24:44 +01:00
Takashi Yano
a0933cd17d Cygwin: access: Correction for samba/SMB share
Previously, access() and eaccess() does not determine the permissions
for files on samba/SMB share correctly. Even if the user logs-in as
the owner of the file, access() and eaccess() referes to others'
permissions. With this patch, to determine the permissions correctly,
NtOpenFile() with desired access mask is used.

Fixes: cf762b08cfb0 ("* security.cc (check_file_access): Create.")
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-11 07:32:22 +09:00
Corinna Vinschen
815eba882e Cygwin: path_conv: allow NULL handle in init_reopen_attr()
init_reopen_attr() doesn't guard against a NULL handle.  However,
there are scenarios calling functions deliberately with a NULL handle,
for instance, av::setup() calling check_file_access() only if opening
the file did NOT succeed.

So check for a NULL handle in init_reopen_attr() and if so, use the
name based approach filling the OBJECT_ATTRIBUTES struct, just as in
the has_buggy_reopen() case.

Fixes: 4c9d01fdad2a ("* mount.h (class fs_info): Add has_buggy_reopen flag and accessor methods.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-10 16:50:11 +01:00
Corinna Vinschen
016ed8fba2 Cygwin: cygthread: add description for pty_master_fwd_thread
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-09 13:15:19 +01:00
Takashi Yano
2a1f407b09 Cygwin: console: Ignore intermediate byte in CSI sequence
Recent vim throughs the sequence CSI '0%m' that cannot be handled
appropriately by psuedo console for a test purpose. This patch
removes the intermediate byte ('%') from the sequence.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-08 22:34:17 +09:00
Takashi Yano
0b6b450c64 Cygwin: _cygtls: Remove _cygtls::spinning
There seems to be no rationale reason for _cygtls::spinning to exist,
so it has been removed. _cygtls::spinning was introduced in the commit
edc4f86ad282A, and this flag means that another thread is waiting to
acquire _cygtls::stacklock. It is checked in the sig thread in _cygtls::
interrupt_now(), and if spinning is true, the interrupt will be delayed.
However, in this case, _cygtls::incyg is also set, so it is supposed to
be covered by _cygtls::incyg flag and does not seem to add any value.

If some problems happen in the signal handling, it might be a good idea
to revert this commit and check if the issue will be fixed.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-08 08:58:27 +09:00
Corinna Vinschen
376fe1dab1 Cygwin: cygthread: stop running all cygthreads at HIGHEST priority.
Given the number of scenarios we're using cygthreads, it just doesn't
make sense to run all of them with HIGHEST priority in preemptive
obedience.

Drop setting the cygthread priority and let the cygthreads decide
by themselves.  For the time being, run all cygthreads with normal
priority.  Change this locally in the thread function, if required.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-06 19:41:35 +01:00
Corinna Vinschen
ad919e0535 Cygwin: cygthread: Add description of existing cygthreads
We're using the cygthread class in a considerable number of
scenarios, but we don't keep track for which purposes we
use them.

Add a comment at the head of cygthread.cc to describe what
cygthreads we maintain.

This is supposed to be kept up-to-date if some cygthread is
added, modified, or removed (wishful thinking).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-06 19:35:53 +01:00
Takashi Yano
cfadd852aa Cygwin: Document several fixes for signal handling in release note 2024-12-06 19:13:04 +09:00
Takashi Yano
496fa7b2ce Cygwin: signal: Introduce a lock for the signal queue
Currently, the signal queue is touched by the thread sig as well as
other threads that call sigaction_worker(). This potentially has
a possibility to destroy the signal queue chain. A possible worst
result may be a self-loop chain which causes infinite loop. With
this patch, lock()/unlock() are introduce to avoid such a situation.

Fixes: 474048c26edf ("* sigproc.cc (pending_signals::add): Just index directly into signal array rather than treating the array as a heap.")
Suggested-by: Corinna Vinschen <corinna@vinschen.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-06 19:13:04 +09:00
Takashi Yano
d565aca46f Cygwin: signal: Remove queue entry from the queue chain when cleared
The queue is cleaned up by removing the entries having si_signo == 0
while processing the queued signals, however, sigpacket::process() may
set si_signo in the queue to 0 of the entry already processed but not
succeed by calling sig_clear(). This patch ensures the sig_clear()
to remove the entry from the queue chain. For this purpose, the pointer
prev has been added to the sigpacket. This is to handle the following
case appropriately.

Consider the queued signal chain of:
A->B->C->D
without pointer prev. Assume that the pointer 'q' and 'qnext' point to
C, and process() is processing C. If B is cleared in process(), A->next
should be set to to C in sigpacket::clear().

Then, if process() for C succeeds, C should be removed from the queue,
so A->next should be set to D. However, we cannot do that because we do
not have the pointer to A in the while loop in wait_sig().

With the pointer prev, we can easily access A and C in sigpacket::clear()
as well as A and D in the while loop in wait_sig() using the pointer prev
and next without pursuing the chain.

Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256744.html
Fixes: 9d2155089e87 ("(wait_sig): Define variable q to be the start of the signal queue.  Just iterate through sigq queue, deleting processed or zeroed signals")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-06 19:13:04 +09:00
Corinna Vinschen
f71550e0db Cygwin: Add setjmp/longjmp fix to 3.5.5 release messages
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-05 22:28:19 +01:00
Corinna Vinschen
96d856320a Cygwin: setjmp/longjmp: drop setting spinning flag
Per the comment in _cygtls::interrupt_now(), the spinning flag
is supposed to guard that the targeted thread is about to enter
the Cygwin DLL.  Setting spinning has then been added to _sigfe,
_sigbe, sigdelayed and stabilize_sig_stack, the latter being called
from setjmp/longjmp.

However, setjmp/longjmp only enter the DLL in case of a pending
signal, calling _cygtls::call_signal_handler(). This in turn is
already guarded by setting the incyg flag, and there's no other
action in stabilize_sig_stack which might interfere with the
signal setup.  All the rest of setjmp/longjmp is plain userspace.

Therefore, drop setting the spinning flag from stabilize_sig_stack,
because it results in dropped signals in tight longjmp loops.

Fixes: edc4f86ad2827 ("* Makefile.in (clean): Remove sigfe.s.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-05 21:16:34 +01:00
Corinna Vinschen
3a9fb7c561 Cygwin: cygtls: add volatile qualifier to spinning
Given that spinning is only checked once at the start of a
_cygtls::interrupt_now() which is called in a loop, it's probably
not necessary to mark _cygtls::spinning as volatile.

However, spinning is changed from assembler code and we don't
want the compiler to make funny assumptions, so, better safe than
sorry.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-05 21:16:03 +01:00
Corinna Vinschen
41e1013e68 Cygwin: setjmp/longjmp: decrement incyg after signal handling
Commit 0b6fbd396ca2f ("* exceptions.cc (_cygtls::interrupt_now): Revert
to checking for "spinning" when choosing to defer signal.") introduced
a bug in the loop inside the stabilize_sig_stack subroutine:

First, stabilize_sig_stack grabs the stacklock. The _cygtls::incyg
flag is then incremented before checking if a signal has to be handled
for the current thread.

If no signal waits, the code simply jumps out, decrements _cygtls::incyg
and returns to the caller, which eventually releases the stacklock.

However, if a signal is waiting, stabilize_sig_stack releases the
stacklock, calls _cygtls::call_signal_handler(), and returns to
the start of the subroutine, trying to grab the lock.

After grabbing the lock, it increments _cygtls::incyg... wait...
again?

The loop does not decrement _cygtls::incyg after
_cygtls::call_signal_handler(), which returns with _cygtls::incyg
set to 1.  So it increments incyg to 2.  If no other signal is
waiting, stabilize_sig_stack jumps out and decrements _cygtls::incyg
to 1.  Eventually, setjmp or longjmp both will return to user
code with _cygtls::incyg set to 1.  This *may* be fixed at some later
point when signals arrive, but there will be a time when the application
runs in user code with broken signal handling.

Fixes: 0b6fbd396ca2f ("* exceptions.cc (_cygtls::interrupt_now): Revert to checking for "spinning" when choosing to defer signal.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-05 11:56:54 +01:00
Corinna Vinschen
0924d5f107 Cygwin: try_to_bin: transpose deleted file name to valid Unicode chars
Since commit 314c2d2fedc5f ("* syscalls.cc (try_to_bin): Handle remote
shares as well.") try_to_bin() transposes the .cyg prefix for temporary
files to invalid low surrogate halfs on filesystems setting the
FILE_UNICODE_ON_DISK flag.

This works on NTFS, but not necessarily on other filesystems, which often
require all chars in a filename to be valid Unicode chars.  Fix this by
transposing into the private use area instead.

Fixes: 314c2d2fedc5f ("* syscalls.cc (try_to_bin): Handle remote shares as well.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-04 22:54:38 +01:00
Christian Franke
61c2f075cd Cygwin: sched_setscheduler: accept SCHED_IDLE
Add SCHED_IDLE to <sys/sched.h>.  If SCHED_IDLE is selected, preserve
the nice value and set the Windows priority to IDLE_PRIORITY_CLASS.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-12-04 19:06:48 +01:00
Christian Franke
757424f744 Cygwin: doc: document sched_setpolicy(2) and priority mapping
Document the long standing mapping from nice or sched_priority
values to Windows priority classes and the new behavior of
sched_setpolicy(8).

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-12-04 19:06:48 +01:00
Christian Franke
48b189245a Cygwin: sched_setscheduler: accept SCHED_OTHER, SCHED_FIFO and SCHED_RR
If SCHED_OTHER is selected, set the Windows priority according to the
nice value.  If SCHED_FIFO or SCHED_RR is selected, preserve the nice
value and set the Windows priority according to the sched_priority
parameter.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-12-04 19:06:48 +01:00
Radek Bartoň
c79954439e Cygwin: Fix compatibility with GCC 15
Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
2024-12-04 16:50:59 +01:00
Corinna Vinschen
0a22adf7eb Cygwin: drop unnecessary inclusion of spinlock.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-04 14:53:08 +01:00
Takashi Yano
1a49c17840 Cygwin: termios: Trim buffer size for GetConsoleProcessList()
Currently, the buffer of 128KB is passed to GetConsoleProcessList().
This causes page fault in the select() loop for console due to:
https://github.com/microsoft/terminal/issues/18264
because the previous code calls GetConsoleProcessList() with large
buffer and PeekConsoleInput() with small buffer alternately.
With this patch, the minimum buffer size is used that is determined
by GetConsoleProcessList() with small buffer passed.

Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256841.html
Fixes: 72770148ad0a ("Cygwin: pty: Prevent pty from changing code page of parent console.")
Reported-by: Steven Buehler <buehlersj@outlook.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-04 20:45:42 +09:00
Takashi Yano
c48d58d838 Cygwin: signal: Increase chance of handling signal in main thread
If the process() fails and the signal remains in the queue, the most
possible reason is that the target thread is already armed by another
signal and does not handle it yet. With this patch, to increase the
chance of handling it in the other threads, call yield() before
retrying process().

Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256744.html
Fixes: e10f822a2b39 ("Cygwin: signal: Handle queued signal without explicit __SIGFLUSH")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Reviewed-by:
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-04 00:04:49 +09:00
Takashi Yano
9a274a967d Cygwin: signal: Optimize the priority of the sig thread
Previously, the sig thread ran in THREAD_PRIORITY_HIGHEST priority.
This causes a critical delay in the signal handling in the main
thread if too many signals are received rapidly and the CPU is very
busy. In this case, most of the CPU time is allocated to the sig
thread, so the main thread cannot have a chance of handling signals.
With this patch, to avoid such a situation, the priority of the sig
thread is set to THREAD_PRIORITY_NORMAL priority.

Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256744.html
Fixes: 53ad6f1394aa ("(cygthread::cygthread): Use three only arguments for detached threads, and start the thread via QueueUserAPC/async_create.")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-04 00:03:43 +09:00