https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bfe2790e7bc4400019a765bb9d0b7545a05ce447 commit bfe2790e7bc4400019a765bb9d0b7545a05ce447 Author: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca> AuthorDate: Sat Mar 16 10:44:00 2024 -0600 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 18 16:33:56 2024 +0100 winsup/cygwin/fhandler/proc.cc: format_proc_cpuinfo() Linux 6.8 cpuinfo flags add Linux 6.8 cpuinfo flags: Intel 0x00000007:1 eax:17 fred Flexible Return and Event Delivery; AMD 0x8000001f eax:4 sev_snp SEV secure nested paging; document unused and some unprinted bits that could look like omissions; fix typos and misalignments; Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca> Diff: --- winsup/cygwin/fhandler/proc.cc | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/fhandler/proc.cc b/winsup/cygwin/fhandler/proc.cc index be107cb8eacc..cb754185b833 100644 --- a/winsup/cygwin/fhandler/proc.cc +++ b/winsup/cygwin/fhandler/proc.cc @@ -1233,6 +1233,7 @@ format_proc_cpuinfo (void *, char *&destbuf) ftcprint (features2, 13, "cx16"); /* cmpxchg16b instruction */ ftcprint (features2, 14, "xtpr"); /* send task priority messages */ ftcprint (features2, 15, "pdcm"); /* perf/debug capabilities MSR */ +/* ftcprint (features2, 16, ""); */ /* unused */ ftcprint (features2, 17, "pcid"); /* process context identifiers */ ftcprint (features2, 18, "dca"); /* direct cache access */ ftcprint (features2, 19, "sse4_1"); /* xmm 4_1 sse 4.1 */ @@ -1273,14 +1274,18 @@ format_proc_cpuinfo (void *, char *&destbuf) ftcprint (features1, 11, "xop"); /* sse 5 extended AVX */ ftcprint (features1, 12, "skinit"); /* skinit/stgi */ ftcprint (features1, 13, "wdt"); /* watchdog timer */ +/* ftcprint (features1, 14, ""); */ /* unused */ ftcprint (features1, 15, "lwp"); /* light weight prof */ ftcprint (features1, 16, "fma4"); /* 4 operand MAC */ ftcprint (features1, 17, "tce"); /* translat cache ext */ +/* ftcprint (features1, 18, ""); */ /* unused */ ftcprint (features1, 19, "nodeid_msr"); /* nodeid MSR */ +/* ftcprint (features1, 20, ""); */ /* unused */ ftcprint (features1, 21, "tbm"); /* trailing bit manip */ ftcprint (features1, 22, "topoext"); /* topology ext */ ftcprint (features1, 23, "perfctr_core"); /* core perf ctr ext */ ftcprint (features1, 24, "perfctr_nb"); /* NB perf ctr ext */ +/* ftcprint (features1, 25, ""); */ /* unused */ ftcprint (features1, 26, "bpext"); /* data brkpt ext */ ftcprint (features1, 27, "ptsc"); /* perf timestamp ctr */ ftcprint (features1, 28, "perfctr_llc"); /* ll cache perf ctr */ @@ -1447,6 +1452,7 @@ format_proc_cpuinfo (void *, char *&destbuf) ftcprint (features1, 19, "adx"); /* adcx/adox */ ftcprint (features1, 20, "smap"); /* sec mode access prev */ ftcprint (features1, 21, "avx512ifma"); /* vec int FMA */ +/* ftcprint (features1, 22, ""); */ /* unused */ ftcprint (features1, 23, "clflushopt"); /* cache line flush opt */ ftcprint (features1, 24, "clwb"); /* cache line write back */ ftcprint (features1, 25, "intel_pt"); /* intel processor trace */ @@ -1468,6 +1474,7 @@ format_proc_cpuinfo (void *, char *&destbuf) ftcprint (features1, 1, "xsavec"); /* xsavec instruction */ ftcprint (features1, 2, "xgetbv1"); /* xgetbv ecx 1 */ ftcprint (features1, 3, "xsaves"); /* xsaves/xrstors */ +/* ftcprint (features1, 4, "xfd"); */ /* eXtended Feature Disabling */ } /* cpuid 0x0000000f edx */ if (maxf >= 0x0000000f) @@ -1502,9 +1509,18 @@ format_proc_cpuinfo (void *, char *&destbuf) ftcprint (features1, 4, "avx_vnni"); /* vex enc NN vec */ ftcprint (features1, 5, "avx512_bf16"); /* vec bfloat16 short */ /* ftcprint (features1, 7, "cmpccxadd"); */ /* CMPccXADD instructions */ -/* ftcprint (features1, 18, "lkgs"); */ /* load kernel (userspace) GS */ -/* ftcprint (features1, 21, "amx_fp16"); */ /* AMX fp16 Support */ -/* ftcprint (features1, 23, "avx_ifma"); */ /* Support for VPMADD52[H,L]UQ */ +/* ftcprint (features1, 8, "arch_perf"); */ /* Arch PerfMon Extension */ +/* ftcprint (features1, 10, "fzrm"); */ /* Fast zero-length REP MOVSB */ +/* ftcprint (features1, 11, "fsrs"); */ /* Fast short REP STOSB */ +/* ftcprint (features1, 12, "fsrc"); */ /* Fast short REP {CMPSB,SCASB} */ + ftcprint (features1, 17, "fred"); /* Flexible Return and Event Delivery */ +/* ftcprint (features1, 18, "lkgs"); */ /* load kernel (userspace) GS */ +/* ftcprint (features1, 19, "wrmsrns"); */ /* Non-serializing WRMSR */ +/* ftcprint (features1, 21, "amx_fp16"); */ /* AMX fp16 Support */ +/* ftcprint (features1, 22, "amx_bf16"); */ /* AMX bf16 Support */ +/* ftcprint (features1, 23, "avx_ifma"); */ /* Support for VPMADD52[H,L]UQ */ +/* ftcprint (features1, 24, "amx_tile"); */ /* AMX tile Support */ +/* ftcprint (features1, 25, "amx_int8"); */ /* AMX int8 Support */ ftcprint (features1, 26, "lam"); /* Linear Address Masking */ } @@ -1531,6 +1547,7 @@ format_proc_cpuinfo (void *, char *&destbuf) /* ftcprint (features1, 26, "ssb_no"); */ /* ssb fixed in hardware */ ftcprint (features1, 27, "cppc"); /* collab proc perf ctl */ /* ftcprint (features1, 28, "amd_psfd"); */ /* predictive store fwd dis */ +/* ftcprint (features1, 29, "btc_no"); */ /* Not vulnerable to Branch Type Confusion */ ftcprint (features1, 31, "brs"); /* branch sampling */ } @@ -1564,7 +1581,7 @@ format_proc_cpuinfo (void *, char *&destbuf) ftcprint (features1, 4, "tsc_scale"); /* TSC rate control */ ftcprint (features1, 5, "vmcb_clean"); /* VMCB clean bits */ ftcprint (features1, 6, "flushbyasid"); /* flush by ASID */ - ftcprint (features1, 7, "decode_assists"); /* decode assists */ + ftcprint (features1, 7, "decodeassists"); /* decode assists */ ftcprint (features1, 10, "pausefilter"); /* filt pause intrcpt */ ftcprint (features1, 12, "pfthreshold"); /* pause filt thresh */ ftcprint (features1, 13, "avic"); /* virt int control */ @@ -1580,6 +1597,7 @@ format_proc_cpuinfo (void *, char *&destbuf) { cpuid (&unused, &unused, &features1, &unused, 0x00000007, 0); +/* ftcprint (features1, 0, ""); */ /* unused */ ftcprint (features1, 1, "avx512vbmi"); /* vec bit manip */ ftcprint (features1, 2, "umip"); /* user mode ins prot */ ftcprint (features1, 3, "pku"); /* prot key userspace */ @@ -1594,10 +1612,14 @@ format_proc_cpuinfo (void *, char *&destbuf) ftcprint (features1, 12, "avx512_bitalg"); /* vpopcnt/b/w vpshuf */ ftcprint (features1, 13, "tme"); /* total mem encrypt */ ftcprint (features1, 14, "avx512_vpopcntdq"); /* vec popcnt dw/qw */ +/* ftcprint (features1, 15, ""); */ /* unused */ ftcprint (features1, 16, "la57"); /* 5 level paging */ +/* ftcprint (features1, .., ""); */ /* unused */ ftcprint (features1, 22, "rdpid"); /* rdpid instruction */ +/* ftcprint (features1, 23, ""); */ /* unused */ ftcprint (features1, 24, "bus_lock_detect"); /* bus lock detect dbg excptn */ ftcprint (features1, 25, "cldemote"); /* cldemote instr */ +/* ftcprint (features1, 26, ""); */ /* unused */ ftcprint (features1, 27, "movdiri"); /* movdiri instr */ ftcprint (features1, 28, "movdir64b"); /* movdir64b instr */ ftcprint (features1, 29, "enqcmd"); /* enqcmd/s instructions*/ @@ -1610,8 +1632,9 @@ format_proc_cpuinfo (void *, char *&destbuf) cpuid (&unused, &features1, &unused, &unused, 0x80000007, 0); ftcprint (features1, 0, "overflow_recov"); /* MCA oflow recovery */ - ftcprint (features1, 1, "succor"); /* uncor err recovery */ - ftcprint (features1, 3, "smca"); /* scalable MCA */ + ftcprint (features1, 1, "succor"); /* uncor err recovery */ +/* ftcprint (features1, 2, ""); */ /* unused */ + ftcprint (features1, 3, "smca"); /* scalable MCA */ } /* Intel cpuid 0x00000007 edx */ @@ -1646,8 +1669,9 @@ format_proc_cpuinfo (void *, char *&destbuf) ftcprint (features2, 1, "sev"); /* AMD secure encrypted virt */ /* ftcprint (features2, 2, "vm_page_flush");*/ /* VM page flush MSR */ ftcprint (features2, 3, "sev_es"); /* AMD SEV encrypted state */ -/* ftcprint (features2, 4, "sev_snp");*//* AMD SEV secure nested paging */ + ftcprint (features2, 4, "sev_snp"); /* AMD SEV secure nested paging */ /* ftcprint (features2, 5, "vmpl"); *//* VM permission levels support */ +/* ftcprint (features2, 9, "v_tsc_aux"); */ /* Virtual TSC_AUX */ /* ftcprint (features2, 10, "sme_coherent"); *//* SME h/w cache coherent */ /* ftcprint (features2, 11, "sev_64b");*//* SEV 64 bit host guest only */ /* ftcprint (features2, 12, "sev_rest_inj"); *//* SEV restricted injection */
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=89afbb8d8af2d4cbb71194bc24697795b5eb0ef6 commit 89afbb8d8af2d4cbb71194bc24697795b5eb0ef6 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Mon Mar 18 10:50:30 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 18 11:10:13 2024 +0100 Revert "Cygwin: glob: perform ignore_case_with_glob on input" This reverts commit a51147467e6cf58618433286f93d17043e00b0fc. Dumb thinko on my part. What was supposed to be an optimization actually broke caseinsensitive globbing in that the entire input of globbed expressions were downcased. Drop the unused CCHAR() macro nevertheless. Fixes: a51147467e6cf ("Cygwin: glob: perform ignore_case_with_glob on input") Reported-by: Michael Goldshteyn <mgold10000@gmail.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/glob.cc | 22 +++------------------- winsup/cygwin/release/3.5.2 | 4 ++++ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc index 4730d09f5590..90ec473aea55 100644 --- a/winsup/cygwin/glob.cc +++ b/winsup/cygwin/glob.cc @@ -96,8 +96,6 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.28 2010/05/12 17:44:00 gordon Ex #ifdef __CYGWIN__ #define Cchar(c) (ignore_case_with_glob ? towlower (c) : (c)) -#else -#define Cchar(c) (c) #endif #undef MAXPATHLEN @@ -123,7 +121,6 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.28 2010/05/12 17:44:00 gordon Ex #define SLASH '/' #define COMMA ',' -#undef DEBUG /* never define */ #ifndef DEBUG #define M_QUOTE 0x40000000U @@ -251,7 +248,7 @@ glob(const char *__restrict pattern, int flags, int (*errfunc)(const char *, int return (GLOB_NOMATCH); else if (clen == 0) break; - *bufnext++ = Cchar(wc); + *bufnext++ = wc; patnext += clen; } } else { @@ -271,7 +268,7 @@ glob(const char *__restrict pattern, int flags, int (*errfunc)(const char *, int return (GLOB_NOMATCH); else if (clen == 0) break; - *bufnext++ = Cchar(wc) | prot; + *bufnext++ = wc | prot; patnext += clen; } } @@ -772,19 +769,6 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last, break; sc += clen; } -#ifdef __CYGWIN__ - if (ignore_case_with_glob) { - wint_t lower_path[MAXPATHLEN]; - wint_t *lp = lower_path, *sp = pathend; - - while ((*lp++ = towlower(*sp++))) - ; - if (!match(lower_path, pattern, restpattern)) { - *pathend = EOS; - continue; - } - } else -#endif if (!match(pathend, pattern, restpattern)) { *pathend = EOS; continue; @@ -938,7 +922,7 @@ match(Char *name, Char *pat, Char *patend) return(0); break; default: - if (*name++ != *c) + if (Cchar(*name++) != Cchar(*c)) return(0); break; } diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2 index 449047d9c276..32137c2e6807 100644 --- a/winsup/cygwin/release/3.5.2 +++ b/winsup/cygwin/release/3.5.2 @@ -20,3 +20,7 @@ Fixes: - Don't skip inadvertently some local SAM accounts on domain member machines. + +- Revert ill-advised optimization of glob(3) in case of caseinsensitive + globbing. + Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255675.html
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=70375b2205ba7cf5eddf4180b3d80ac8264c0e0a commit 70375b2205ba7cf5eddf4180b3d80ac8264c0e0a Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Mon Mar 18 10:50:30 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 18 11:10:20 2024 +0100 Revert "Cygwin: glob: perform ignore_case_with_glob on input" This reverts commit a51147467e6cf58618433286f93d17043e00b0fc. Dumb thinko on my part. What was supposed to be an optimization actually broke caseinsensitive globbing in that the entire input of globbed expressions were downcased. Drop the unused CCHAR() macro nevertheless. Fixes: a51147467e6cf ("Cygwin: glob: perform ignore_case_with_glob on input") Reported-by: Michael Goldshteyn <mgold10000@gmail.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/glob.cc | 22 +++------------------- winsup/cygwin/release/3.5.2 | 4 ++++ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc index 4730d09f5590..90ec473aea55 100644 --- a/winsup/cygwin/glob.cc +++ b/winsup/cygwin/glob.cc @@ -96,8 +96,6 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.28 2010/05/12 17:44:00 gordon Ex #ifdef __CYGWIN__ #define Cchar(c) (ignore_case_with_glob ? towlower (c) : (c)) -#else -#define Cchar(c) (c) #endif #undef MAXPATHLEN @@ -123,7 +121,6 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.28 2010/05/12 17:44:00 gordon Ex #define SLASH '/' #define COMMA ',' -#undef DEBUG /* never define */ #ifndef DEBUG #define M_QUOTE 0x40000000U @@ -251,7 +248,7 @@ glob(const char *__restrict pattern, int flags, int (*errfunc)(const char *, int return (GLOB_NOMATCH); else if (clen == 0) break; - *bufnext++ = Cchar(wc); + *bufnext++ = wc; patnext += clen; } } else { @@ -271,7 +268,7 @@ glob(const char *__restrict pattern, int flags, int (*errfunc)(const char *, int return (GLOB_NOMATCH); else if (clen == 0) break; - *bufnext++ = Cchar(wc) | prot; + *bufnext++ = wc | prot; patnext += clen; } } @@ -772,19 +769,6 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last, break; sc += clen; } -#ifdef __CYGWIN__ - if (ignore_case_with_glob) { - wint_t lower_path[MAXPATHLEN]; - wint_t *lp = lower_path, *sp = pathend; - - while ((*lp++ = towlower(*sp++))) - ; - if (!match(lower_path, pattern, restpattern)) { - *pathend = EOS; - continue; - } - } else -#endif if (!match(pathend, pattern, restpattern)) { *pathend = EOS; continue; @@ -938,7 +922,7 @@ match(Char *name, Char *pat, Char *patend) return(0); break; default: - if (*name++ != *c) + if (Cchar(*name++) != Cchar(*c)) return(0); break; } diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2 index 449047d9c276..32137c2e6807 100644 --- a/winsup/cygwin/release/3.5.2 +++ b/winsup/cygwin/release/3.5.2 @@ -20,3 +20,7 @@ Fixes: - Don't skip inadvertently some local SAM accounts on domain member machines. + +- Revert ill-advised optimization of glob(3) in case of caseinsensitive + globbing. + Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255675.html
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fc691d0246b95807cd2fac83cceb8053fc295eb2 commit fc691d0246b95807cd2fac83cceb8053fc295eb2 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Mon Mar 11 22:08:00 2024 +0900 Cygwin: pipe: Make sure to set read pipe non-blocking for cygwin apps. If pipe reader is a non-cygwin app first, and cygwin process reads the same pipe after that, the pipe has been set to bclocking mode for the cygwin app. However, the commit 9e4d308cd592 assumes the pipe for cygwin process always is non-blocking mode. With this patch, the pipe mode is reset to non-blocking when cygwin app is started. Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255644.html Fixes: 9e4d308cd592 ("Cygwin: pipe: Adopt FILE_SYNCHRONOUS_IO_NONALERT flag for read pipe.") Reported-by: wh <wh9692@protonmail.com> Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Diff: --- winsup/cygwin/fhandler/pipe.cc | 63 +++++++++++++++++++++++++++++++++ winsup/cygwin/local_includes/fhandler.h | 3 ++ winsup/cygwin/spawn.cc | 34 ++---------------- 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc index 29d3b41d9..ae43cbc00 100644 --- a/winsup/cygwin/fhandler/pipe.cc +++ b/winsup/cygwin/fhandler/pipe.cc @@ -18,6 +18,7 @@ details. */ #include "pinfo.h" #include "shared_info.h" #include "tls_pbuf.h" +#include "sigproc.h" #include <assert.h> /* This is only to be used for writing. When reading, @@ -602,6 +603,17 @@ fhandler_pipe::fixup_after_fork (HANDLE parent) ReleaseMutex (hdl_cnt_mtx); } +void +fhandler_pipe::fixup_after_exec () +{ + /* Set read pipe itself always non-blocking for cygwin process. + Blocking/non-blocking is simulated in raw_read(). For write + pipe, follow is_nonblocking(). */ + bool mode = get_device () == FH_PIPEW ? is_nonblocking () : true; + set_pipe_non_blocking (mode); + fhandler_base::fixup_after_exec (); +} + int fhandler_pipe::dup (fhandler_base *child, int flags) { @@ -1288,3 +1300,54 @@ close_proc: } return NULL; } + +void +fhandler_pipe::spawn_worker (int fileno_stdin, int fileno_stdout, + int fileno_stderr) +{ + bool need_send_noncygchld_sig = false; + + /* spawn_worker() is called from spawn.cc only when non-cygwin app + is started. Set pipe mode blocking for the non-cygwin process. */ + int fd; + cygheap_fdenum cfd (false); + while ((fd = cfd.next ()) >= 0) + if (cfd->get_dev () == FH_PIPEW + && (fd == fileno_stdout || fd == fileno_stderr)) + { + fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; + pipe->set_pipe_non_blocking (false); + + /* Setup for query_ndl stuff. Read the comment below. */ + if (pipe->request_close_query_hdl ()) + need_send_noncygchld_sig = true; + } + else if (cfd->get_dev () == FH_PIPER && fd == fileno_stdin) + { + fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; + pipe->set_pipe_non_blocking (false); + } + + /* If multiple writers including non-cygwin app exist, the non-cygwin + app cannot detect pipe closure on the read side when the pipe is + created by system account or the pipe creator is running as service. + This is because query_hdl which is held in write side also is a read + end of the pipe, so the pipe is still alive for the non-cygwin app + even after the reader is closed. + + To avoid this problem, let all processes in the same process + group close query_hdl using internal signal __SIGNONCYGCHLD when + non-cygwin app is started. */ + if (need_send_noncygchld_sig) + { + tty_min dummy_tty; + dummy_tty.ntty = (fh_devices) myself->ctty; + dummy_tty.pgid = myself->pgid; + tty_min *t = cygwin_shared->tty.get_cttyp (); + if (!t) /* If tty is not allocated, use dummy_tty instead. */ + t = &dummy_tty; + /* Emit __SIGNONCYGCHLD to let all processes in the + process group close query_hdl. */ + t->kill_pgrp (__SIGNONCYGCHLD); + } +} diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h index 8729eb276..d9e0a011b 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -1234,6 +1234,7 @@ public: int open (int flags, mode_t mode = 0); bool open_setup (int flags); void fixup_after_fork (HANDLE); + void fixup_after_exec (); int dup (fhandler_base *child, int); void set_close_on_exec (bool val); int close (); @@ -1295,6 +1296,8 @@ public: } return false; } + static void spawn_worker (int fileno_stdin, int fileno_stdout, + int fileno_stderr); }; #define CYGWIN_FIFO_PIPE_NAME_LEN 47 diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 71d75bbf4..3da77088d 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -580,38 +580,8 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, int fileno_stderr = 2; if (!iscygwin ()) - { - bool need_send_sig = false; - int fd; - cygheap_fdenum cfd (false); - while ((fd = cfd.next ()) >= 0) - if (cfd->get_dev () == FH_PIPEW - && (fd == fileno_stdout || fd == fileno_stderr)) - { - fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; - pipe->set_pipe_non_blocking (false); - if (pipe->request_close_query_hdl ()) - need_send_sig = true; - } - else if (cfd->get_dev () == FH_PIPER && fd == fileno_stdin) - { - fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; - pipe->set_pipe_non_blocking (false); - } - - if (need_send_sig) - { - tty_min dummy_tty; - dummy_tty.ntty = (fh_devices) myself->ctty; - dummy_tty.pgid = myself->pgid; - tty_min *t = cygwin_shared->tty.get_cttyp (); - if (!t) /* If tty is not allocated, use dummy_tty instead. */ - t = &dummy_tty; - /* Emit __SIGNONCYGCHLD to let all processes in the - process group close query_hdl. */ - t->kill_pgrp (__SIGNONCYGCHLD); - } - } + fhandler_pipe::spawn_worker (fileno_stdin, fileno_stdout, + fileno_stderr); bool no_pcon = mode != _P_OVERLAY && mode != _P_WAIT; term_spawn_worker.setup (iscygwin (), handle (fileno_stdin, false),
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=55431b408e7a6cb29d52ec619c38cdb6c40e2120 commit 55431b408e7a6cb29d52ec619c38cdb6c40e2120 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Mon Mar 11 22:08:00 2024 +0900 Cygwin: pipe: Make sure to set read pipe non-blocking for cygwin apps. If pipe reader is a non-cygwin app first, and cygwin process reads the same pipe after that, the pipe has been set to bclocking mode for the cygwin app. However, the commit 9e4d308cd592 assumes the pipe for cygwin process always is non-blocking mode. With this patch, the pipe mode is reset to non-blocking when cygwin app is started. Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255644.html Fixes: 9e4d308cd592 ("Cygwin: pipe: Adopt FILE_SYNCHRONOUS_IO_NONALERT flag for read pipe.") Reported-by: wh <wh9692@protonmail.com> Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Diff: --- winsup/cygwin/fhandler/pipe.cc | 63 +++++++++++++++++++++++++++++++++ winsup/cygwin/local_includes/fhandler.h | 3 ++ winsup/cygwin/spawn.cc | 34 ++---------------- 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc index c877d89d7..4c4ad0383 100644 --- a/winsup/cygwin/fhandler/pipe.cc +++ b/winsup/cygwin/fhandler/pipe.cc @@ -18,6 +18,7 @@ details. */ #include "pinfo.h" #include "shared_info.h" #include "tls_pbuf.h" +#include "sigproc.h" #include <assert.h> /* This is only to be used for writing. When reading, @@ -587,6 +588,17 @@ fhandler_pipe::fixup_after_fork (HANDLE parent) ReleaseMutex (hdl_cnt_mtx); } +void +fhandler_pipe::fixup_after_exec () +{ + /* Set read pipe itself always non-blocking for cygwin process. + Blocking/non-blocking is simulated in raw_read(). For write + pipe, follow is_nonblocking(). */ + bool mode = get_device () == FH_PIPEW ? is_nonblocking () : true; + set_pipe_non_blocking (mode); + fhandler_base::fixup_after_exec (); +} + int fhandler_pipe::dup (fhandler_base *child, int flags) { @@ -1289,3 +1301,54 @@ close_proc: } return NULL; } + +void +fhandler_pipe::spawn_worker (int fileno_stdin, int fileno_stdout, + int fileno_stderr) +{ + bool need_send_noncygchld_sig = false; + + /* spawn_worker() is called from spawn.cc only when non-cygwin app + is started. Set pipe mode blocking for the non-cygwin process. */ + int fd; + cygheap_fdenum cfd (false); + while ((fd = cfd.next ()) >= 0) + if (cfd->get_dev () == FH_PIPEW + && (fd == fileno_stdout || fd == fileno_stderr)) + { + fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; + pipe->set_pipe_non_blocking (false); + + /* Setup for query_ndl stuff. Read the comment below. */ + if (pipe->request_close_query_hdl ()) + need_send_noncygchld_sig = true; + } + else if (cfd->get_dev () == FH_PIPER && fd == fileno_stdin) + { + fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; + pipe->set_pipe_non_blocking (false); + } + + /* If multiple writers including non-cygwin app exist, the non-cygwin + app cannot detect pipe closure on the read side when the pipe is + created by system account or the pipe creator is running as service. + This is because query_hdl which is held in write side also is a read + end of the pipe, so the pipe is still alive for the non-cygwin app + even after the reader is closed. + + To avoid this problem, let all processes in the same process + group close query_hdl using internal signal __SIGNONCYGCHLD when + non-cygwin app is started. */ + if (need_send_noncygchld_sig) + { + tty_min dummy_tty; + dummy_tty.ntty = (fh_devices) myself->ctty; + dummy_tty.pgid = myself->pgid; + tty_min *t = cygwin_shared->tty.get_cttyp (); + if (!t) /* If tty is not allocated, use dummy_tty instead. */ + t = &dummy_tty; + /* Emit __SIGNONCYGCHLD to let all processes in the + process group close query_hdl. */ + t->kill_pgrp (__SIGNONCYGCHLD); + } +} diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h index a21aeb7d8..87adca962 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -1223,6 +1223,7 @@ public: int open (int flags, mode_t mode = 0); bool open_setup (int flags); void fixup_after_fork (HANDLE); + void fixup_after_exec (); int dup (fhandler_base *child, int); void set_close_on_exec (bool val); int close (); @@ -1284,6 +1285,8 @@ public: } return false; } + static void spawn_worker (int fileno_stdin, int fileno_stdout, + int fileno_stderr); }; #define CYGWIN_FIFO_PIPE_NAME_LEN 47 diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 77dc6dff4..d01f678c3 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -588,38 +588,8 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, int fileno_stderr = 2; if (!iscygwin ()) - { - bool need_send_sig = false; - int fd; - cygheap_fdenum cfd (false); - while ((fd = cfd.next ()) >= 0) - if (cfd->get_dev () == FH_PIPEW - && (fd == fileno_stdout || fd == fileno_stderr)) - { - fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; - pipe->set_pipe_non_blocking (false); - if (pipe->request_close_query_hdl ()) - need_send_sig = true; - } - else if (cfd->get_dev () == FH_PIPER && fd == fileno_stdin) - { - fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; - pipe->set_pipe_non_blocking (false); - } - - if (need_send_sig) - { - tty_min dummy_tty; - dummy_tty.ntty = (fh_devices) myself->ctty; - dummy_tty.pgid = myself->pgid; - tty_min *t = cygwin_shared->tty.get_cttyp (); - if (!t) /* If tty is not allocated, use dummy_tty instead. */ - t = &dummy_tty; - /* Emit __SIGNONCYGCHLD to let all processes in the - process group close query_hdl. */ - t->kill_pgrp (__SIGNONCYGCHLD); - } - } + fhandler_pipe::spawn_worker (fileno_stdin, fileno_stdout, + fileno_stderr); bool no_pcon = mode != _P_OVERLAY && mode != _P_WAIT; term_spawn_worker.setup (iscygwin (), handle (fileno_stdin, false),
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3af5d2bbdde00dc9443588f9a3938e6a862c85b4 commit 3af5d2bbdde00dc9443588f9a3938e6a862c85b4 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Mon Mar 11 12:53:50 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 11 12:53:50 2024 +0100 Cygwin: 3.6.0: add release entries for pinned/unpinned flag handling Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/release/3.6.0 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/winsup/cygwin/release/3.6.0 b/winsup/cygwin/release/3.6.0 index e190aa2927d6..20aab2b44dc8 100644 --- a/winsup/cygwin/release/3.6.0 +++ b/winsup/cygwin/release/3.6.0 @@ -9,6 +9,10 @@ What's new: - New API call: timespec_get. +- Add FS_IOC_[GS]ETFLAGS FS_PINNED_FL and FS_UNPINNED_FL flags to handle + Windows attributes FILE_ATTRIBUTE_PINNED and FILE_ATTRIBUTE_UNPINNED. + Add matching 'p' and 'u' mode bits in chattr(1) and lsattr(1). + What changed: -------------
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=775069553b8ef40651db100becfc8bd91c7f7881 commit 775069553b8ef40651db100becfc8bd91c7f7881 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Mon Mar 11 12:53:24 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 11 12:53:24 2024 +0100 Cygwin: add 3.5.2 release entries for latest commits Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/release/3.5.2 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2 index e6782c1c004b..449047d9c276 100644 --- a/winsup/cygwin/release/3.5.2 +++ b/winsup/cygwin/release/3.5.2 @@ -13,3 +13,10 @@ Fixes: - Fix a problem that select() call for write-side of a pipe possibly hangs with non-cygwin reader. Addresses: https://github.com/msys2/msys2-runtime/issues/202 + +- Avoid recalling offline files if the file is not explicitely opened + for reading or writing data. + Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255613.html + +- Don't skip inadvertently some local SAM accounts on domain member + machines.
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=5f586adc634588895b5c4afa24f819859aee50d7 commit 5f586adc634588895b5c4afa24f819859aee50d7 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Mon Mar 11 12:38:39 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 11 12:46:50 2024 +0100 Cygwin: getgrent: don't skip SAM-only builtin-accounts Since commit 15e82eef3a40b ("Cygwin: getgrent: fix local SAM enumeration on domain member machines") we skip enumerating local BUILTIN accounts if we also enumerate AD. However, there are two local accounts which are only available in local SAM, not in AD. Don't skip enumerating those. Fixes: 15e82eef3a40b ("Cygwin: getgrent: fix local SAM enumeration on domain member machines") Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/grp.cc | 11 ++++++++--- winsup/cygwin/local_includes/winlean.h | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 77cf6a72c69f..5f80d7aa7ec5 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -428,10 +428,15 @@ gr_ent::enumerate_local () ((PLOCALGROUP_INFO_0) buf)[cnt++].lgrpi0_name, sid, &slen, dom, &dlen, &acc_type)) continue; - if (sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */ + /* Skip builtin groups if we're enumerating AD as well to avoid + duplication. Don't skip "Power Users" and "Device Owners" + accounts, they don't show up in AD enumeration. */ + if (cygheap->dom.member_machine () + && nss_db_enum_primary () + && sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */ && sid_sub_auth (sid, 0) == SECURITY_BUILTIN_DOMAIN_RID - && cygheap->dom.member_machine () - && nss_db_enum_primary ()) + && sid_sub_auth (sid, 1) != DOMAIN_ALIAS_RID_POWER_USERS + && sid_sub_auth (sid, 1) != DOMAIN_ALIAS_RID_DEVICE_OWNERS) continue; fetch_user_arg_t arg; arg.type = SID_arg; diff --git a/winsup/cygwin/local_includes/winlean.h b/winsup/cygwin/local_includes/winlean.h index 947109bdeee4..5bf1be262a00 100644 --- a/winsup/cygwin/local_includes/winlean.h +++ b/winsup/cygwin/local_includes/winlean.h @@ -104,6 +104,10 @@ details. */ #define FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS 0x00400000 #endif +#ifndef DOMAIN_ALIAS_RID_DEVICE_OWNERS +#define DOMAIN_ALIAS_RID_DEVICE_OWNERS (__MSABI_LONG(0x00000247)) +#endif + /* So-called "Microsoft Account" SIDs (S-1-11-...) have a netbios domain name "MicrosoftAccounts". The new "Application Container SIDs" (S-1-15-...) have a netbios domain name "APPLICATION PACKAGE AUTHORITY"
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=83afe30071c0cb44db924892074010e78cb476a7 commit 83afe30071c0cb44db924892074010e78cb476a7 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Mon Mar 11 12:53:24 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 11 15:29:51 2024 +0100 Cygwin: add 3.5.2 release entries for latest commits Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/release/3.5.2 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2 index e6782c1c004b..449047d9c276 100644 --- a/winsup/cygwin/release/3.5.2 +++ b/winsup/cygwin/release/3.5.2 @@ -13,3 +13,10 @@ Fixes: - Fix a problem that select() call for write-side of a pipe possibly hangs with non-cygwin reader. Addresses: https://github.com/msys2/msys2-runtime/issues/202 + +- Avoid recalling offline files if the file is not explicitely opened + for reading or writing data. + Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255613.html + +- Don't skip inadvertently some local SAM accounts on domain member + machines.
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=66f7dd9ff676a17b877b7be12b3ad8d01c8eb3f3 commit 66f7dd9ff676a17b877b7be12b3ad8d01c8eb3f3 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Mon Mar 11 12:38:39 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 11 15:29:51 2024 +0100 Cygwin: getgrent: don't skip SAM-only builtin-accounts Since commit 15e82eef3a40b ("Cygwin: getgrent: fix local SAM enumeration on domain member machines") we skip enumerating local BUILTIN accounts if we also enumerate AD. However, there are two local accounts which are only available in local SAM, not in AD. Don't skip enumerating those. Fixes: 15e82eef3a40b ("Cygwin: getgrent: fix local SAM enumeration on domain member machines") Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/grp.cc | 11 ++++++++--- winsup/cygwin/local_includes/winlean.h | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 77cf6a72c69f..5f80d7aa7ec5 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -428,10 +428,15 @@ gr_ent::enumerate_local () ((PLOCALGROUP_INFO_0) buf)[cnt++].lgrpi0_name, sid, &slen, dom, &dlen, &acc_type)) continue; - if (sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */ + /* Skip builtin groups if we're enumerating AD as well to avoid + duplication. Don't skip "Power Users" and "Device Owners" + accounts, they don't show up in AD enumeration. */ + if (cygheap->dom.member_machine () + && nss_db_enum_primary () + && sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */ && sid_sub_auth (sid, 0) == SECURITY_BUILTIN_DOMAIN_RID - && cygheap->dom.member_machine () - && nss_db_enum_primary ()) + && sid_sub_auth (sid, 1) != DOMAIN_ALIAS_RID_POWER_USERS + && sid_sub_auth (sid, 1) != DOMAIN_ALIAS_RID_DEVICE_OWNERS) continue; fetch_user_arg_t arg; arg.type = SID_arg; diff --git a/winsup/cygwin/local_includes/winlean.h b/winsup/cygwin/local_includes/winlean.h index 947109bdeee4..5bf1be262a00 100644 --- a/winsup/cygwin/local_includes/winlean.h +++ b/winsup/cygwin/local_includes/winlean.h @@ -104,6 +104,10 @@ details. */ #define FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS 0x00400000 #endif +#ifndef DOMAIN_ALIAS_RID_DEVICE_OWNERS +#define DOMAIN_ALIAS_RID_DEVICE_OWNERS (__MSABI_LONG(0x00000247)) +#endif + /* So-called "Microsoft Account" SIDs (S-1-11-...) have a netbios domain name "MicrosoftAccounts". The new "Application Container SIDs" (S-1-15-...) have a netbios domain name "APPLICATION PACKAGE AUTHORITY"
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=66138cbee4ed784b4cafc00533ebb74b6cdbfff1 commit 66138cbee4ed784b4cafc00533ebb74b6cdbfff1 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 8 21:30:57 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 11 15:29:51 2024 +0100 Cygwin: get/set security descriptors using FILE_OPEN_NO_RECALL Add FILE_OPEN_NO_RECALL to NtOpenFile calls trying to fetch or write file security descriptors so as not to recall them from offline storage inadvertently. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/sec/base.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/sec/base.cc b/winsup/cygwin/sec/base.cc index 8b04b40b4943..0fc8699bfc9e 100644 --- a/winsup/cygwin/sec/base.cc +++ b/winsup/cygwin/sec/base.cc @@ -65,7 +65,8 @@ get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, fh ? pc.init_reopen_attr (attr, fh) : pc.get_object_attr (attr, sec_none_nih), &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | pc.is_known_reparse_point () ? FILE_OPEN_REPARSE_POINT : 0); if (!NT_SUCCESS (status)) @@ -129,7 +130,8 @@ get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, NULL, NULL); status = NtOpenFile (&fh, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_REPARSE_POINT); if (!NT_SUCCESS (status)) { @@ -234,7 +236,8 @@ set_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, bool is_chown) : pc.get_object_attr (attr, sec_none_nih), &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | pc.is_known_reparse_point () ? FILE_OPEN_REPARSE_POINT : 0); if (!NT_SUCCESS (status))
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c1cf14a871528d1adba88a0128813b58d52ba926 commit c1cf14a871528d1adba88a0128813b58d52ba926 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 8 20:57:06 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Mon Mar 11 15:29:32 2024 +0100 Cygwin: try to avoid recalling offline files Chances are high that Cygwin recalls offline files from remote storage, even if the file is only accessed during stat(2) or readdir(3). To avoid this - make sure Cygwin is placeholder-aware, - open files in path_conv handling, as well as in stat(2)/readdir(3) scenarios with FILE_OPEN_NO_RECALL, and - during symlink checking or testing for executablility, don't even try to open the file if one of the OFFLINE attributes is set. Reported-by: Marcin Wisnicki <mwisnicki@gmail.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/autoload.cc | 1 + winsup/cygwin/dcrt0.cc | 3 +++ winsup/cygwin/fhandler/disk_file.cc | 20 ++++++++++++++------ winsup/cygwin/local_includes/ntdll.h | 8 ++++++++ winsup/cygwin/local_includes/path.h | 16 +++++++++++++++- winsup/cygwin/local_includes/winlean.h | 7 +++++++ winsup/cygwin/path.cc | 17 +++++++++++++---- 7 files changed, 61 insertions(+), 11 deletions(-) diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index 65e906e8b9d0..cc9dafe1b621 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -479,6 +479,7 @@ LoadDLLfuncEx (SetThreadDescription, KernelBase, 1) LoadDLLfunc (VirtualAlloc2, KernelBase) LoadDLLfunc (NtMapViewOfSectionEx, ntdll) +LoadDLLfuncEx (RtlSetProcessPlaceholderCompatibilityMode, ntdll, 1) LoadDLLfunc (ldap_bind_s, wldap32) LoadDLLfunc (ldap_count_entries, wldap32) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index fc1eec76a4a5..ea6a18b51d70 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -809,6 +809,9 @@ dll_crt0_1 (void *) if (dynamically_loaded) sigproc_init (); + /* Call this before accessing any files. */ + RtlSetProcessPlaceholderCompatibilityMode (PHCM_EXPOSE_PLACEHOLDERS); + check_sanity_and_sync (user_data); /* Initialize malloc and then call user_shared_initialize since it relies diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/disk_file.cc index d08fe9160d35..f3592148fc5b 100644 --- a/winsup/cygwin/fhandler/disk_file.cc +++ b/winsup/cygwin/fhandler/disk_file.cc @@ -176,7 +176,9 @@ readdir_check_reparse_point (POBJECT_ATTRIBUTES attr, bool remote) bool ret = false; status = NtOpenFile (&reph, READ_CONTROL, attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_REPARSE_POINT); + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT + | FILE_OPEN_REPARSE_POINT); if (NT_SUCCESS (status)) { PREPARSE_DATA_BUFFER rp = (PREPARSE_DATA_BUFFER) tp.c_get (); @@ -328,6 +330,7 @@ fhandler_base::fstat_by_name (struct stat *buf) status = NtOpenFile (&dir, SYNCHRONIZE | FILE_LIST_DIRECTORY, &attr, &io, FILE_SHARE_VALID_FLAGS, FILE_SYNCHRONOUS_IO_NONALERT + | FILE_OPEN_NO_RECALL | FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE); if (!NT_SUCCESS (status)) @@ -616,7 +619,8 @@ fhandler_disk_file::fstatvfs (struct statvfs *sfs) opened = NT_SUCCESS (NtOpenFile (&fh, READ_CONTROL, pc.get_object_attr (attr, sec_none_nih), &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT)); + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT)); if (!opened) { /* Can't open file. Try again with parent dir. */ @@ -625,7 +629,8 @@ fhandler_disk_file::fstatvfs (struct statvfs *sfs) attr.ObjectName = &dirname; opened = NT_SUCCESS (NtOpenFile (&fh, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT)); + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT)); if (!opened) goto out; } @@ -2323,7 +2328,8 @@ readdir_get_ino (const char *path, bool dot_dot) || NT_SUCCESS (NtOpenFile (&hdl, READ_CONTROL, pc.get_object_attr (attr, sec_none_nih), &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | (pc.is_known_reparse_point () ? FILE_OPEN_REPARSE_POINT : 0))) ) @@ -2372,8 +2378,9 @@ fhandler_disk_file::readdir_helper (DIR *dir, dirent *de, DWORD w32_err, Mountpoints and unknown or unhandled reparse points will be treated as normal file/directory/unknown. In all cases, returning the INO of the reparse point (not of the target) matches behavior of posix systems. + Unless the file is OFFLINE. *. */ - if (attr & FILE_ATTRIBUTE_REPARSE_POINT) + if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) && !isoffline (attr)) { OBJECT_ATTRIBUTES oattr; @@ -2618,7 +2625,8 @@ go_ahead: &nfs_aol_ffei, sizeof nfs_aol_ffei) : NtOpenFile (&hdl, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_REPARSE_POINT); if (NT_SUCCESS (f_status)) { diff --git a/winsup/cygwin/local_includes/ntdll.h b/winsup/cygwin/local_includes/ntdll.h index 9605784e32a8..7737ae503c18 100644 --- a/winsup/cygwin/local_includes/ntdll.h +++ b/winsup/cygwin/local_includes/ntdll.h @@ -169,6 +169,13 @@ extern GUID __cygwin_socket_guid; #define FILE_VC_QUOTAS_REBUILDING 0x00000200 #define FILE_VC_VALID_MASK 0x000003ff +#define PHCM_APPLICATION_DEFAULT 0 +#define PHCM_DISGUISE_PLACEHOLDER 1 +#define PHCM_EXPOSE_PLACEHOLDERS 2 +#define PHCM_MAX 2 +#define PHCM_ERROR_INVALID_PARAMETER -1 +#define PHCM_ERROR_NO_TEB -2 + /* IOCTL code to impersonate client of named pipe. */ #define FSCTL_PIPE_DISCONNECT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 1, \ @@ -1639,6 +1646,7 @@ extern "C" BOOLEAN); NTSTATUS RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR, PSID, BOOLEAN); NTSTATUS RtlSetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR, PSID, BOOLEAN); + CHAR RtlSetProcessPlaceholderCompatibilityMode (CHAR); PUCHAR RtlSubAuthorityCountSid (PSID); PULONG RtlSubAuthoritySid (PSID, ULONG); ULONG RtlUnicodeStringToAnsiSize (PUNICODE_STRING); diff --git a/winsup/cygwin/local_includes/path.h b/winsup/cygwin/local_includes/path.h index d19721e0cd3f..cd0cc8a41256 100644 --- a/winsup/cygwin/local_includes/path.h +++ b/winsup/cygwin/local_includes/path.h @@ -23,6 +23,14 @@ has_attribute (DWORD attributes, DWORD attribs_to_test) && (attributes & attribs_to_test); } +extern inline bool +isoffline (DWORD attributes) +{ + return has_attribute (attributes, FILE_ATTRIBUTE_OFFLINE + | FILE_ATTRIBUTE_RECALL_ON_OPEN + | FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS); +} + enum executable_states { is_executable, @@ -236,6 +244,12 @@ class path_conv bool exists () const {return fileattr != INVALID_FILE_ATTRIBUTES;} bool has_attribute (DWORD x) const {return exists () && (fileattr & x);} int isdir () const {return has_attribute (FILE_ATTRIBUTE_DIRECTORY);} + bool isoffline () const + { + return has_attribute (FILE_ATTRIBUTE_OFFLINE + | FILE_ATTRIBUTE_RECALL_ON_OPEN + | FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS); + } executable_states exec_state () { extern int _check_for_executable; @@ -243,7 +257,7 @@ class path_conv return is_executable; if (mount_flags & MOUNT_NOTEXEC) return not_executable; - if (!_check_for_executable) + if (isoffline () || !_check_for_executable) return dont_care_if_executable; return dont_know_if_executable; } diff --git a/winsup/cygwin/local_includes/winlean.h b/winsup/cygwin/local_includes/winlean.h index 113b2c6b0d3f..947109bdeee4 100644 --- a/winsup/cygwin/local_includes/winlean.h +++ b/winsup/cygwin/local_includes/winlean.h @@ -97,6 +97,13 @@ details. */ #define FILE_SUPPORTS_GHOSTING 0x40000000 #endif +#ifndef FILE_ATTRIBUTE_RECALL_ON_OPEN +#define FILE_ATTRIBUTE_RECALL_ON_OPEN 0x00040000 +#endif +#ifndef FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS +#define FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS 0x00400000 +#endif + /* So-called "Microsoft Account" SIDs (S-1-11-...) have a netbios domain name "MicrosoftAccounts". The new "Application Container SIDs" (S-1-15-...) have a netbios domain name "APPLICATION PACKAGE AUTHORITY" diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index b8e5746fdd2a..c0d62e5654b4 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -576,6 +576,7 @@ getfileattr (const char *path, bool caseinsensitive) /* path has to be always ab status = NtOpenFile (&dir, SYNCHRONIZE | FILE_LIST_DIRECTORY, &attr, &io, FILE_SHARE_VALID_FLAGS, FILE_SYNCHRONOUS_IO_NONALERT + | FILE_OPEN_NO_RECALL | FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE); if (NT_SUCCESS (status)) @@ -3191,7 +3192,8 @@ restart: } status = NtOpenFile (&h, READ_CONTROL | FILE_READ_ATTRIBUTES, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_REPARSE_POINT + FILE_OPEN_NO_RECALL + | FILE_OPEN_REPARSE_POINT | FILE_OPEN_FOR_BACKUP_INTENT); debug_printf ("%y = NtOpenFile (no-EAs %S)", status, &upath); } @@ -3319,6 +3321,7 @@ restart: status = NtOpenFile (&dir, SYNCHRONIZE | FILE_LIST_DIRECTORY, &dattr, &io, FILE_SHARE_VALID_FLAGS, FILE_SYNCHRONOUS_IO_NONALERT + | FILE_OPEN_NO_RECALL | FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE); if (!NT_SUCCESS (status)) @@ -3408,7 +3411,11 @@ restart: directory using a relative path, symlink evaluation goes totally awry. We never want a virtual drive evaluated as symlink. */ if (upath.Length <= 14) - goto file_not_symlink; + goto file_not_symlink; + + /* Offline files, even if reparse points, are not symlinks. */ + if (isoffline (fileattr)) + goto file_not_symlink; /* Reparse points are potentially symlinks. This check must be performed before checking the SYSTEM attribute for sysfile @@ -3454,7 +3461,8 @@ restart: status = NtOpenFile (&sym_h, SYNCHRONIZE | GENERIC_READ, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT); if (!NT_SUCCESS (status)) res = 0; @@ -3508,7 +3516,8 @@ restart: status = NtOpenFile (&sym_h, SYNCHRONIZE | GENERIC_READ, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT); if (!NT_SUCCESS (status))
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=06aa5a751682118ef1d7f2456f8937b4ac181fac commit 06aa5a751682118ef1d7f2456f8937b4ac181fac Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 8 21:54:58 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Fri Mar 8 21:54:58 2024 +0100 Cygwin: FS_IOC_[GS]ETFLAGS: handle pinned and unpinned attributes Add FS_PINNED_FL and FS_UNPINNED_FL flags and handle them with mode bits 'p' and 'u' in chattr(1) and lsattr(1). Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/fhandler/disk_file.cc | 4 +++- winsup/cygwin/include/cygwin/fs.h | 6 ++++-- winsup/doc/utils.xml | 6 +++++- winsup/utils/chattr.c | 8 ++++++-- winsup/utils/lsattr.c | 6 +++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/disk_file.cc index f3592148fc5b..9aadbb539f01 100644 --- a/winsup/cygwin/fhandler/disk_file.cc +++ b/winsup/cygwin/fhandler/disk_file.cc @@ -2763,7 +2763,9 @@ fhandler_disk_file::fs_ioc_getflags () | FS_SYSTEM_FL \ | FS_ARCHIVE_FL \ | FS_TEMP_FL \ - | FS_NOTINDEXED_FL) + | FS_NOTINDEXED_FL\ + | FS_PINNED_FL \ + | FS_UNPINNED_FL) int fhandler_disk_file::fs_ioc_setflags (uint64_t flags) diff --git a/winsup/cygwin/include/cygwin/fs.h b/winsup/cygwin/include/cygwin/fs.h index 9b4baf30227a..76d92453808d 100644 --- a/winsup/cygwin/include/cygwin/fs.h +++ b/winsup/cygwin/include/cygwin/fs.h @@ -41,10 +41,12 @@ details. */ #define FS_OFFLINE_FL 0x000001000ULL /* DOS Offline */ #define FS_NOTINDEXED_FL 0x000002000ULL /* DOS Not context indexed */ #define FS_ENCRYPT_FL 0x000004000ULL /* Encrypted file */ +#define FS_PINNED_FL 0x000080000ULL /* Pinned file */ +#define FS_UNPINNED_FL 0x000100000ULL /* Unpinned file */ #define FS_CASESENS_FL 0x100000000ULL /* Case sensitive dir */ -#define FS_FL_USER_VISIBLE 0x100007f27ULL /* User visible flags */ -#define FS_FL_USER_MODIFIABLE 0x100006b27ULL /* User modifiable flags */ +#define FS_FL_USER_VISIBLE 0x100187f27ULL /* User visible flags */ +#define FS_FL_USER_MODIFIABLE 0x100186b27ULL /* User modifiable flags */ /* Flags for renameat2, from /usr/include/linux/fs.h. For now we support only RENAME_NOREPLACE. */ diff --git a/winsup/doc/utils.xml b/winsup/doc/utils.xml index b93671b16dba..fbb39f5f2791 100644 --- a/winsup/doc/utils.xml +++ b/winsup/doc/utils.xml @@ -68,7 +68,7 @@ case sensitivity. </para> - <para>The format of 'mode' is {+-=}[acCehnrsSt]</para> + <para>The format of 'mode' is {+-=}[acCehnprsStu]</para> <para>The operator '+' causes the selected attributes to be added to the existing attributes of the files; '-' causes them to be removed; and @@ -88,6 +88,8 @@ 'n', 'Notindexed': file or directory is not to be indexed by the content indexing service 'e', 'Encrypted': file is encrypted + 'p', 'Pinned': file is pinned + 'u', 'Unpinned': file is unpinned 'C', 'Casesensitive': directory is handled case sensitive </screen> </refsect1> @@ -1448,6 +1450,8 @@ bash$ locale noexpr 'n', 'Notindexed': file or directory is not to be indexed by the content indexing service 'e', 'Encrypted': file is encrypted + 'p', 'Pinned': file is pinned + 'u', 'Unpinned': file is unpinned 'C', 'Casesensitive': directory is handled case sensitive (Windows 10 1803 or later, local NTFS only, WSL must be installed) diff --git a/winsup/utils/chattr.c b/winsup/utils/chattr.c index 4b074133cf6f..4ba977112d94 100644 --- a/winsup/utils/chattr.c +++ b/winsup/utils/chattr.c @@ -53,10 +53,12 @@ struct { FS_OFFLINE_FL, 'o', NULL }, { FS_NOTINDEXED_FL, 'n', "Notindexed" }, { FS_ENCRYPT_FL, 'e', "Encrypted" }, + { FS_PINNED_FL, 'p', "Pinned" }, + { FS_UNPINNED_FL, 'u', "Unpinned" }, { FS_CASESENS_FL, 'C', "Casesensitive" }, { 0, '\0', NULL }, }; -const char *supp_list = "rhsatSrconeC"; +const char *supp_list = "rhsatSrconepuC"; void print_flags (uint64_t flags) @@ -245,7 +247,7 @@ usage (FILE *stream) " -H, --help this help text\n" " -v, --version display the program version\n" "\n" - "The format of 'mode' is {+-=}[acCehnrsSt]\n" + "The format of 'mode' is {+-=}[acCehnprsStu]\n" "\n" "The operator '+' causes the selected attributes to be added to the\n" "existing attributes of the files; '-' causes them to be removed; and\n" @@ -264,6 +266,8 @@ usage (FILE *stream) " 'n', 'Notindexed': file or directory is not to be indexed by the\n" " content indexing service\n" " 'e', 'Encrypted': file is encrypted\n" + " 'p', 'Pinned': file is pinned\n" + " 'u', 'Unpinned': file is unpinned\n" " 'C', 'Casesensitive': directory is handled case sensitive\n"); exit (stream == stdout ? 0 : 1); } diff --git a/winsup/utils/lsattr.c b/winsup/utils/lsattr.c index 70022803d068..50935f682ea5 100644 --- a/winsup/utils/lsattr.c +++ b/winsup/utils/lsattr.c @@ -53,6 +53,8 @@ struct { FS_OFFLINE_FL, 'o', "Offline" }, { FS_NOTINDEXED_FL, 'n', "Notindexed" }, { FS_ENCRYPT_FL, 'e', "Encrypted" }, + { FS_PINNED_FL, 'p', "Pinned" }, + { FS_UNPINNED_FL, 'u', "Unpinned" }, { FS_CASESENS_FL, 'C', "Casesensitive" }, { 0, '\0', NULL }, }; @@ -218,6 +220,8 @@ usage (FILE *stream) " 'n', 'Notindexed': file or directory is not to be indexed by the\n" " content indexing service\n" " 'e', 'Encrypted': file is encrypted\n" + " 'p', 'Pinned': file is pinned\n" + " 'u', 'Unpinned': file is unpinned\n" " 'C', 'Casesensitive': directory is handled case sensitive\n" " (Windows 10 1803 or later, local NTFS only,\n" " WSL must be installed)\n"); @@ -284,7 +288,7 @@ main (int argc, char **argv) ret = 1; } else if (lsattr (argv[optind])) - ret = 1; + ret = 1; } return ret; }
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2100c6ef0dee120c316b7bea42bf5e93c281e808 commit 2100c6ef0dee120c316b7bea42bf5e93c281e808 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 8 21:30:57 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Fri Mar 8 21:30:57 2024 +0100 Cygwin: get/set security descriptors using FILE_OPEN_NO_RECALL Add FILE_OPEN_NO_RECALL to NtOpenFile calls trying to fetch or write file security descriptors so as not to recall them from offline storage inadvertently. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/sec/base.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/sec/base.cc b/winsup/cygwin/sec/base.cc index 8b04b40b4943..0fc8699bfc9e 100644 --- a/winsup/cygwin/sec/base.cc +++ b/winsup/cygwin/sec/base.cc @@ -65,7 +65,8 @@ get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, fh ? pc.init_reopen_attr (attr, fh) : pc.get_object_attr (attr, sec_none_nih), &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | pc.is_known_reparse_point () ? FILE_OPEN_REPARSE_POINT : 0); if (!NT_SUCCESS (status)) @@ -129,7 +130,8 @@ get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, NULL, NULL); status = NtOpenFile (&fh, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_REPARSE_POINT); if (!NT_SUCCESS (status)) { @@ -234,7 +236,8 @@ set_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, bool is_chown) : pc.get_object_attr (attr, sec_none_nih), &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | pc.is_known_reparse_point () ? FILE_OPEN_REPARSE_POINT : 0); if (!NT_SUCCESS (status))
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=f6b56abec1865f8da7632644210bae36b395569b commit f6b56abec1865f8da7632644210bae36b395569b Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 8 20:57:06 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Fri Mar 8 20:57:06 2024 +0100 Cygwin: try to avoid recalling offline files Chances are high that Cygwin recalls offline files from remote storage, even if the file is only accessed during stat(2) or readdir(3). To avoid this - make sure Cygwin is placeholder-aware, - open files in path_conv handling, as well as in stat(2)/readdir(3) scenarios with FILE_OPEN_NO_RECALL, and - during symlink checking or testing for executablility, don't even try to open the file if one of the OFFLINE attributes is set. Reported-by: Marcin Wisnicki <mwisnicki@gmail.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/autoload.cc | 1 + winsup/cygwin/dcrt0.cc | 3 +++ winsup/cygwin/fhandler/disk_file.cc | 20 ++++++++++++++------ winsup/cygwin/local_includes/ntdll.h | 8 ++++++++ winsup/cygwin/local_includes/path.h | 16 +++++++++++++++- winsup/cygwin/local_includes/winlean.h | 7 +++++++ winsup/cygwin/path.cc | 19 ++++++++++++++----- 7 files changed, 62 insertions(+), 12 deletions(-) diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index 65e906e8b9d0..cc9dafe1b621 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -479,6 +479,7 @@ LoadDLLfuncEx (SetThreadDescription, KernelBase, 1) LoadDLLfunc (VirtualAlloc2, KernelBase) LoadDLLfunc (NtMapViewOfSectionEx, ntdll) +LoadDLLfuncEx (RtlSetProcessPlaceholderCompatibilityMode, ntdll, 1) LoadDLLfunc (ldap_bind_s, wldap32) LoadDLLfunc (ldap_count_entries, wldap32) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index a40129c22232..7229377eb3fe 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -809,6 +809,9 @@ dll_crt0_1 (void *) if (dynamically_loaded) sigproc_init (); + /* Call this before accessing any files. */ + RtlSetProcessPlaceholderCompatibilityMode (PHCM_EXPOSE_PLACEHOLDERS); + check_sanity_and_sync (user_data); /* Initialize malloc and then call user_shared_initialize since it relies diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/disk_file.cc index d08fe9160d35..f3592148fc5b 100644 --- a/winsup/cygwin/fhandler/disk_file.cc +++ b/winsup/cygwin/fhandler/disk_file.cc @@ -176,7 +176,9 @@ readdir_check_reparse_point (POBJECT_ATTRIBUTES attr, bool remote) bool ret = false; status = NtOpenFile (&reph, READ_CONTROL, attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_REPARSE_POINT); + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT + | FILE_OPEN_REPARSE_POINT); if (NT_SUCCESS (status)) { PREPARSE_DATA_BUFFER rp = (PREPARSE_DATA_BUFFER) tp.c_get (); @@ -328,6 +330,7 @@ fhandler_base::fstat_by_name (struct stat *buf) status = NtOpenFile (&dir, SYNCHRONIZE | FILE_LIST_DIRECTORY, &attr, &io, FILE_SHARE_VALID_FLAGS, FILE_SYNCHRONOUS_IO_NONALERT + | FILE_OPEN_NO_RECALL | FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE); if (!NT_SUCCESS (status)) @@ -616,7 +619,8 @@ fhandler_disk_file::fstatvfs (struct statvfs *sfs) opened = NT_SUCCESS (NtOpenFile (&fh, READ_CONTROL, pc.get_object_attr (attr, sec_none_nih), &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT)); + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT)); if (!opened) { /* Can't open file. Try again with parent dir. */ @@ -625,7 +629,8 @@ fhandler_disk_file::fstatvfs (struct statvfs *sfs) attr.ObjectName = &dirname; opened = NT_SUCCESS (NtOpenFile (&fh, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT)); + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT)); if (!opened) goto out; } @@ -2323,7 +2328,8 @@ readdir_get_ino (const char *path, bool dot_dot) || NT_SUCCESS (NtOpenFile (&hdl, READ_CONTROL, pc.get_object_attr (attr, sec_none_nih), &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | (pc.is_known_reparse_point () ? FILE_OPEN_REPARSE_POINT : 0))) ) @@ -2372,8 +2378,9 @@ fhandler_disk_file::readdir_helper (DIR *dir, dirent *de, DWORD w32_err, Mountpoints and unknown or unhandled reparse points will be treated as normal file/directory/unknown. In all cases, returning the INO of the reparse point (not of the target) matches behavior of posix systems. + Unless the file is OFFLINE. *. */ - if (attr & FILE_ATTRIBUTE_REPARSE_POINT) + if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) && !isoffline (attr)) { OBJECT_ATTRIBUTES oattr; @@ -2618,7 +2625,8 @@ go_ahead: &nfs_aol_ffei, sizeof nfs_aol_ffei) : NtOpenFile (&hdl, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_REPARSE_POINT); if (NT_SUCCESS (f_status)) { diff --git a/winsup/cygwin/local_includes/ntdll.h b/winsup/cygwin/local_includes/ntdll.h index 9605784e32a8..7737ae503c18 100644 --- a/winsup/cygwin/local_includes/ntdll.h +++ b/winsup/cygwin/local_includes/ntdll.h @@ -169,6 +169,13 @@ extern GUID __cygwin_socket_guid; #define FILE_VC_QUOTAS_REBUILDING 0x00000200 #define FILE_VC_VALID_MASK 0x000003ff +#define PHCM_APPLICATION_DEFAULT 0 +#define PHCM_DISGUISE_PLACEHOLDER 1 +#define PHCM_EXPOSE_PLACEHOLDERS 2 +#define PHCM_MAX 2 +#define PHCM_ERROR_INVALID_PARAMETER -1 +#define PHCM_ERROR_NO_TEB -2 + /* IOCTL code to impersonate client of named pipe. */ #define FSCTL_PIPE_DISCONNECT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 1, \ @@ -1639,6 +1646,7 @@ extern "C" BOOLEAN); NTSTATUS RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR, PSID, BOOLEAN); NTSTATUS RtlSetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR, PSID, BOOLEAN); + CHAR RtlSetProcessPlaceholderCompatibilityMode (CHAR); PUCHAR RtlSubAuthorityCountSid (PSID); PULONG RtlSubAuthoritySid (PSID, ULONG); ULONG RtlUnicodeStringToAnsiSize (PUNICODE_STRING); diff --git a/winsup/cygwin/local_includes/path.h b/winsup/cygwin/local_includes/path.h index 4e62287f6a6e..cb8c4ca9f4d6 100644 --- a/winsup/cygwin/local_includes/path.h +++ b/winsup/cygwin/local_includes/path.h @@ -23,6 +23,14 @@ has_attribute (DWORD attributes, DWORD attribs_to_test) && (attributes & attribs_to_test); } +extern inline bool +isoffline (DWORD attributes) +{ + return has_attribute (attributes, FILE_ATTRIBUTE_OFFLINE + | FILE_ATTRIBUTE_RECALL_ON_OPEN + | FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS); +} + enum executable_states { is_executable, @@ -235,6 +243,12 @@ class path_conv bool exists () const {return fileattr != INVALID_FILE_ATTRIBUTES;} bool has_attribute (DWORD x) const {return exists () && (fileattr & x);} int isdir () const {return has_attribute (FILE_ATTRIBUTE_DIRECTORY);} + bool isoffline () const + { + return has_attribute (FILE_ATTRIBUTE_OFFLINE + | FILE_ATTRIBUTE_RECALL_ON_OPEN + | FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS); + } executable_states exec_state () { extern int _check_for_executable; @@ -242,7 +256,7 @@ class path_conv return is_executable; if (mount_flags & MOUNT_NOTEXEC) return not_executable; - if (!_check_for_executable) + if (isoffline () || !_check_for_executable) return dont_care_if_executable; return dont_know_if_executable; } diff --git a/winsup/cygwin/local_includes/winlean.h b/winsup/cygwin/local_includes/winlean.h index 113b2c6b0d3f..947109bdeee4 100644 --- a/winsup/cygwin/local_includes/winlean.h +++ b/winsup/cygwin/local_includes/winlean.h @@ -97,6 +97,13 @@ details. */ #define FILE_SUPPORTS_GHOSTING 0x40000000 #endif +#ifndef FILE_ATTRIBUTE_RECALL_ON_OPEN +#define FILE_ATTRIBUTE_RECALL_ON_OPEN 0x00040000 +#endif +#ifndef FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS +#define FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS 0x00400000 +#endif + /* So-called "Microsoft Account" SIDs (S-1-11-...) have a netbios domain name "MicrosoftAccounts". The new "Application Container SIDs" (S-1-15-...) have a netbios domain name "APPLICATION PACKAGE AUTHORITY" diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 68639f323972..ddea4b3889eb 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -608,6 +608,7 @@ getfileattr (const char *path, bool caseinsensitive) /* path has to be always ab status = NtOpenFile (&dir, SYNCHRONIZE | FILE_LIST_DIRECTORY, &attr, &io, FILE_SHARE_VALID_FLAGS, FILE_SYNCHRONOUS_IO_NONALERT + | FILE_OPEN_NO_RECALL | FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE); if (NT_SUCCESS (status)) @@ -3208,7 +3209,8 @@ restart: } status = NtOpenFile (&h, READ_CONTROL | FILE_READ_ATTRIBUTES, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_REPARSE_POINT + FILE_OPEN_NO_RECALL + | FILE_OPEN_REPARSE_POINT | FILE_OPEN_FOR_BACKUP_INTENT); debug_printf ("%y = NtOpenFile (no-EAs %S)", status, &upath); } @@ -3336,6 +3338,7 @@ restart: status = NtOpenFile (&dir, SYNCHRONIZE | FILE_LIST_DIRECTORY, &dattr, &io, FILE_SHARE_VALID_FLAGS, FILE_SYNCHRONOUS_IO_NONALERT + | FILE_OPEN_NO_RECALL | FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE); if (!NT_SUCCESS (status)) @@ -3426,12 +3429,16 @@ restart: directory using a relative path, symlink evaluation goes totally awry. We never want a virtual drive evaluated as symlink. */ if (upath.Length <= 14) - goto file_not_symlink; + goto file_not_symlink; + + /* Offline files, even if reparse points, are not symlinks. */ + if (isoffline (fileattr ())) + goto file_not_symlink; /* Reparse points are potentially symlinks. This check must be performed before checking the SYSTEM attribute for sysfile symlinks, since reparse points can have this flag set, too. */ - if ((fileattr () & FILE_ATTRIBUTE_REPARSE_POINT)) + if (fileattr () & FILE_ATTRIBUTE_REPARSE_POINT) { res = check_reparse_point (h, fs.is_remote_drive ()); if (res > 0) @@ -3474,7 +3481,8 @@ restart: status = NtOpenFile (&sym_h, SYNCHRONIZE | GENERIC_READ, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT); if (!NT_SUCCESS (status)) res = 0; @@ -3529,7 +3537,8 @@ restart: status = NtOpenFile (&sym_h, SYNCHRONIZE | GENERIC_READ, &attr, &io, FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT + FILE_OPEN_NO_RECALL + | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT); if (!NT_SUCCESS (status))
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=f2010ed78479b1b6b4518ea79acb6cd36514344f commit f2010ed78479b1b6b4518ea79acb6cd36514344f Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Thu Mar 7 21:50:07 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Thu Mar 7 21:50:07 2024 +0100 Cygwin: move EXPORT_ALIAS expressions to end of source This isn't strictly required, but it avoids confusion in ctags. Ctags fails to record the next function or method following the EXPORT_ALIAS expression. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/exec.cc | 3 ++- winsup/cygwin/random.cc | 4 ++-- winsup/cygwin/sched.cc | 2 +- winsup/cygwin/syscalls.cc | 24 +++++++++--------------- winsup/cygwin/times.cc | 7 +++---- winsup/cygwin/tzcode/localtime_wrapper.c | 3 ++- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/winsup/cygwin/exec.cc b/winsup/cygwin/exec.cc index 2f4041329a65..0e6e535d86cf 100644 --- a/winsup/cygwin/exec.cc +++ b/winsup/cygwin/exec.cc @@ -85,7 +85,6 @@ execve (const char *path, char *const argv[], char *const envp[]) { return spawnve (_P_OVERLAY, path, argv, envp); } -EXPORT_ALIAS (execve, _execve) /* For newlib */ extern "C" int execvp (const char *file, char * const *argv) @@ -126,3 +125,5 @@ sexecve_is_bad () set_errno (ENOSYS); return 0; } + +EXPORT_ALIAS (execve, _execve) /* For newlib */ diff --git a/winsup/cygwin/random.cc b/winsup/cygwin/random.cc index ddba6fb944ec..d33cffada0f0 100644 --- a/winsup/cygwin/random.cc +++ b/winsup/cygwin/random.cc @@ -293,8 +293,6 @@ srandom(unsigned x) __random_unlock(); } -EXPORT_ALIAS (srandom, srand) - /* * initstate: * @@ -490,3 +488,5 @@ rand() } } + +EXPORT_ALIAS (srandom, srand) diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc index 845fcef5702c..71a1e868f9b4 100644 --- a/winsup/cygwin/sched.cc +++ b/winsup/cygwin/sched.cc @@ -411,7 +411,6 @@ sched_yield () SwitchToThread (); return 0; } -EXPORT_ALIAS (sched_yield, pthread_yield) int sched_getcpu () @@ -696,4 +695,5 @@ __cpuset_free (cpu_set_t *set) free (set); } +EXPORT_ALIAS (sched_yield, pthread_yield) } /* extern C */ diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 2c5bf7cbe08b..df7d3a14efd4 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1282,8 +1282,6 @@ read (int fd, void *ptr, size_t len) return (ssize_t) res; } -EXPORT_ALIAS (read, _read) - extern "C" ssize_t readv (int fd, const struct iovec *const iov, const int iovcnt) { @@ -1380,8 +1378,6 @@ write (int fd, const void *ptr, size_t len) return res; } -EXPORT_ALIAS (write, _write) - extern "C" ssize_t writev (const int fd, const struct iovec *const iov, const int iovcnt) { @@ -1594,8 +1590,6 @@ open (const char *unix_path, int flags, ...) return res; } -EXPORT_ALIAS (open, _open ) - static int posix_getdents_lseek (cygheap_fdget &cfd, off_t pos, int dir) { @@ -1684,8 +1678,6 @@ lseek (int fd, off_t pos, int dir) return res; } -EXPORT_ALIAS (lseek, _lseek) - extern "C" int close (int fd) { @@ -1709,8 +1701,6 @@ close (int fd) return res; } -EXPORT_ALIAS (close, _close) - extern "C" int isatty (int fd) { @@ -1724,7 +1714,6 @@ isatty (int fd) syscall_printf ("%R = isatty(%d)", res, fd); return res; } -EXPORT_ALIAS (isatty, _isatty) extern "C" int link (const char *oldpath, const char *newpath) @@ -1977,8 +1966,6 @@ fsync (int fd) return cfd->fsync (); } -EXPORT_ALIAS (fsync, fdatasync) - static void sync_worker (HANDLE dir, USHORT len, LPCWSTR vol) { @@ -4071,8 +4058,6 @@ utmpname (const char *file) return -1; } -EXPORT_ALIAS (utmpname, utmpxname) - /* Note: do not make NO_COPY */ static struct utmp utmp_data_buf[16]; static unsigned utix = 0; @@ -5128,3 +5113,12 @@ tmpfile (void) set_errno (e); return fp; } + +EXPORT_ALIAS (close, _close) +EXPORT_ALIAS (fsync, fdatasync) +EXPORT_ALIAS (isatty, _isatty) +EXPORT_ALIAS (lseek, _lseek) +EXPORT_ALIAS (open, _open) +EXPORT_ALIAS (read, _read) +EXPORT_ALIAS (utmpname, utmpxname) +EXPORT_ALIAS (write, _write) diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index 71a7210318fa..f6e2692b598c 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -91,8 +91,6 @@ times (struct tms *buf) return tc; } -EXPORT_ALIAS (times, _times) - /* settimeofday: BSD */ extern "C" int settimeofday (const struct timeval *tv, const struct timezone *tz) @@ -192,8 +190,6 @@ gettimeofday (struct timeval *__restrict tv, void *__restrict tzvp) return 0; } -EXPORT_ALIAS (gettimeofday, _gettimeofday) - /* Cygwin internal */ void timespec_to_filetime (const struct timespec *time_in, PLARGE_INTEGER out) @@ -571,3 +567,6 @@ timespec_get (struct timespec *ts, int base) clock_gettime (CLOCK_REALTIME, ts); return base; } + +EXPORT_ALIAS (gettimeofday, _gettimeofday) +EXPORT_ALIAS (times, _times) diff --git a/winsup/cygwin/tzcode/localtime_wrapper.c b/winsup/cygwin/tzcode/localtime_wrapper.c index 4e784480b0f4..41a5bcb63cc9 100644 --- a/winsup/cygwin/tzcode/localtime_wrapper.c +++ b/winsup/cygwin/tzcode/localtime_wrapper.c @@ -124,7 +124,6 @@ tzgetwintzi (char *wildabbr, char *outbuf) #include "localtime.patched.c" // Don't forget these Cygwin-specific additions from this point to EOF -EXPORT_ALIAS (tzset_unlocked, _tzset_unlocked) long __cygwin_gettzoffset (const struct tm *tmp) @@ -150,3 +149,5 @@ __cygwin_gettzname (const struct tm *tmp) #endif return _tzname[tmp->tm_isdst > 0]; } + +EXPORT_ALIAS (tzset_unlocked, _tzset_unlocked)
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c2310061c66a100653fe10762859b8adb6a3d357 commit c2310061c66a100653fe10762859b8adb6a3d357 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Tue Mar 5 23:34:21 2024 +0900 Cygwin: pipe: Simplify chhecking procedure of query_hdl. This patch eliminates verbose NtQueryObject() calls in the procedure to get query_hdl by storing pipe name into fhandler_base::pc when the pipe is created. fhandler_pipe::temporary_query_hdl() uses the storedpipe name rather than the name retrieved by NtQueryObject(). Suggested-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Diff: --- winsup/cygwin/fhandler/pipe.cc | 47 ++++++++++++++++----------------- winsup/cygwin/local_includes/fhandler.h | 5 +--- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc index c877d89d7..29d3b41d9 100644 --- a/winsup/cygwin/fhandler/pipe.cc +++ b/winsup/cygwin/fhandler/pipe.cc @@ -93,6 +93,21 @@ fhandler_pipe::init (HANDLE f, DWORD a, mode_t mode, int64_t uniq_id) even with FILE_SYNCHRONOUS_IO_NONALERT. */ set_pipe_non_blocking (get_device () == FH_PIPER ? true : is_nonblocking ()); + + /* Store pipe name to path_conv pc for query_hdl check */ + if (get_dev () == FH_PIPEW) + { + UNICODE_STRING name; + WCHAR pipename_buf[MAX_PATH]; + __small_swprintf (pipename_buf, L"%S%S-%u-pipe-nt-%p", + &ro_u_npfs, &cygheap->installation_key, + GetCurrentProcessId (), unique_id >> 32); + name.Length = wcslen (pipename_buf) * sizeof (WCHAR); + name.MaximumLength = sizeof (pipename_buf); + name.Buffer = pipename_buf; + pc.set_nt_native_path (&name); + } + return 1; } @@ -1149,6 +1164,8 @@ fhandler_pipe::temporary_query_hdl () tmp_pathbuf tp; OBJECT_NAME_INFORMATION *ntfn = (OBJECT_NAME_INFORMATION *) tp.w_get (); + UNICODE_STRING *name = pc.get_nt_native_path (NULL); + /* Try process handle opened and pipe handle value cached first in order to reduce overhead. */ if (query_hdl_proc && query_hdl_value) @@ -1161,14 +1178,7 @@ fhandler_pipe::temporary_query_hdl () status = NtQueryObject (h, ObjectNameInformation, ntfn, 65536, &len); if (!NT_SUCCESS (status) || !ntfn->Name.Buffer) goto hdl_err; - ntfn->Name.Buffer[ntfn->Name.Length / sizeof (WCHAR)] = L'\0'; - uint64_t key; - DWORD pid; - LONG id; - if (swscanf (ntfn->Name.Buffer, - L"\\Device\\NamedPipe\\%llx-%u-pipe-nt-0x%x", - &key, &pid, &id) == 3 && - key == pipename_key && pid == pipename_pid && id == pipename_id) + if (RtlEqualUnicodeString (name, &ntfn->Name, FALSE)) return h; hdl_err: CloseHandle (h); @@ -1178,24 +1188,13 @@ cache_err: query_hdl_value = NULL; } - status = NtQueryObject (get_handle (), ObjectNameInformation, ntfn, - 65536, &len); - if (!NT_SUCCESS (status) || !ntfn->Name.Buffer) - return NULL; /* Non cygwin pipe? */ - WCHAR name[MAX_PATH]; - int namelen = min (ntfn->Name.Length / sizeof (WCHAR), MAX_PATH-1); - memcpy (name, ntfn->Name.Buffer, namelen * sizeof (WCHAR)); - name[namelen] = L'\0'; - if (swscanf (name, L"\\Device\\NamedPipe\\%llx-%u-pipe-nt-0x%x", - &pipename_key, &pipename_pid, &pipename_id) != 3) + if (name->Length == 0 || name->Buffer == NULL) return NULL; /* Non cygwin pipe? */ - - return get_query_hdl_per_process (name, ntfn); /* Since Win8 */ + return get_query_hdl_per_process (ntfn); /* Since Win8 */ } HANDLE -fhandler_pipe::get_query_hdl_per_process (WCHAR *name, - OBJECT_NAME_INFORMATION *ntfn) +fhandler_pipe::get_query_hdl_per_process (OBJECT_NAME_INFORMATION *ntfn) { winpids pids ((DWORD) 0); @@ -1272,8 +1271,8 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name, ntfn, 65536, &len); if (!NT_SUCCESS (status) || !ntfn->Name.Buffer) goto close_handle; - ntfn->Name.Buffer[ntfn->Name.Length / sizeof (WCHAR)] = L'\0'; - if (wcscmp (name, ntfn->Name.Buffer) == 0) + if (RtlEqualUnicodeString (pc.get_nt_native_path (), + &ntfn->Name, FALSE)) { query_hdl_proc = proc; query_hdl_value = (HANDLE)(intptr_t) phi->Handles[j].HandleValue; diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h index 6ddf37370..8729eb276 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -1216,11 +1216,8 @@ private: HANDLE query_hdl_proc; HANDLE query_hdl_value; HANDLE query_hdl_close_req_evt; - uint64_t pipename_key; - DWORD pipename_pid; - LONG pipename_id; void release_select_sem (const char *); - HANDLE get_query_hdl_per_process (WCHAR *, OBJECT_NAME_INFORMATION *); + HANDLE get_query_hdl_per_process (OBJECT_NAME_INFORMATION *); public: fhandler_pipe ();
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=46bb999a8945f4d3243f560b5cbd71e18113fb01 commit 46bb999a8945f4d3243f560b5cbd71e18113fb01 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Sun Mar 3 13:44:17 2024 +0900 Cygwin: pipe: Give up to use query_hdl for non-cygwin apps. Non-cygwin app may call ReadFile() for empty pipe, which makes NtQueryObject() for ObjectNameInformation block in fhandler_pipe:: get_query_hdl_per_process. Therefore, do not to try to get query_hdl for non-cygwin apps. Addresses: https://github.com/msys2/msys2-runtime/issues/202 Fixes: b531d6b06eeb ("Cygwin: pipe: Introduce temporary query_hdl.") Reported-by: Alisa Sireneva, Johannes Schindelin <Johannes.Schindelin@gmx.de> Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Diff: --- winsup/cygwin/fhandler/pipe.cc | 57 ++++++++++-------------------------------- winsup/cygwin/release/3.5.2 | 4 +++ 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc index 1a97108b5..c877d89d7 100644 --- a/winsup/cygwin/fhandler/pipe.cc +++ b/winsup/cygwin/fhandler/pipe.cc @@ -1197,53 +1197,24 @@ HANDLE fhandler_pipe::get_query_hdl_per_process (WCHAR *name, OBJECT_NAME_INFORMATION *ntfn) { - NTSTATUS status; - ULONG len; - DWORD n_process = 256; - PSYSTEM_PROCESS_INFORMATION spi; - do - { /* Enumerate processes */ - DWORD nbytes = n_process * sizeof (SYSTEM_PROCESS_INFORMATION); - spi = (PSYSTEM_PROCESS_INFORMATION) HeapAlloc (GetProcessHeap (), - 0, nbytes); - if (!spi) - return NULL; - status = NtQuerySystemInformation (SystemProcessInformation, - spi, nbytes, &len); - if (NT_SUCCESS (status)) - break; - HeapFree (GetProcessHeap (), 0, spi); - n_process *= 2; - } - while (n_process < (1L<<20) && status == STATUS_INFO_LENGTH_MISMATCH); - if (!NT_SUCCESS (status)) - return NULL; + winpids pids ((DWORD) 0); - /* In most cases, it is faster to check the processes in reverse order. - To do this, store PIDs into an array. */ - DWORD *proc_pids = (DWORD *) HeapAlloc (GetProcessHeap (), 0, - n_process * sizeof (DWORD)); - if (!proc_pids) + /* In most cases, it is faster to check the processes in reverse order. */ + for (LONG i = (LONG) pids.npids - 1; i >= 0; i--) { - HeapFree (GetProcessHeap (), 0, spi); - return NULL; - } - PSYSTEM_PROCESS_INFORMATION p = spi; - n_process = 0; - while (true) - { - proc_pids[n_process++] = (DWORD)(intptr_t) p->UniqueProcessId; - if (!p->NextEntryOffset) - break; - p = (PSYSTEM_PROCESS_INFORMATION) ((char *) p + p->NextEntryOffset); - } - HeapFree (GetProcessHeap (), 0, spi); + NTSTATUS status; + ULONG len; + + /* Non-cygwin app may call ReadFile() for empty pipe, which makes + NtQueryObject() for ObjectNameInformation block. Therefore, do + not try to get query_hdl for non-cygwin apps. */ + _pinfo *p = pids[i]; + if (!p || ISSTATE (p, PID_NOTCYGWIN)) + continue; - for (LONG i = (LONG) n_process - 1; i >= 0; i--) - { HANDLE proc = OpenProcess (PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION, - 0, proc_pids[i]); + 0, p->dwProcessId); if (!proc) continue; @@ -1307,7 +1278,6 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name, query_hdl_proc = proc; query_hdl_value = (HANDLE)(intptr_t) phi->Handles[j].HandleValue; HeapFree (GetProcessHeap (), 0, phi); - HeapFree (GetProcessHeap (), 0, proc_pids); return h; } close_handle: @@ -1317,6 +1287,5 @@ close_handle: close_proc: CloseHandle (proc); } - HeapFree (GetProcessHeap (), 0, proc_pids); return NULL; } diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2 index fd3c768de..e6782c1c0 100644 --- a/winsup/cygwin/release/3.5.2 +++ b/winsup/cygwin/release/3.5.2 @@ -9,3 +9,7 @@ Fixes: - Fix a race issue between console open() and close() which is caused by state mismatch between con.owner and console attaching state. Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html + +- Fix a problem that select() call for write-side of a pipe possibly + hangs with non-cygwin reader. + Addresses: https://github.com/msys2/msys2-runtime/issues/202
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=f6be372ace889afa12163bd2c8a9cb717d7eff85 commit f6be372ace889afa12163bd2c8a9cb717d7eff85 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Sun Mar 3 13:44:17 2024 +0900 Cygwin: pipe: Give up to use query_hdl for non-cygwin apps. Non-cygwin app may call ReadFile() for empty pipe, which makes NtQueryObject() for ObjectNameInformation block in fhandler_pipe:: get_query_hdl_per_process. Therefore, do not to try to get query_hdl for non-cygwin apps. Addresses: https://github.com/msys2/msys2-runtime/issues/202 Fixes: b531d6b06eeb ("Cygwin: pipe: Introduce temporary query_hdl.") Reported-by: Alisa Sireneva, Johannes Schindelin <Johannes.Schindelin@gmx.de> Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Diff: --- winsup/cygwin/fhandler/pipe.cc | 57 ++++++++++-------------------------------- winsup/cygwin/release/3.5.2 | 4 +++ 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc index 1a97108b5..c877d89d7 100644 --- a/winsup/cygwin/fhandler/pipe.cc +++ b/winsup/cygwin/fhandler/pipe.cc @@ -1197,53 +1197,24 @@ HANDLE fhandler_pipe::get_query_hdl_per_process (WCHAR *name, OBJECT_NAME_INFORMATION *ntfn) { - NTSTATUS status; - ULONG len; - DWORD n_process = 256; - PSYSTEM_PROCESS_INFORMATION spi; - do - { /* Enumerate processes */ - DWORD nbytes = n_process * sizeof (SYSTEM_PROCESS_INFORMATION); - spi = (PSYSTEM_PROCESS_INFORMATION) HeapAlloc (GetProcessHeap (), - 0, nbytes); - if (!spi) - return NULL; - status = NtQuerySystemInformation (SystemProcessInformation, - spi, nbytes, &len); - if (NT_SUCCESS (status)) - break; - HeapFree (GetProcessHeap (), 0, spi); - n_process *= 2; - } - while (n_process < (1L<<20) && status == STATUS_INFO_LENGTH_MISMATCH); - if (!NT_SUCCESS (status)) - return NULL; + winpids pids ((DWORD) 0); - /* In most cases, it is faster to check the processes in reverse order. - To do this, store PIDs into an array. */ - DWORD *proc_pids = (DWORD *) HeapAlloc (GetProcessHeap (), 0, - n_process * sizeof (DWORD)); - if (!proc_pids) + /* In most cases, it is faster to check the processes in reverse order. */ + for (LONG i = (LONG) pids.npids - 1; i >= 0; i--) { - HeapFree (GetProcessHeap (), 0, spi); - return NULL; - } - PSYSTEM_PROCESS_INFORMATION p = spi; - n_process = 0; - while (true) - { - proc_pids[n_process++] = (DWORD)(intptr_t) p->UniqueProcessId; - if (!p->NextEntryOffset) - break; - p = (PSYSTEM_PROCESS_INFORMATION) ((char *) p + p->NextEntryOffset); - } - HeapFree (GetProcessHeap (), 0, spi); + NTSTATUS status; + ULONG len; + + /* Non-cygwin app may call ReadFile() for empty pipe, which makes + NtQueryObject() for ObjectNameInformation block. Therefore, do + not try to get query_hdl for non-cygwin apps. */ + _pinfo *p = pids[i]; + if (!p || ISSTATE (p, PID_NOTCYGWIN)) + continue; - for (LONG i = (LONG) n_process - 1; i >= 0; i--) - { HANDLE proc = OpenProcess (PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION, - 0, proc_pids[i]); + 0, p->dwProcessId); if (!proc) continue; @@ -1307,7 +1278,6 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name, query_hdl_proc = proc; query_hdl_value = (HANDLE)(intptr_t) phi->Handles[j].HandleValue; HeapFree (GetProcessHeap (), 0, phi); - HeapFree (GetProcessHeap (), 0, proc_pids); return h; } close_handle: @@ -1317,6 +1287,5 @@ close_handle: close_proc: CloseHandle (proc); } - HeapFree (GetProcessHeap (), 0, proc_pids); return NULL; } diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2 index fd3c768de..e6782c1c0 100644 --- a/winsup/cygwin/release/3.5.2 +++ b/winsup/cygwin/release/3.5.2 @@ -9,3 +9,7 @@ Fixes: - Fix a race issue between console open() and close() which is caused by state mismatch between con.owner and console attaching state. Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html + +- Fix a problem that select() call for write-side of a pipe possibly + hangs with non-cygwin reader. + Addresses: https://github.com/msys2/msys2-runtime/issues/202
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b160b690b6ace93ee4225f14a9287549e37f4a71 commit b160b690b6ace93ee4225f14a9287549e37f4a71 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Mon Mar 4 11:32:34 2024 +0900 Cygwin: console: Fix a race issue between close() and open(). The open() call for console sometimes fails if the console owner process is closing the console by close() at the same time. This is due to mismatch state of con.owner variable and attaching state to the console. With this patch, checking con.owner and attaching to con.owner sequence in open(), and resetting con.owner and freeing console sequence in close() are guarded by output_mutex to avoid such a race issue. Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from other terminals.") Reported-by: Kate Deplaix <kit-ty-kate@outlook.com> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Diff: --- winsup/cygwin/fhandler/console.cc | 58 +++++++++++++++++++++++---------------- winsup/cygwin/release/3.5.2 | 4 +++ 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc index 67ea95466..1c0d5c815 100644 --- a/winsup/cygwin/fhandler/console.cc +++ b/winsup/cygwin/fhandler/console.cc @@ -687,14 +687,6 @@ fhandler_console::set_unit () { devset = (fh_devices) shared_console_info[unit]->tty_min_state.getntty (); _tc = &(shared_console_info[unit]->tty_min_state); - if (!created) - { - while (con.owner > MAX_PID) - Sleep (1); - pinfo p (con.owner); - if (!p) - con.owner = myself->pid; - } } dev ().parse (devset); @@ -1744,11 +1736,23 @@ fhandler_console::open (int flags, mode_t) set_handle (NULL); set_output_handle (NULL); + setup_io_mutex (); + acquire_output_mutex (mutex_timeout); + + do + { + pinfo p (con.owner); + if (!p) + con.owner = myself->pid; + } + while (false); + /* Open the input handle as handle_ */ bool err = false; DWORD resume_pid = attach_console (con.owner, &err); if (err) { + release_output_mutex (); set_errno (EACCES); return 0; } @@ -1759,6 +1763,7 @@ fhandler_console::open (int flags, mode_t) if (h == INVALID_HANDLE_VALUE) { + release_output_mutex (); __seterrno (); return 0; } @@ -1768,6 +1773,7 @@ fhandler_console::open (int flags, mode_t) resume_pid = attach_console (con.owner, &err); if (err) { + release_output_mutex (); set_errno (EACCES); return 0; } @@ -1778,14 +1784,16 @@ fhandler_console::open (int flags, mode_t) if (h == INVALID_HANDLE_VALUE) { + release_output_mutex (); __seterrno (); return 0; } set_output_handle (h); handle_set.output_handle = h; + release_output_mutex (); + wpbuf.init (); - setup_io_mutex (); handle_set.input_mutex = input_mutex; handle_set.output_mutex = output_mutex; @@ -1895,25 +1903,20 @@ fhandler_console::close () } } - release_output_mutex (); - - if (shared_console_info[unit] && con.owner == myself->pid - && master_thread_started) + if (shared_console_info[unit] && con.owner == myself->pid) { - char name[MAX_PATH]; - shared_name (name, CONS_THREAD_SYNC, get_minor ()); - thread_sync_event = OpenEvent (MAXIMUM_ALLOWED, FALSE, name); - con.owner = MAX_PID + 1; - WaitForSingleObject (thread_sync_event, INFINITE); - CloseHandle (thread_sync_event); + if (master_thread_started) + { + char name[MAX_PATH]; + shared_name (name, CONS_THREAD_SYNC, get_minor ()); + thread_sync_event = OpenEvent (MAXIMUM_ALLOWED, FALSE, name); + con.owner = MAX_PID + 1; + WaitForSingleObject (thread_sync_event, INFINITE); + CloseHandle (thread_sync_event); + } con.owner = 0; } - CloseHandle (input_mutex); - input_mutex = NULL; - CloseHandle (output_mutex); - output_mutex = NULL; - CloseHandle (get_handle ()); CloseHandle (get_output_handle ()); @@ -1926,6 +1929,13 @@ fhandler_console::close () || get_device () == (dev_t) myself->ctty)) free_console (); + release_output_mutex (); + + CloseHandle (input_mutex); + input_mutex = NULL; + CloseHandle (output_mutex); + output_mutex = NULL; + if (shared_console_info[unit] && myself->ctty != tc ()->ntty) { UnmapViewOfFile ((void *) shared_console_info[unit]); diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2 index 7d8df9489..fd3c768de 100644 --- a/winsup/cygwin/release/3.5.2 +++ b/winsup/cygwin/release/3.5.2 @@ -5,3 +5,7 @@ Fixes: is already unmapped due to race condition. To avoid this issue, shared console memory will be kept mapped if it belongs to CTTY. Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255561.html + +- Fix a race issue between console open() and close() which is caused + by state mismatch between con.owner and console attaching state. + Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fc5e9525453fea7c27b0e13635ae54abaa0db69d commit fc5e9525453fea7c27b0e13635ae54abaa0db69d Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Mon Mar 4 11:32:34 2024 +0900 Cygwin: console: Fix a race issue between close() and open(). The open() call for console sometimes fails if the console owner process is closing the console by close() at the same time. This is due to mismatch state of con.owner variable and attaching state to the console. With this patch, checking con.owner and attaching to con.owner sequence in open(), and resetting con.owner and freeing console sequence in close() are guarded by output_mutex to avoid such a race issue. Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from other terminals.") Reported-by: Kate Deplaix <kit-ty-kate@outlook.com> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Diff: --- winsup/cygwin/fhandler/console.cc | 58 +++++++++++++++++++++++---------------- winsup/cygwin/release/3.5.2 | 4 +++ 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc index 67ea95466..1c0d5c815 100644 --- a/winsup/cygwin/fhandler/console.cc +++ b/winsup/cygwin/fhandler/console.cc @@ -687,14 +687,6 @@ fhandler_console::set_unit () { devset = (fh_devices) shared_console_info[unit]->tty_min_state.getntty (); _tc = &(shared_console_info[unit]->tty_min_state); - if (!created) - { - while (con.owner > MAX_PID) - Sleep (1); - pinfo p (con.owner); - if (!p) - con.owner = myself->pid; - } } dev ().parse (devset); @@ -1744,11 +1736,23 @@ fhandler_console::open (int flags, mode_t) set_handle (NULL); set_output_handle (NULL); + setup_io_mutex (); + acquire_output_mutex (mutex_timeout); + + do + { + pinfo p (con.owner); + if (!p) + con.owner = myself->pid; + } + while (false); + /* Open the input handle as handle_ */ bool err = false; DWORD resume_pid = attach_console (con.owner, &err); if (err) { + release_output_mutex (); set_errno (EACCES); return 0; } @@ -1759,6 +1763,7 @@ fhandler_console::open (int flags, mode_t) if (h == INVALID_HANDLE_VALUE) { + release_output_mutex (); __seterrno (); return 0; } @@ -1768,6 +1773,7 @@ fhandler_console::open (int flags, mode_t) resume_pid = attach_console (con.owner, &err); if (err) { + release_output_mutex (); set_errno (EACCES); return 0; } @@ -1778,14 +1784,16 @@ fhandler_console::open (int flags, mode_t) if (h == INVALID_HANDLE_VALUE) { + release_output_mutex (); __seterrno (); return 0; } set_output_handle (h); handle_set.output_handle = h; + release_output_mutex (); + wpbuf.init (); - setup_io_mutex (); handle_set.input_mutex = input_mutex; handle_set.output_mutex = output_mutex; @@ -1895,25 +1903,20 @@ fhandler_console::close () } } - release_output_mutex (); - - if (shared_console_info[unit] && con.owner == myself->pid - && master_thread_started) + if (shared_console_info[unit] && con.owner == myself->pid) { - char name[MAX_PATH]; - shared_name (name, CONS_THREAD_SYNC, get_minor ()); - thread_sync_event = OpenEvent (MAXIMUM_ALLOWED, FALSE, name); - con.owner = MAX_PID + 1; - WaitForSingleObject (thread_sync_event, INFINITE); - CloseHandle (thread_sync_event); + if (master_thread_started) + { + char name[MAX_PATH]; + shared_name (name, CONS_THREAD_SYNC, get_minor ()); + thread_sync_event = OpenEvent (MAXIMUM_ALLOWED, FALSE, name); + con.owner = MAX_PID + 1; + WaitForSingleObject (thread_sync_event, INFINITE); + CloseHandle (thread_sync_event); + } con.owner = 0; } - CloseHandle (input_mutex); - input_mutex = NULL; - CloseHandle (output_mutex); - output_mutex = NULL; - CloseHandle (get_handle ()); CloseHandle (get_output_handle ()); @@ -1926,6 +1929,13 @@ fhandler_console::close () || get_device () == (dev_t) myself->ctty)) free_console (); + release_output_mutex (); + + CloseHandle (input_mutex); + input_mutex = NULL; + CloseHandle (output_mutex); + output_mutex = NULL; + if (shared_console_info[unit] && myself->ctty != tc ()->ntty) { UnmapViewOfFile ((void *) shared_console_info[unit]); diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2 index 7d8df9489..fd3c768de 100644 --- a/winsup/cygwin/release/3.5.2 +++ b/winsup/cygwin/release/3.5.2 @@ -5,3 +5,7 @@ Fixes: is already unmapped due to race condition. To avoid this issue, shared console memory will be kept mapped if it belongs to CTTY. Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255561.html + +- Fix a race issue between console open() and close() which is caused + by state mismatch between con.owner and console attaching state. + Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=abb532a87ff6ed37f6ee2c8a58c65178a15aa345 commit abb532a87ff6ed37f6ee2c8a58c65178a15aa345 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 1 22:27:40 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Fri Mar 1 22:35:22 2024 +0100 Cygwin: cygheap: compute bucket instead of looping over it Start at index 0 and use 32 bytes as minimal allocation size. Reduce NBUCKETS, we don't have such big objects on the cygheap anyway. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/local_includes/cygheap.h | 2 +- winsup/cygwin/mm/cygheap.cc | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/local_includes/cygheap.h b/winsup/cygwin/local_includes/cygheap.h index b6acdf7f18b7..9edd61c28abd 100644 --- a/winsup/cygwin/local_includes/cygheap.h +++ b/winsup/cygwin/local_includes/cygheap.h @@ -487,7 +487,7 @@ struct mini_cygheap cygheap_locale locale; }; -#define NBUCKETS 40 +#define NBUCKETS 32 struct threadlist_t { diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc index c763a0967388..4cc851716fbe 100644 --- a/winsup/cygwin/mm/cygheap.cc +++ b/winsup/cygwin/mm/cygheap.cc @@ -264,15 +264,15 @@ init_cygheap::init_installation_root () /* Initialize bucket_val. The value is the max size of a block fitting into the bucket. The values are powers of two and their - medians: 24, 32, 48, 64, ... + medians: 32, 48, 64, 96, ... The idea is to have better matching bucket sizes (not wasting space) without trading in performance compared to the old powers of 2 method. */ static const uint32_t bucket_val[NBUCKETS] = { - 0, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, - 3072, 4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304, - 131072, 196608, 262144, 393216, 524288, 786432, 1048576, 1572864, 2097152, - 3145728, 4194304, 6291456, 8388608, 12582912 + 32, 48, 64, 96, 128, 192, 256, 384, + 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, + 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304, + 131072, 196608, 262144, 393216, 524288, 786432, 1048576, 1572864 }; void @@ -355,11 +355,15 @@ static void * _cmalloc (unsigned size) { _cmalloc_entry *rvc; - unsigned b; + unsigned b = 0; /* Calculate "bit bucket". */ - for (b = 1; b < NBUCKETS && bucket_val[b] < size; b++) - continue; + if (size > bucket_val[0]) + { + const unsigned clz = __builtin_clzl (size - 1); + b = (59 - clz) << 1; + b -= !((size - 1) & (1 << (62 - clz))); + } if (b >= NBUCKETS) return NULL;
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=5d3e79ec6bb7362cb56765025a5ca756da41a293 commit 5d3e79ec6bb7362cb56765025a5ca756da41a293 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 1 22:24:37 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Fri Mar 1 22:31:33 2024 +0100 Cygwin: cygheap: use SRWLOCK for cygheap locking Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/mm/cygheap.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc index 3dc0c011fae4..c763a0967388 100644 --- a/winsup/cygwin/mm/cygheap.cc +++ b/winsup/cygwin/mm/cygheap.cc @@ -35,7 +35,7 @@ static mini_cygheap NO_COPY cygheap_dummy = init_cygheap NO_COPY *cygheap = (init_cygheap *) &cygheap_dummy; void NO_COPY *cygheap_max; -static NO_COPY muto cygheap_protect; +static NO_COPY SRWLOCK cygheap_protect = SRWLOCK_INIT; struct cygheap_entry { @@ -278,7 +278,6 @@ static const uint32_t bucket_val[NBUCKETS] = { void cygheap_init () { - cygheap_protect.init ("cygheap_protect"); if (cygheap == &cygheap_dummy) { cygheap = (init_cygheap *) VirtualAlloc ((LPVOID) CYGHEAP_STORAGE_LOW, @@ -364,7 +363,7 @@ _cmalloc (unsigned size) if (b >= NBUCKETS) return NULL; - cygheap_protect.acquire (); + AcquireSRWLockExclusive (&cygheap_protect); if (cygheap->buckets[b]) { rvc = (_cmalloc_entry *) cygheap->buckets[b]; @@ -376,7 +375,7 @@ _cmalloc (unsigned size) rvc = (_cmalloc_entry *) _csbrk (bucket_val[b] + sizeof (_cmalloc_entry)); if (!rvc) { - cygheap_protect.release (); + ReleaseSRWLockExclusive (&cygheap_protect); return NULL; } @@ -384,19 +383,19 @@ _cmalloc (unsigned size) rvc->prev = cygheap->chain; cygheap->chain = rvc; } - cygheap_protect.release (); + ReleaseSRWLockExclusive (&cygheap_protect); return rvc->data; } static void _cfree (void *ptr) { - cygheap_protect.acquire (); + AcquireSRWLockExclusive (&cygheap_protect); _cmalloc_entry *rvc = to_cmalloc (ptr); unsigned b = rvc->b; rvc->ptr = cygheap->buckets[b]; cygheap->buckets[b] = (char *) rvc; - cygheap_protect.release (); + ReleaseSRWLockExclusive (&cygheap_protect); } static void *
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e2ea60728cf9de3085cb5f19b899d3470f2399e5 commit e2ea60728cf9de3085cb5f19b899d3470f2399e5 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 1 15:31:57 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Fri Mar 1 15:32:39 2024 +0100 Cygwin: posix_getdents: do not clear attached DIR structure at fork(2) The upcoming POSIX issue 8 will require that posix_getdents after fork() will pick up at the right spot, independently of being called in the parent or in the child process. Remove the expression clearing out the attached DIR after fork. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/fhandler/base.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc index 643236751ab1..e5e9f2325fce 100644 --- a/winsup/cygwin/fhandler/base.cc +++ b/winsup/cygwin/fhandler/base.cc @@ -1636,7 +1636,6 @@ fhandler_base::fixup_after_fork (HANDLE parent) /* POSIX locks are not inherited across fork. */ if (unique_id) del_my_locks (after_fork); - clear_getdents (); } void
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6d936915477ca8f64ecba31c9876103d69827fb2 commit 6d936915477ca8f64ecba31c9876103d69827fb2 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Fri Mar 1 15:16:44 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Fri Mar 1 15:32:39 2024 +0100 Cygwin: lseek: improve seeking posix_getdents descriptors Transfer code lseeking on posix_getdents() directory descriptor into its own static function and rework it so SEEK_END, SEEK_DATA and SEEK_HOLE work here as expected, too. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/syscalls.cc | 83 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 600c6c54e343..2c5bf7cbe08b 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1596,6 +1596,66 @@ open (const char *unix_path, int flags, ...) EXPORT_ALIAS (open, _open ) +static int +posix_getdents_lseek (cygheap_fdget &cfd, off_t pos, int dir) +{ + long cur = cfd->telldir (cfd->getdents_dir ()); + long abs_pos; + + switch (dir) + { + case SEEK_CUR: + abs_pos = cur + pos; + break; + case SEEK_SET: + case SEEK_DATA: + abs_pos = pos; + break; + case SEEK_END: + case SEEK_HOLE: + /* First read full dir to learn end-of-dir position. */ + while (::readdir (cfd->getdents_dir ())) + ; + long eod = cfd->telldir (cfd->getdents_dir ()); + /* Seek back so it looks like nothing happend in error case */ + cfd->seekdir (cfd->getdents_dir (), cur); + if (dir == SEEK_HOLE) + { + if (pos > eod) + { + set_errno (ENXIO); + return -1; + } + abs_pos = eod; + } + else + abs_pos = eod + pos; + break; + } + if (abs_pos < 0) + { + set_errno (EINVAL); + return -1; + } + if (abs_pos != cur) + { + cfd->seekdir (cfd->getdents_dir (), abs_pos); + /* In SEEK_DATA case, check that we didn't seek beyond EOF */ + if (dir == SEEK_DATA || dir == SEEK_HOLE) + { + pos = cfd->telldir (cfd->getdents_dir ()); + if (pos < abs_pos) + { + /* Seek back so it looks like nothing happend */ + cfd->seekdir (cfd->getdents_dir (), cur); + set_errno (ENXIO); + return -1; + } + } + } + return abs_pos; +} + extern "C" off_t lseek (int fd, off_t pos, int dir) { @@ -1612,28 +1672,7 @@ lseek (int fd, off_t pos, int dir) if (cfd < 0) res = -1; else if (cfd->getdents_dir ()) - { - if (dir != SEEK_SET && dir != SEEK_CUR) /* No SEEK_END */ - { - set_errno (EINVAL); - res = -1; - } - else - { - long cur; - - cur = cfd->telldir (cfd->getdents_dir ()); - if (dir == SEEK_CUR && cur == 0) - res = cur; - else - { - if (dir == SEEK_CUR) - pos = cur + pos; - cfd->seekdir (cfd->getdents_dir (), pos); - res = pos; - } - } - } + res = posix_getdents_lseek (cfd, pos, dir); else res = cfd->lseek (pos, dir); }