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>
This commit is contained in:
Corinna Vinschen 2022-11-15 17:22:43 +01:00
parent c3c71e39f9
commit 4e40b21464
4 changed files with 1 additions and 90 deletions

View File

@ -1176,10 +1176,7 @@ cache_err:
&pipename_key, &pipename_pid, &pipename_id) != 3) &pipename_key, &pipename_pid, &pipename_id) != 3)
return NULL; /* Non cygwin pipe? */ return NULL; /* Non cygwin pipe? */
if (wincap.has_query_process_handle_info ())
return get_query_hdl_per_process (name, ntfn); /* Since Win8 */ return get_query_hdl_per_process (name, ntfn); /* Since Win8 */
else
return get_query_hdl_per_system (name, ntfn); /* Win7 */
} }
/* This function is faster than get_query_hdl_per_system(), however, /* This function is faster than get_query_hdl_per_system(), however,
@ -1312,74 +1309,3 @@ close_proc:
HeapFree (GetProcessHeap (), 0, proc_pids); HeapFree (GetProcessHeap (), 0, proc_pids);
return NULL; 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;
}

View File

@ -1195,7 +1195,6 @@ private:
LONG pipename_id; LONG pipename_id;
void release_select_sem (const char *); void release_select_sem (const char *);
HANDLE get_query_hdl_per_process (WCHAR *, OBJECT_NAME_INFORMATION *); HANDLE get_query_hdl_per_process (WCHAR *, OBJECT_NAME_INFORMATION *);
HANDLE get_query_hdl_per_system (WCHAR *, OBJECT_NAME_INFORMATION *);
public: public:
fhandler_pipe (); fhandler_pipe ();

View File

@ -32,7 +32,6 @@ struct wincaps
unsigned has_tcp_fastopen : 1; unsigned has_tcp_fastopen : 1;
unsigned has_linux_tcp_keepalive_sockopts : 1; unsigned has_linux_tcp_keepalive_sockopts : 1;
unsigned has_tcp_maxrtms : 1; unsigned has_tcp_maxrtms : 1;
unsigned has_query_process_handle_info : 1;
unsigned has_con_broken_tabs : 1; unsigned has_con_broken_tabs : 1;
unsigned has_broken_attach_console : 1; unsigned has_broken_attach_console : 1;
unsigned cons_need_small_input_record_buf : 1; unsigned cons_need_small_input_record_buf : 1;
@ -87,7 +86,6 @@ public:
bool IMPLEMENT (has_tcp_fastopen) bool IMPLEMENT (has_tcp_fastopen)
bool IMPLEMENT (has_linux_tcp_keepalive_sockopts) bool IMPLEMENT (has_linux_tcp_keepalive_sockopts)
bool IMPLEMENT (has_tcp_maxrtms) bool IMPLEMENT (has_tcp_maxrtms)
bool IMPLEMENT (has_query_process_handle_info)
bool IMPLEMENT (has_con_broken_tabs) bool IMPLEMENT (has_con_broken_tabs)
bool IMPLEMENT (has_broken_attach_console) bool IMPLEMENT (has_broken_attach_console)
bool IMPLEMENT (cons_need_small_input_record_buf) bool IMPLEMENT (cons_need_small_input_record_buf)

View File

@ -39,7 +39,6 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = {
has_tcp_fastopen:false, has_tcp_fastopen:false,
has_linux_tcp_keepalive_sockopts:false, has_linux_tcp_keepalive_sockopts:false,
has_tcp_maxrtms:false, has_tcp_maxrtms:false,
has_query_process_handle_info:false,
has_con_broken_tabs:false, has_con_broken_tabs:false,
has_broken_attach_console:true, has_broken_attach_console:true,
cons_need_small_input_record_buf: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_tcp_fastopen:false,
has_linux_tcp_keepalive_sockopts:false, has_linux_tcp_keepalive_sockopts:false,
has_tcp_maxrtms:false, has_tcp_maxrtms:false,
has_query_process_handle_info:true,
has_con_broken_tabs:false, has_con_broken_tabs:false,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:false,
has_linux_tcp_keepalive_sockopts:false, has_linux_tcp_keepalive_sockopts:false,
has_tcp_maxrtms:false, has_tcp_maxrtms:false,
has_query_process_handle_info:true,
has_con_broken_tabs:false, has_con_broken_tabs:false,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:false,
has_linux_tcp_keepalive_sockopts:false, has_linux_tcp_keepalive_sockopts:false,
has_tcp_maxrtms:false, has_tcp_maxrtms:false,
has_query_process_handle_info:true,
has_con_broken_tabs:false, has_con_broken_tabs:false,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:true,
has_linux_tcp_keepalive_sockopts:false, has_linux_tcp_keepalive_sockopts:false,
has_tcp_maxrtms:true, has_tcp_maxrtms:true,
has_query_process_handle_info:true,
has_con_broken_tabs:false, has_con_broken_tabs:false,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:true,
has_linux_tcp_keepalive_sockopts:false, has_linux_tcp_keepalive_sockopts:false,
has_tcp_maxrtms:true, has_tcp_maxrtms:true,
has_query_process_handle_info:true,
has_con_broken_tabs:true, has_con_broken_tabs:true,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:true,
has_linux_tcp_keepalive_sockopts:true, has_linux_tcp_keepalive_sockopts:true,
has_tcp_maxrtms:true, has_tcp_maxrtms:true,
has_query_process_handle_info:true,
has_con_broken_tabs:true, has_con_broken_tabs:true,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:true,
has_linux_tcp_keepalive_sockopts:true, has_linux_tcp_keepalive_sockopts:true,
has_tcp_maxrtms:true, has_tcp_maxrtms:true,
has_query_process_handle_info:true,
has_con_broken_tabs:true, has_con_broken_tabs:true,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:true,
has_linux_tcp_keepalive_sockopts:true, has_linux_tcp_keepalive_sockopts:true,
has_tcp_maxrtms:true, has_tcp_maxrtms:true,
has_query_process_handle_info:true,
has_con_broken_tabs:true, has_con_broken_tabs:true,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:true,
has_linux_tcp_keepalive_sockopts:true, has_linux_tcp_keepalive_sockopts:true,
has_tcp_maxrtms:true, has_tcp_maxrtms:true,
has_query_process_handle_info:true,
has_con_broken_tabs:true, has_con_broken_tabs:true,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:true,
has_linux_tcp_keepalive_sockopts:true, has_linux_tcp_keepalive_sockopts:true,
has_tcp_maxrtms:true, has_tcp_maxrtms:true,
has_query_process_handle_info:true,
has_con_broken_tabs:true, has_con_broken_tabs:true,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf: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_tcp_fastopen:true,
has_linux_tcp_keepalive_sockopts:true, has_linux_tcp_keepalive_sockopts:true,
has_tcp_maxrtms:true, has_tcp_maxrtms:true,
has_query_process_handle_info:true,
has_con_broken_tabs:false, has_con_broken_tabs:false,
has_broken_attach_console:false, has_broken_attach_console:false,
cons_need_small_input_record_buf:false, cons_need_small_input_record_buf:false,