[newlib-cygwin] Cygwin: drop wincap::has_query_process_handle_info

Corinna Vinschen corinna@sourceware.org
Sun Dec 4 13:27:37 GMT 2022


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4e40b214649139623c96923f678f1ee85c90286d

commit 4e40b214649139623c96923f678f1ee85c90286d
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Nov 15 17:22:43 2022 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Sun Dec 4 14:01:41 2022 +0100

    Cygwin: drop wincap::has_query_process_handle_info
    
    Only required for Windows 7.
    
    This allows to remove fhandler_pipe::get_query_hdl_per_system(),
    too.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler/pipe.cc          | 76 +--------------------------------
 winsup/cygwin/local_includes/fhandler.h |  1 -
 winsup/cygwin/local_includes/wincap.h   |  2 -
 winsup/cygwin/wincap.cc                 | 12 ------
 4 files changed, 1 insertion(+), 90 deletions(-)

diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc
index 720e4efd39c2..608a78490879 100644
--- a/winsup/cygwin/fhandler/pipe.cc
+++ b/winsup/cygwin/fhandler/pipe.cc
@@ -1176,10 +1176,7 @@ cache_err:
 	       &pipename_key, &pipename_pid, &pipename_id) != 3)
     return NULL; /* Non cygwin pipe? */
 
-  if (wincap.has_query_process_handle_info ())
-    return get_query_hdl_per_process (name, ntfn); /* Since Win8 */
-  else
-    return get_query_hdl_per_system (name, ntfn); /* Win7 */
+  return get_query_hdl_per_process (name, ntfn); /* Since Win8 */
 }
 
 /* This function is faster than get_query_hdl_per_system(), however,
@@ -1312,74 +1309,3 @@ close_proc:
   HeapFree (GetProcessHeap (), 0, proc_pids);
   return NULL;
 }
-
-/* This function is slower than get_query_hdl_per_process(), however,
-   works even before Windows 8. */
-HANDLE
-fhandler_pipe::get_query_hdl_per_system (WCHAR *name,
-					 OBJECT_NAME_INFORMATION *ntfn)
-{
-  NTSTATUS status;
-  SIZE_T n_handle = 65536;
-  PSYSTEM_HANDLE_INFORMATION shi;
-  do
-    { /* Enumerate handles */
-      SIZE_T nbytes =
-	sizeof (ULONG) + n_handle * sizeof (SYSTEM_HANDLE_TABLE_ENTRY_INFO);
-      shi = (PSYSTEM_HANDLE_INFORMATION) HeapAlloc (GetProcessHeap (),
-						    0, nbytes);
-      if (!shi)
-	return NULL;
-      status = NtQuerySystemInformation (SystemHandleInformation,
-					 shi, nbytes, NULL);
-      if (NT_SUCCESS (status))
-	break;
-      HeapFree (GetProcessHeap (), 0, shi);
-      n_handle *= 2;
-    }
-  while (n_handle < (1L<<23) && status == STATUS_INFO_LENGTH_MISMATCH);
-  if (!NT_SUCCESS (status))
-    return NULL;
-
-  for (LONG i = (LONG) shi->NumberOfHandles - 1; i >= 0; i--)
-    {
-      /* Check for the peculiarity of cygwin read pipe */
-      const ULONG access = FILE_READ_DATA | FILE_READ_EA
-	| FILE_WRITE_EA /* marker */
-	| FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES
-	| READ_CONTROL | SYNCHRONIZE;
-      if (shi->Handles[i].GrantedAccess != access)
-	continue;
-
-      /* Retrieve handle */
-      HANDLE proc = OpenProcess (PROCESS_DUP_HANDLE, 0,
-				 shi->Handles[i].UniqueProcessId);
-      if (!proc)
-	continue;
-      HANDLE h = (HANDLE)(intptr_t) shi->Handles[i].HandleValue;
-      BOOL res  = DuplicateHandle (proc, h, GetCurrentProcess (), &h,
-				   FILE_READ_DATA, 0, 0);
-      if (!res)
-	goto close_proc;
-
-      /* Check object name */
-      ULONG len;
-      status = NtQueryObject (h, ObjectNameInformation, 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)
-	{
-	  query_hdl_proc = proc;
-	  query_hdl_value = (HANDLE)(intptr_t) shi->Handles[i].HandleValue;
-	  HeapFree (GetProcessHeap (), 0, shi);
-	  return h;
-	}
-close_handle:
-      CloseHandle (h);
-close_proc:
-      CloseHandle (proc);
-    }
-  HeapFree (GetProcessHeap (), 0, shi);
-  return NULL;
-}
diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h
index bc02eae66d7f..6671d8a05c60 100644
--- a/winsup/cygwin/local_includes/fhandler.h
+++ b/winsup/cygwin/local_includes/fhandler.h
@@ -1195,7 +1195,6 @@ private:
   LONG pipename_id;
   void release_select_sem (const char *);
   HANDLE get_query_hdl_per_process (WCHAR *, OBJECT_NAME_INFORMATION *);
