This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH draft v2 6/6] Cygwin: add fhandler_base::npfs_handle
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin-patches at cygwin dot com" <cygwin-patches at cygwin dot com>
- Date: Fri, 7 Jun 2019 18:05:31 +0000
- Subject: [PATCH draft v2 6/6] Cygwin: add fhandler_base::npfs_handle
- References: <20190607180511.46369-1-kbrown@cornell.edu>
This gets a handle to the Windows named pipe file system directory.
It replaces the three identical functions of the same name in the
classes fhandler_pipe, fhandler_fifo, and fhandler_socket_unix.
---
winsup/cygwin/fhandler.cc | 30 +++++++++++++++++++++++++
winsup/cygwin/fhandler.h | 7 +++---
winsup/cygwin/fhandler_fifo.cc | 30 -------------------------
winsup/cygwin/fhandler_pipe.cc | 32 +--------------------------
winsup/cygwin/fhandler_socket_unix.cc | 30 -------------------------
5 files changed, 35 insertions(+), 94 deletions(-)
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index bb618fa88..7619db6c7 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1835,3 +1835,33 @@ fhandler_base::fpathconf (int v)
}
return -1;
}
+
+NTSTATUS
+fhandler_base::npfs_handle (HANDLE &nph)
+{
+ static NO_COPY SRWLOCK npfs_lock;
+ static NO_COPY HANDLE npfs_dirh;
+
+ NTSTATUS status = STATUS_SUCCESS;
+ OBJECT_ATTRIBUTES attr;
+ IO_STATUS_BLOCK io;
+
+ /* Lockless after first call. */
+ if (npfs_dirh)
+ {
+ nph = npfs_dirh;
+ return STATUS_SUCCESS;
+ }
+ AcquireSRWLockExclusive (&npfs_lock);
+ if (!npfs_dirh)
+ {
+ InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
+ status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+ &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ 0);
+ }
+ ReleaseSRWLockExclusive (&npfs_lock);
+ if (NT_SUCCESS (status))
+ nph = npfs_dirh;
+ return status;
+}
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 55b49bced..0aedb63c3 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -385,6 +385,10 @@ public:
virtual int dup (fhandler_base *child, int flags);
virtual int fpathconf (int);
+ /* Get a handle to the named pipe file system directory. Used by
+ fhandler_pipe, fhandler_fifo, and fhandler_socket_unix. */
+ static NTSTATUS npfs_handle (HANDLE &);
+
virtual HANDLE mmap (caddr_t *addr, size_t len, int prot,
int flags, off_t off);
virtual int munmap (HANDLE h, caddr_t addr, size_t len);
@@ -1008,7 +1012,6 @@ class fhandler_socket_unix : public fhandler_socket
int send_sock_info (bool from_bind);
int grab_admin_pkg ();
int recv_peer_info ();
- static NTSTATUS npfs_handle (HANDLE &nph);
HANDLE create_pipe (bool single_instance);
HANDLE create_pipe_instance ();
NTSTATUS open_pipe (PUNICODE_STRING pipe_name, bool xchg_sock_info);
@@ -1143,7 +1146,6 @@ public:
int __reg3 fadvise (off_t, off_t, int);
int __reg3 ftruncate (off_t, bool);
int init (HANDLE, DWORD, mode_t, int64_t);
- static NTSTATUS npfs_handle (HANDLE &);
static int create (fhandler_pipe *[2], unsigned, int);
static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD,
const char *, DWORD, int64_t *unique_id = NULL);
@@ -1198,7 +1200,6 @@ class fhandler_fifo: public fhandler_base
bool reader, writer, duplexer;
size_t max_atomic_write;
bool __reg2 wait (HANDLE);
- static NTSTATUS npfs_handle (HANDLE &);
HANDLE create_pipe_instance (bool);
NTSTATUS open_pipe (HANDLE&);
int add_client_handler ();
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index c9ff0a309..6cb35b5b9 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -118,36 +118,6 @@ set_pipe_non_blocking (HANDLE ph, bool nonblocking)
debug_printf ("NtSetInformationFile(FilePipeInformation): %y", status);
}
-NTSTATUS
-fhandler_fifo::npfs_handle (HANDLE &nph)
-{
- static NO_COPY SRWLOCK npfs_lock;
- static NO_COPY HANDLE npfs_dirh;
-
- NTSTATUS status = STATUS_SUCCESS;
- OBJECT_ATTRIBUTES attr;
- IO_STATUS_BLOCK io;
-
- /* Lockless after first call. */
- if (npfs_dirh)
- {
- nph = npfs_dirh;
- return STATUS_SUCCESS;
- }
- AcquireSRWLockExclusive (&npfs_lock);
- if (!npfs_dirh)
- {
- InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
- status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
- &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0);
- }
- ReleaseSRWLockExclusive (&npfs_lock);
- if (NT_SUCCESS (status))
- nph = npfs_dirh;
- return status;
-}
-
/* Called when a FIFO is first opened for reading and again each time
a new client handler is needed. Each pipe instance is created in
blocking mode so that we can easily wait for a connection. After
diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc
index 27fdc8e76..efd9bc6e2 100644
--- a/winsup/cygwin/fhandler_pipe.cc
+++ b/winsup/cygwin/fhandler_pipe.cc
@@ -624,36 +624,6 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode)
return res;
}
-NTSTATUS
-fhandler_pipe::npfs_handle (HANDLE &nph)
-{
- static NO_COPY SRWLOCK npfs_lock;
- static NO_COPY HANDLE npfs_dirh;
-
- NTSTATUS status = STATUS_SUCCESS;
- OBJECT_ATTRIBUTES attr;
- IO_STATUS_BLOCK io;
-
- /* Lockless after first call. */
- if (npfs_dirh)
- {
- nph = npfs_dirh;
- return STATUS_SUCCESS;
- }
- AcquireSRWLockExclusive (&npfs_lock);
- if (!npfs_dirh)
- {
- InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
- status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
- &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0);
- }
- ReleaseSRWLockExclusive (&npfs_lock);
- if (NT_SUCCESS (status))
- nph = npfs_dirh;
- return status;
-}
-
static int
nt_create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w,
DWORD psize, int64_t *unique_id)
@@ -671,7 +641,7 @@ nt_create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w,
if (w)
*w = NULL;
- status = fhandler_pipe::npfs_handle (npfsh);
+ status = fhandler_base::npfs_handle (npfsh);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc
index eea7e76b3..23d3f403f 100644
--- a/winsup/cygwin/fhandler_socket_unix.cc
+++ b/winsup/cygwin/fhandler_socket_unix.cc
@@ -804,36 +804,6 @@ fhandler_socket_unix::recv_peer_info ()
return ret;
}
-NTSTATUS
-fhandler_socket_unix::npfs_handle (HANDLE &nph)
-{
- static NO_COPY SRWLOCK npfs_lock;
- static NO_COPY HANDLE npfs_dirh;
-
- NTSTATUS status = STATUS_SUCCESS;
- OBJECT_ATTRIBUTES attr;
- IO_STATUS_BLOCK io;
-
- /* Lockless after first call. */
- if (npfs_dirh)
- {
- nph = npfs_dirh;
- return STATUS_SUCCESS;
- }
- AcquireSRWLockExclusive (&npfs_lock);
- if (!npfs_dirh)
- {
- InitializeObjectAttributes (&attr, &ro_u_npfs, 0, NULL, NULL);
- status = NtOpenFile (&npfs_dirh, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
- &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0);
- }
- ReleaseSRWLockExclusive (&npfs_lock);
- if (NT_SUCCESS (status))
- nph = npfs_dirh;
- return status;
-}
-
HANDLE
fhandler_socket_unix::create_pipe (bool single_instance)
{
--
2.21.0