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.
This commit is contained in:
parent
f002d02b17
commit
8a10f6302c
|
@ -1833,3 +1833,33 @@ fhandler_base::fpathconf (int v)
|
||||||
}
|
}
|
||||||
return -1;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -413,6 +413,10 @@ public:
|
||||||
virtual int dup (fhandler_base *child, int flags);
|
virtual int dup (fhandler_base *child, int flags);
|
||||||
virtual int fpathconf (int);
|
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,
|
virtual HANDLE mmap (caddr_t *addr, size_t len, int prot,
|
||||||
int flags, off_t off);
|
int flags, off_t off);
|
||||||
virtual int munmap (HANDLE h, caddr_t addr, size_t len);
|
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 send_sock_info (bool from_bind);
|
||||||
int grab_admin_pkg ();
|
int grab_admin_pkg ();
|
||||||
int recv_peer_info ();
|
int recv_peer_info ();
|
||||||
static NTSTATUS npfs_handle (HANDLE &nph);
|
|
||||||
HANDLE create_pipe (bool single_instance);
|
HANDLE create_pipe (bool single_instance);
|
||||||
HANDLE create_pipe_instance ();
|
HANDLE create_pipe_instance ();
|
||||||
NTSTATUS open_pipe (PUNICODE_STRING pipe_name, bool xchg_sock_info);
|
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 fadvise (off_t, off_t, int);
|
||||||
int __reg3 ftruncate (off_t, bool);
|
int __reg3 ftruncate (off_t, bool);
|
||||||
int init (HANDLE, DWORD, mode_t, int64_t);
|
int init (HANDLE, DWORD, mode_t, int64_t);
|
||||||
static NTSTATUS npfs_handle (HANDLE &);
|
|
||||||
static int create (fhandler_pipe *[2], unsigned, int);
|
static int create (fhandler_pipe *[2], unsigned, int);
|
||||||
static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD,
|
static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD,
|
||||||
const char *, DWORD, int64_t *unique_id = NULL);
|
const char *, DWORD, int64_t *unique_id = NULL);
|
||||||
|
@ -1346,7 +1348,6 @@ class fhandler_fifo: public fhandler_base
|
||||||
fifo_client_handler *shared_fc_handler;
|
fifo_client_handler *shared_fc_handler;
|
||||||
|
|
||||||
bool __reg2 wait (HANDLE);
|
bool __reg2 wait (HANDLE);
|
||||||
static NTSTATUS npfs_handle (HANDLE &);
|
|
||||||
HANDLE create_pipe_instance ();
|
HANDLE create_pipe_instance ();
|
||||||
NTSTATUS open_pipe (HANDLE&);
|
NTSTATUS open_pipe (HANDLE&);
|
||||||
NTSTATUS wait_open_pipe (HANDLE&);
|
NTSTATUS wait_open_pipe (HANDLE&);
|
||||||
|
|
|
@ -195,36 +195,6 @@ set_pipe_non_blocking (HANDLE ph, bool nonblocking)
|
||||||
debug_printf ("NtSetInformationFile(FilePipeInformation): %y", status);
|
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
|
/* 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
|
a new client handler is needed. Each pipe instance is created in
|
||||||
blocking mode so that we can easily wait for a connection. After
|
blocking mode so that we can easily wait for a connection. After
|
||||||
|
|
|
@ -624,36 +624,6 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode)
|
||||||
return res;
|
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
|
static int
|
||||||
nt_create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w,
|
nt_create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w,
|
||||||
DWORD psize, int64_t *unique_id)
|
DWORD psize, int64_t *unique_id)
|
||||||
|
@ -671,7 +641,7 @@ nt_create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w,
|
||||||
if (w)
|
if (w)
|
||||||
*w = NULL;
|
*w = NULL;
|
||||||
|
|
||||||
status = fhandler_pipe::npfs_handle (npfsh);
|
status = fhandler_base::npfs_handle (npfsh);
|
||||||
if (!NT_SUCCESS (status))
|
if (!NT_SUCCESS (status))
|
||||||
{
|
{
|
||||||
__seterrno_from_nt_status (status);
|
__seterrno_from_nt_status (status);
|
||||||
|
|
|
@ -805,36 +805,6 @@ fhandler_socket_unix::recv_peer_info ()
|
||||||
return ret;
|
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
|
HANDLE
|
||||||
fhandler_socket_unix::create_pipe (bool single_instance)
|
fhandler_socket_unix::create_pipe (bool single_instance)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue