From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 06C0D385802D; Tue, 14 Sep 2021 15:05:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06C0D385802D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: add fhandler_base::npfs_handle X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: f002d02b17d92f8057786c51077d1c746cd99d0f X-Git-Newrev: 8a10f6302cad62cf8adc5c736e3eab8da4aa689b Message-Id: <20210914150504.06C0D385802D@sourceware.org> Date: Tue, 14 Sep 2021 15:05:04 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Sep 2021 15:05:04 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=8a10f6302cad62cf8adc5c736e3eab8da4aa689b commit 8a10f6302cad62cf8adc5c736e3eab8da4aa689b Author: Ken Brown Date: Thu Aug 26 18:05:53 2021 -0400 Cygwin: add fhandler_base::npfs_handle It replaces the three identical functions of the same name in the classes fhandler_pipe, fhandler_fifo, and fhandler_socket_unix. Diff: --- 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 035e3d7bd..f0c1b68f1 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -1833,3 +1833,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 9a7c38f8f..132e60021 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -413,6 +413,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); @@ -1057,7 +1061,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); @@ -1194,7 +1197,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); @@ -1346,7 +1348,6 @@ class fhandler_fifo: public fhandler_base fifo_client_handler *shared_fc_handler; bool __reg2 wait (HANDLE); - static NTSTATUS npfs_handle (HANDLE &); HANDLE create_pipe_instance (); NTSTATUS open_pipe (HANDLE&); NTSTATUS wait_open_pipe (HANDLE&); diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index 365f14053..b55ba95e7 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -195,36 +195,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 4819fc580..2dec0a848 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 a2428e952..8abb581b9 100644 --- a/winsup/cygwin/fhandler_socket_unix.cc +++ b/winsup/cygwin/fhandler_socket_unix.cc @@ -805,36 +805,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) {