From e7d0f0eb411f952f708ed12768ad556c136030e6 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 12 Jan 2023 10:33:52 +0100 Subject: [PATCH] Cygwin: wincap: make capability flags readonly So far the capability bits were stored in the .cygwin_dll_common R/W section because we overwrite the is_server bit. Just don't. Move the bit to class wincapc instead and define all wincaps bitfields const. Fixes: 8937c103ed141 ("* wincap.cc (all wincaps): Store in .cygwin_dll_common section same as wincap. Add comment to explain why.") Signed-off-by: Corinna Vinschen --- winsup/cygwin/local_includes/wincap.h | 6 ++--- winsup/cygwin/wincap.cc | 38 ++++++++------------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/winsup/cygwin/local_includes/wincap.h b/winsup/cygwin/local_includes/wincap.h index c6dbd2311..29a7a63de 100644 --- a/winsup/cygwin/local_includes/wincap.h +++ b/winsup/cygwin/local_includes/wincap.h @@ -16,7 +16,6 @@ struct wincaps /* The bitfields must be 8 byte aligned on x86_64, otherwise the bitfield ops generated by gcc are off by 4 bytes. */ struct __attribute__ ((aligned (8))) { - unsigned is_server : 1; unsigned has_new_pebteb_region : 1; unsigned has_unprivileged_createsymlink : 1; unsigned has_precise_interrupt_time : 1; @@ -41,7 +40,8 @@ class wincapc SYSTEM_INFO system_info; RTL_OSVERSIONINFOEXW version; char osnam[40]; - void *caps; + const void *caps; + bool _is_server; public: void init (); @@ -67,7 +67,7 @@ public: { return DEFAULT_GUARD_PAGE_COUNT * page_size (); } - bool IMPLEMENT (is_server) + bool is_server () const { return _is_server; } bool IMPLEMENT (has_new_pebteb_region) bool IMPLEMENT (has_unprivileged_createsymlink) bool IMPLEMENT (has_precise_interrupt_time) diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index cc10e90dc..91d5d9df8 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -13,15 +13,8 @@ details. */ #include "ntdll.h" #include "memory_layout.h" -/* CV, 2008-10-23: All wincapc's have to be in the .cygwin_dll_common section, - same as wincap itself. Otherwise the capability changes made in - wincapc::init() are not propagated to any subsequently started process - in the same session. I'm only writing this longish comment because I'm - puzzled that this has never been noticed before... */ - -wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_8_1 = { { - is_server:false, has_new_pebteb_region:false, has_unprivileged_createsymlink:false, has_precise_interrupt_time:false, @@ -41,9 +34,8 @@ wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = { }, }; -wincaps wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_10_1507 = { { - is_server:false, has_new_pebteb_region:false, has_unprivileged_createsymlink:false, has_precise_interrupt_time:true, @@ -63,9 +55,8 @@ wincaps wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared)) }, }; -wincaps wincap_10_1607 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_10_1607 = { { - is_server:false, has_new_pebteb_region:false, has_unprivileged_createsymlink:false, has_precise_interrupt_time:true, @@ -85,9 +76,8 @@ wincaps wincap_10_1607 __attribute__((section (".cygwin_dll_common"), shared)) }, }; -wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_10_1703 = { { - is_server:false, has_new_pebteb_region:true, has_unprivileged_createsymlink:true, has_precise_interrupt_time:true, @@ -107,9 +97,8 @@ wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) = }, }; -wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_10_1709 = { { - is_server:false, has_new_pebteb_region:true, has_unprivileged_createsymlink:true, has_precise_interrupt_time:true, @@ -129,9 +118,8 @@ wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) = }, }; -wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_10_1803 = { { - is_server:false, has_new_pebteb_region:true, has_unprivileged_createsymlink:true, has_precise_interrupt_time:true, @@ -151,9 +139,8 @@ wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) = }, }; -wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_10_1809 = { { - is_server:false, has_new_pebteb_region:true, has_unprivileged_createsymlink:true, has_precise_interrupt_time:true, @@ -173,9 +160,8 @@ wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) = }, }; -wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_10_1903 = { { - is_server:false, has_new_pebteb_region:true, has_unprivileged_createsymlink:true, has_precise_interrupt_time:true, @@ -195,9 +181,8 @@ wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) = }, }; -wincaps wincap_10_2004 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_10_2004 = { { - is_server:false, has_new_pebteb_region:true, has_unprivileged_createsymlink:true, has_precise_interrupt_time:true, @@ -217,9 +202,8 @@ wincaps wincap_10_2004 __attribute__((section (".cygwin_dll_common"), shared)) = }, }; -wincaps wincap_11 __attribute__((section (".cygwin_dll_common"), shared)) = { +static const wincaps wincap_11 = { { - is_server:false, has_new_pebteb_region:true, has_unprivileged_createsymlink:true, has_precise_interrupt_time:true, @@ -284,7 +268,7 @@ wincapc::init () caps = & wincap_10_1507; } - ((wincaps *)caps)->is_server = (version.wProductType != VER_NT_WORKSTATION); + _is_server = (version.wProductType != VER_NT_WORKSTATION); __small_sprintf (osnam, "NT-%d.%d", version.dwMajorVersion, version.dwMinorVersion);