-  HANDLE get_query_hdl_per_system (WCHAR *, OBJECT_NAME_INFORMATION *);
 public:
   fhandler_pipe ();
 
diff --git a/winsup/cygwin/local_includes/wincap.h b/winsup/cygwin/local_includes/wincap.h
index e123b4bd1845..17d2d74293d1 100644
--- a/winsup/cygwin/local_includes/wincap.h
+++ b/winsup/cygwin/local_includes/wincap.h
@@ -32,7 +32,6 @@ struct wincaps
     unsigned has_tcp_fastopen					: 1;
     unsigned has_linux_tcp_keepalive_sockopts			: 1;
     unsigned has_tcp_maxrtms					: 1;
-    unsigned has_query_process_handle_info			: 1;
     unsigned has_con_broken_tabs				: 1;
     unsigned has_broken_attach_console				: 1;
     unsigned cons_need_small_input_record_buf			: 1;
@@ -87,7 +86,6 @@ public:
   bool	IMPLEMENT (has_tcp_fastopen)
   bool	IMPLEMENT (has_linux_tcp_keepalive_sockopts)
   bool	IMPLEMENT (has_tcp_maxrtms)
-  bool	IMPLEMENT (has_query_process_handle_info)
   bool	IMPLEMENT (has_con_broken_tabs)
   bool	IMPLEMENT (has_broken_attach_console)
   bool	IMPLEMENT (cons_need_small_input_record_buf)
diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc
index 52bdda48d876..c52d4154010c 100644
--- a/winsup/cygwin/wincap.cc
+++ b/winsup/cygwin/wincap.cc
@@ -39,7 +39,6 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = {
     has_tcp_fastopen:false,
     has_linux_tcp_keepalive_sockopts:false,
     has_tcp_maxrtms:false,
-    has_query_process_handle_info:false,
     has_con_broken_tabs:false,
     has_broken_attach_console:true,
     cons_need_small_input_record_buf:true,
@@ -66,7 +65,6 @@ wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = {
     has_tcp_fastopen:false,
     has_linux_tcp_keepalive_sockopts:false,
     has_tcp_maxrtms:false,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:false,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -93,7 +91,6 @@ wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = {
     has_tcp_fastopen:false,
     has_linux_tcp_keepalive_sockopts:false,
     has_tcp_maxrtms:false,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:false,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -120,7 +117,6 @@ wincaps  wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared))
     has_tcp_fastopen:false,
     has_linux_tcp_keepalive_sockopts:false,
     has_tcp_maxrtms:false,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:false,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -147,7 +143,6 @@ wincaps  wincap_10_1607 __attribute__((section (".cygwin_dll_common"), shared))
     has_tcp_fastopen:true,
     has_linux_tcp_keepalive_sockopts:false,
     has_tcp_maxrtms:true,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:false,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -174,7 +169,6 @@ wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_tcp_fastopen:true,
     has_linux_tcp_keepalive_sockopts:false,
     has_tcp_maxrtms:true,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:true,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -201,7 +195,6 @@ wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_tcp_fastopen:true,
     has_linux_tcp_keepalive_sockopts:true,
     has_tcp_maxrtms:true,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:true,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -228,7 +221,6 @@ wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_tcp_fastopen:true,
     has_linux_tcp_keepalive_sockopts:true,
     has_tcp_maxrtms:true,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:true,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -255,7 +247,6 @@ wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_tcp_fastopen:true,
     has_linux_tcp_keepalive_sockopts:true,
     has_tcp_maxrtms:true,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:true,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -282,7 +273,6 @@ wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_tcp_fastopen:true,
     has_linux_tcp_keepalive_sockopts:true,
     has_tcp_maxrtms:true,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:true,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -309,7 +299,6 @@ wincaps wincap_10_2004 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_tcp_fastopen:true,
     has_linux_tcp_keepalive_sockopts:true,
     has_tcp_maxrtms:true,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:true,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,
@@ -336,7 +325,6 @@ wincaps wincap_11 __attribute__((section (".cygwin_dll_common"), shared)) = {
     has_tcp_fastopen:true,
     has_linux_tcp_keepalive_sockopts:true,
     has_tcp_maxrtms:true,
-    has_query_process_handle_info:true,
     has_con_broken_tabs:false,
     has_broken_attach_console:false,
     cons_need_small_input_record_buf:false,


More information about the Cygwin-cvs mailing list