From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 7792A38582AC; Wed, 6 Mar 2024 13:06:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7792A38582AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1709730390; bh=uXkAbi5BmElbXo4ekpomGuSgIHARC/3xG7ZvIbx2+G8=; h=From:To:Subject:Date:From; b=qKi92Qgpnm10tRJZyuqFEtSIU4LIBEFl5SBBtnlbgMZYkuFLi+IDxReb+lelBUZPx 7bMnT0bwpL59rcwkw7GflgT3PuK93/mEKPF1SZTFvy2qWNPthqV11J3UdTq5/1V4wA IWYTPKKrAz0dFc5W7/yPAQJ4UBz3L+0QqqYlfsDc= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pipe: Simplify chhecking procedure of query_hdl. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 46bb999a8945f4d3243f560b5cbd71e18113fb01 X-Git-Newrev: c2310061c66a100653fe10762859b8adb6a3d357 Message-Id: <20240306130630.7792A38582AC@sourceware.org> Date: Wed, 6 Mar 2024 13:06:30 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dc2310061c66= a100653fe10762859b8adb6a3d357 commit c2310061c66a100653fe10762859b8adb6a3d357 Author: Takashi Yano Date: Tue Mar 5 23:34:21 2024 +0900 Cygwin: pipe: Simplify chhecking procedure of query_hdl. =20 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(). =20 Suggested-by: Corinna Vinschen Signed-off-by: Takashi Yano 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, int= 64_t uniq_id) even with FILE_SYNCHRONOUS_IO_NONALERT. */ set_pipe_non_blocking (get_device () =3D=3D FH_PIPER ? true : is_nonblocking ()); + + /* Store pipe name to path_conv pc for query_hdl check */ + if (get_dev () =3D=3D 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 =3D wcslen (pipename_buf) * sizeof (WCHAR); + name.MaximumLength =3D sizeof (pipename_buf); + name.Buffer =3D pipename_buf; + pc.set_nt_native_path (&name); + } + return 1; } =20 @@ -1149,6 +1164,8 @@ fhandler_pipe::temporary_query_hdl () tmp_pathbuf tp; OBJECT_NAME_INFORMATION *ntfn =3D (OBJECT_NAME_INFORMATION *) tp.w_get (= ); =20 + UNICODE_STRING *name =3D 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 =3D NtQueryObject (h, ObjectNameInformation, ntfn, 65536, &le= n); if (!NT_SUCCESS (status) || !ntfn->Name.Buffer) goto hdl_err; - ntfn->Name.Buffer[ntfn->Name.Length / sizeof (WCHAR)] =3D 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) =3D=3D 3 && - key =3D=3D pipename_key && pid =3D=3D pipename_pid && id =3D=3D pipenam= e_id) + if (RtlEqualUnicodeString (name, &ntfn->Name, FALSE)) return h; hdl_err: CloseHandle (h); @@ -1178,24 +1188,13 @@ cache_err: query_hdl_value =3D NULL; } =20 - status =3D 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 =3D min (ntfn->Name.Length / sizeof (WCHAR), MAX_PATH-1); - memcpy (name, ntfn->Name.Buffer, namelen * sizeof (WCHAR)); - name[namelen] =3D L'\0'; - if (swscanf (name, L"\\Device\\NamedPipe\\%llx-%u-pipe-nt-0x%x", - &pipename_key, &pipename_pid, &pipename_id) !=3D 3) + if (name->Length =3D=3D 0 || name->Buffer =3D=3D 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 */ } =20 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); =20 @@ -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)] =3D L'\0'; - if (wcscmp (name, ntfn->Name.Buffer) =3D=3D 0) + if (RtlEqualUnicodeString (pc.get_nt_native_path (), + &ntfn->Name, FALSE)) { query_hdl_proc =3D proc; query_hdl_value =3D (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 ();