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>
This commit is contained in:
parent
46bb999a89
commit
c2310061c6
|
@ -93,6 +93,21 @@ fhandler_pipe::init (HANDLE f, DWORD a, mode_t mode, int64_t uniq_id)
|
||||||
even with FILE_SYNCHRONOUS_IO_NONALERT. */
|
even with FILE_SYNCHRONOUS_IO_NONALERT. */
|
||||||
set_pipe_non_blocking (get_device () == FH_PIPER ?
|
set_pipe_non_blocking (get_device () == FH_PIPER ?
|
||||||
true : is_nonblocking ());
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1149,6 +1164,8 @@ fhandler_pipe::temporary_query_hdl ()
|
||||||
tmp_pathbuf tp;
|
tmp_pathbuf tp;
|
||||||
OBJECT_NAME_INFORMATION *ntfn = (OBJECT_NAME_INFORMATION *) tp.w_get ();
|
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
|
/* Try process handle opened and pipe handle value cached first
|
||||||
in order to reduce overhead. */
|
in order to reduce overhead. */
|
||||||
if (query_hdl_proc && query_hdl_value)
|
if (query_hdl_proc && query_hdl_value)
|
||||||
|
@ -1161,14 +1178,7 @@ fhandler_pipe::temporary_query_hdl ()
|
||||||
status = NtQueryObject (h, ObjectNameInformation, ntfn, 65536, &len);
|
status = NtQueryObject (h, ObjectNameInformation, ntfn, 65536, &len);
|
||||||
if (!NT_SUCCESS (status) || !ntfn->Name.Buffer)
|
if (!NT_SUCCESS (status) || !ntfn->Name.Buffer)
|
||||||
goto hdl_err;
|
goto hdl_err;
|
||||||
ntfn->Name.Buffer[ntfn->Name.Length / sizeof (WCHAR)] = L'\0';
|
if (RtlEqualUnicodeString (name, &ntfn->Name, FALSE))
|
||||||
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)
|
|
||||||
return h;
|
return h;
|
||||||
hdl_err:
|
hdl_err:
|
||||||
CloseHandle (h);
|
CloseHandle (h);
|
||||||
|
@ -1178,24 +1188,13 @@ cache_err:
|
||||||
query_hdl_value = NULL;
|
query_hdl_value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = NtQueryObject (get_handle (), ObjectNameInformation, ntfn,
|
if (name->Length == 0 || name->Buffer == NULL)
|
||||||
65536, &len);
|
|
||||||
if (!NT_SUCCESS (status) || !ntfn->Name.Buffer)
|
|
||||||
return NULL; /* Non cygwin pipe? */
|
return NULL; /* Non cygwin pipe? */
|
||||||
WCHAR name[MAX_PATH];
|
return get_query_hdl_per_process (ntfn); /* Since Win8 */
|
||||||
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)
|
|
||||||
return NULL; /* Non cygwin pipe? */
|
|
||||||
|
|
||||||
return get_query_hdl_per_process (name, ntfn); /* Since Win8 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE
|
HANDLE
|
||||||
fhandler_pipe::get_query_hdl_per_process (WCHAR *name,
|
fhandler_pipe::get_query_hdl_per_process (OBJECT_NAME_INFORMATION *ntfn)
|
||||||
OBJECT_NAME_INFORMATION *ntfn)
|
|
||||||
{
|
{
|
||||||
winpids pids ((DWORD) 0);
|
winpids pids ((DWORD) 0);
|
||||||
|
|
||||||
|
@ -1272,8 +1271,8 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name,
|
||||||
ntfn, 65536, &len);
|
ntfn, 65536, &len);
|
||||||
if (!NT_SUCCESS (status) || !ntfn->Name.Buffer)
|
if (!NT_SUCCESS (status) || !ntfn->Name.Buffer)
|
||||||
goto close_handle;
|
goto close_handle;
|
||||||
ntfn->Name.Buffer[ntfn->Name.Length / sizeof (WCHAR)] = L'\0';
|
if (RtlEqualUnicodeString (pc.get_nt_native_path (),
|
||||||
if (wcscmp (name, ntfn->Name.Buffer) == 0)
|
&ntfn->Name, FALSE))
|
||||||
{
|
{
|
||||||
query_hdl_proc = proc;
|
query_hdl_proc = proc;
|
||||||
query_hdl_value = (HANDLE)(intptr_t) phi->Handles[j].HandleValue;
|
query_hdl_value = (HANDLE)(intptr_t) phi->Handles[j].HandleValue;
|
||||||
|
|
|
@ -1216,11 +1216,8 @@ private:
|
||||||
HANDLE query_hdl_proc;
|
HANDLE query_hdl_proc;
|
||||||
HANDLE query_hdl_value;
|
HANDLE query_hdl_value;
|
||||||
HANDLE query_hdl_close_req_evt;
|
HANDLE query_hdl_close_req_evt;
|
||||||
uint64_t pipename_key;
|
|
||||||
DWORD pipename_pid;
|
|
||||||
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 (OBJECT_NAME_INFORMATION *);
|
||||||
public:
|
public:
|
||||||
fhandler_pipe ();
|
fhandler_pipe ();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue