Rebase against 5b4f8a385b46a8a8a8b09b8ca6578aa7b7995a1e.

This commit is contained in:
Sebastian Lackner
2017-04-02 05:09:40 +02:00
parent 4232441093
commit 55ab42ece0
12 changed files with 194 additions and 270 deletions

View File

@@ -1,4 +1,4 @@
From a6015c0c962802b44e1bf918e454745f1cc377b8 Mon Sep 17 00:00:00 2001
From 104443cbb9a1087ec753af2462ccf41ba26eb444 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Mon, 4 Aug 2014 05:01:11 +0200
Subject: server: Use SOCK_SEQPACKET socket in combination with SO_PEEK_OFF to
@@ -27,16 +27,16 @@ Changes in v6:
* When running on an older kernel make sure that ntdll doesn't try to use message mode features.
---
dlls/kernel32/sync.c | 2 +-
dlls/kernel32/tests/pipe.c | 17 ++-----
dlls/ntdll/file.c | 106 ++++++++++++++++++++++++++++++++++------
server/named_pipe.c | 117 ++++++++++++++++++++++++++++++++++++---------
dlls/kernel32/tests/pipe.c | 17 ++------
dlls/ntdll/file.c | 106 ++++++++++++++++++++++++++++++++++++++-------
server/named_pipe.c | 103 ++++++++++++++++++++++++++++++++++++-------
server/sock.c | 4 +-
server/sock.h | 26 ++++++++++
6 files changed, 219 insertions(+), 53 deletions(-)
server/sock.h | 26 +++++++++++
6 files changed, 212 insertions(+), 46 deletions(-)
create mode 100644 server/sock.h
diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c
index 494db9c1a31..38aaccfa55c 100644
index 494db9c1a3..38aaccfa55 100644
--- a/dlls/kernel32/sync.c
+++ b/dlls/kernel32/sync.c
@@ -1475,7 +1475,7 @@ BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
@@ -49,7 +49,7 @@ index 494db9c1a31..38aaccfa55c 100644
}
else SetLastError( RtlNtStatusToDosError(status) );
diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c
index e7cfce4c00e..71d75be90e8 100644
index e7cfce4c00..71d75be90e 100644
--- a/dlls/kernel32/tests/pipe.c
+++ b/dlls/kernel32/tests/pipe.c
@@ -294,7 +294,6 @@ static void test_CreateNamedPipe(int pipemode)
@@ -149,7 +149,7 @@ index e7cfce4c00e..71d75be90e8 100644
ret = RpcReadFile(hnp, ibuf + 8, sizeof(ibuf), &readden, NULL);
ok(ret, "RpcReadFile 10\n");
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index af582ecfdb0..42b81fb3fbb 100644
index 41d44c9af4..1b0eff02f2 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -96,6 +96,10 @@
@@ -329,7 +329,7 @@ index af582ecfdb0..42b81fb3fbb 100644
if (needs_close) close( fd );
}
diff --git a/server/named_pipe.c b/server/named_pipe.c
index c75a7379283..6c6a8b40bd1 100644
index b215816650..74a9a44dcf 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -42,6 +42,10 @@
@@ -351,7 +351,7 @@ index c75a7379283..6c6a8b40bd1 100644
#include "handle.h"
#include "thread.h"
#include "request.h"
@@ -761,14 +766,43 @@ static int named_pipe_link_name( struct object *obj, struct object_name *name, s
@@ -804,14 +809,43 @@ static int named_pipe_link_name( struct object *obj, struct object_name *name, s
return 1;
}
@@ -396,19 +396,26 @@ index c75a7379283..6c6a8b40bd1 100644
if (!(server = find_available_server( pipe )))
{
@@ -787,7 +821,10 @@ static struct object *named_pipe_open_file( struct object *obj, unsigned int acc
@@ -830,6 +864,9 @@ static struct object *named_pipe_open_file( struct object *obj, unsigned int acc
if ((client = create_pipe_client( options, pipe->flags )))
if ((client = create_pipe_client( options, pipe->flags, pipe->outsize )))
{
- if (!socketpair( PF_UNIX, SOCK_STREAM, 0, fds ))
+ type = ((pipe->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) && is_messagemode_supported()) ?
+ SOCK_SEQPACKET : SOCK_STREAM;
+
+ if (!socketpair( PF_UNIX, type, 0, fds ))
if (use_server_io( &server->pipe_end ))
{
client->pipe_end.fd = alloc_pseudo_fd( &pipe_client_fd_ops, &client->pipe_end.obj, options );
@@ -845,7 +882,7 @@ static struct object *named_pipe_open_file( struct object *obj, unsigned int acc
client = NULL;
}
}
- else if (!socketpair( PF_UNIX, SOCK_STREAM, 0, fds ))
+ else if (!socketpair( PF_UNIX, type, 0, fds ))
{
assert( !server->pipe_end.fd );
@@ -797,32 +834,55 @@ static struct object *named_pipe_open_file( struct object *obj, unsigned int acc
@@ -855,25 +892,48 @@ static struct object *named_pipe_open_file( struct object *obj, unsigned int acc
if (is_overlapped( options )) fcntl( fds[1], F_SETFL, O_NONBLOCK );
if (is_overlapped( server->options )) fcntl( fds[0], F_SETFL, O_NONBLOCK );
@@ -445,14 +452,7 @@ index c75a7379283..6c6a8b40bd1 100644
+ if (type != SOCK_SEQPACKET || (setsockopt( fds[0], SOL_SOCKET, SO_PEEK_OFF, &zero, sizeof(zero) ) != -1 &&
+ setsockopt( fds[1], SOL_SOCKET, SO_PEEK_OFF, &zero, sizeof(zero) ) != -1))
{
- allow_fd_caching( client->pipe_end.fd );
- allow_fd_caching( server->pipe_end.fd );
- fd_copy_completion( server->ioctl_fd, server->pipe_end.fd );
- if (server->state == ps_wait_open)
- fd_async_wake_up( server->ioctl_fd, ASYNC_TYPE_WAIT, STATUS_SUCCESS );
- set_server_state( server, ps_connected_server );
- server->client = client;
- client->server = server;
+ #ifdef __linux__
+ fcntl( fds[0], F_SETSIG, messagemode_flags( server->pipe_end.flags ) );
+ fcntl( fds[1], F_SETSIG, messagemode_flags( client->pipe_end.flags ) );
@@ -462,14 +462,7 @@ index c75a7379283..6c6a8b40bd1 100644
+ server->pipe_end.fd = create_anonymous_fd( &pipe_server_fd_ops, fds[0], &server->pipe_end.obj, server->options );
+ if (client->pipe_end.fd && server->pipe_end.fd)
+ {
+ allow_fd_caching( client->pipe_end.fd );
+ allow_fd_caching( server->pipe_end.fd );
+ fd_copy_completion( server->ioctl_fd, server->pipe_end.fd );
+ if (server->state == ps_wait_open)
+ fd_async_wake_up( server->ioctl_fd, ASYNC_TYPE_WAIT, STATUS_SUCCESS );
+ set_server_state( server, ps_connected_server );
+ server->client = client;
+ client->server = server;
+ }
+ else
+ {
@@ -483,7 +476,7 @@ index c75a7379283..6c6a8b40bd1 100644
release_object( client );
client = NULL;
}
@@ -907,7 +967,7 @@ DECL_HANDLER(create_named_pipe)
@@ -970,7 +1030,7 @@ DECL_HANDLER(create_named_pipe)
return;
}
@@ -492,7 +485,7 @@ index c75a7379283..6c6a8b40bd1 100644
if (!name.len) /* pipes need a root directory even without a name */
{
@@ -1010,6 +1070,9 @@ DECL_HANDLER(set_named_pipe_info)
@@ -1073,6 +1133,9 @@ DECL_HANDLER(set_named_pipe_info)
{
struct pipe_server *server;
struct pipe_client *client = NULL;
@@ -502,7 +495,7 @@ index c75a7379283..6c6a8b40bd1 100644
server = get_pipe_server_obj( current->process, req->handle, FILE_WRITE_ATTRIBUTES );
if (!server)
@@ -1036,10 +1099,20 @@ DECL_HANDLER(set_named_pipe_info)
@@ -1099,10 +1162,20 @@ DECL_HANDLER(set_named_pipe_info)
else if (client)
{
client->pipe_end.flags = server->pipe->flags | req->flags;
@@ -524,7 +517,7 @@ index c75a7379283..6c6a8b40bd1 100644
if (client)
diff --git a/server/sock.c b/server/sock.c
index d6b4fb2fa5c..49b6d3d5758 100644
index d6b4fb2fa5..49b6d3d575 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -61,6 +61,7 @@
@@ -554,7 +547,7 @@ index d6b4fb2fa5c..49b6d3d5758 100644
}
diff --git a/server/sock.h b/server/sock.h
new file mode 100644
index 00000000000..21551b42b1c
index 0000000000..21551b42b1
--- /dev/null
+++ b/server/sock.h
@@ -0,0 +1,26 @@

View File

@@ -1,4 +1,4 @@
From 260d35bbb99549c5ebf8447f6f1bf0680f6e3943 Mon Sep 17 00:00:00 2001
From 3f96971d0d54e5d32a57970c36cb55e3ad6ff7c8 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sat, 6 Jun 2015 01:21:05 +0200
Subject: server: Return correct error codes for NtWriteFile when pipes are
@@ -12,7 +12,7 @@ Subject: server: Return correct error codes for NtWriteFile when pipes are
4 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c
index ba365ed666e..23f1a5f5f55 100644
index ba365ed666..23f1a5f5f5 100644
--- a/dlls/kernel32/tests/pipe.c
+++ b/dlls/kernel32/tests/pipe.c
@@ -1917,7 +1917,7 @@ static void test_CloseHandle(void)
@@ -25,7 +25,7 @@ index ba365ed666e..23f1a5f5f55 100644
CloseHandle(hfile);
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index ab34d99d5b6..d0662d9ae59 100644
index 899ebddabb..91316bd2c4 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -1235,6 +1235,9 @@ static NTSTATUS write_unix_fd(int fd, const char *buf, ULONG *total, ULONG lengt
@@ -39,10 +39,19 @@ index ab34d99d5b6..d0662d9ae59 100644
}
}
diff --git a/server/named_pipe.c b/server/named_pipe.c
index 6c6a8b40bd1..47a88790fa3 100644
index 74a9a44dcf..9a8d8b37ca 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -150,6 +150,7 @@ static const struct object_ops named_pipe_ops =
@@ -119,6 +119,8 @@ struct named_pipe_device
struct namespace *pipes; /* named pipe namespace */
};
+static inline int messagemode_flags( int flags );
+
static void named_pipe_dump( struct object *obj, int verbose );
static unsigned int named_pipe_map_access( struct object *obj, unsigned int access );
static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent );
@@ -155,6 +157,7 @@ static void pipe_end_queue_async( struct fd *fd, struct async *async, int type,
/* server end functions */
static void pipe_server_dump( struct object *obj, int verbose );
static struct fd *pipe_server_get_fd( struct object *obj );
@@ -50,7 +59,7 @@ index 6c6a8b40bd1..47a88790fa3 100644
static void pipe_server_destroy( struct object *obj);
static obj_handle_t pipe_server_flush( struct fd *fd, struct async *async, int blocking );
static enum server_fd_type pipe_server_get_fd_type( struct fd *fd );
@@ -175,7 +176,7 @@ static const struct object_ops pipe_server_ops =
@@ -180,7 +183,7 @@ static const struct object_ops pipe_server_ops =
NULL, /* unlink_name */
no_open_file, /* open_file */
no_alloc_handle, /* alloc_handle */
@@ -59,7 +68,7 @@ index 6c6a8b40bd1..47a88790fa3 100644
pipe_server_destroy /* destroy */
};
@@ -196,6 +197,7 @@ static const struct fd_ops pipe_server_fd_ops =
@@ -201,6 +204,7 @@ static const struct fd_ops pipe_server_fd_ops =
static void pipe_client_dump( struct object *obj, int verbose );
static int pipe_client_signaled( struct object *obj, struct wait_queue_entry *entry );
static struct fd *pipe_client_get_fd( struct object *obj );
@@ -67,7 +76,7 @@ index 6c6a8b40bd1..47a88790fa3 100644
static void pipe_client_destroy( struct object *obj );
static obj_handle_t pipe_client_flush( struct fd *fd, struct async *async, int blocking );
static enum server_fd_type pipe_client_get_fd_type( struct fd *fd );
@@ -219,7 +221,7 @@ static const struct object_ops pipe_client_ops =
@@ -224,7 +228,7 @@ static const struct object_ops pipe_client_ops =
NULL, /* unlink_name */
no_open_file, /* open_file */
no_alloc_handle, /* alloc_handle */
@@ -76,16 +85,7 @@ index 6c6a8b40bd1..47a88790fa3 100644
pipe_client_destroy /* destroy */
};
@@ -284,6 +286,8 @@ static const struct fd_ops named_pipe_device_fd_ops =
default_fd_reselect_async /* reselect_async */
};
+static inline int messagemode_flags( int flags );
+
static void named_pipe_dump( struct object *obj, int verbose )
{
fputs( "Named pipe\n", stderr );
@@ -393,6 +397,23 @@ static void do_disconnect( struct pipe_server *server )
@@ -418,6 +422,23 @@ static void do_disconnect( struct pipe_server *server )
server->pipe_end.fd = NULL;
}
@@ -109,7 +109,7 @@ index 6c6a8b40bd1..47a88790fa3 100644
static void pipe_server_destroy( struct object *obj)
{
struct pipe_server *server = (struct pipe_server *)obj;
@@ -419,6 +440,24 @@ static void pipe_server_destroy( struct object *obj)
@@ -446,6 +467,24 @@ static void pipe_server_destroy( struct object *obj)
release_object( server->pipe );
}
@@ -135,7 +135,7 @@ index 6c6a8b40bd1..47a88790fa3 100644
{
struct pipe_client *client = (struct pipe_client *)obj;
diff --git a/server/protocol.def b/server/protocol.def
index e7a55d7a2d8..f1e7af1d568 100644
index e7a55d7a2d..f1e7af1d56 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -2427,6 +2427,7 @@ enum message_type

View File

@@ -1,92 +1,39 @@
From 7fce25b8259f816e1cc8c2c40b6a73379f2fb4ef Mon Sep 17 00:00:00 2001
From a5a9edf432ca2aecef11db6bde388730cc9eadf8 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 24 Feb 2016 15:45:09 +0100
Subject: server: Do not allow to queue async operation for broken pipes.
---
server/named_pipe.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
server/named_pipe.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/server/named_pipe.c b/server/named_pipe.c
index 47a88790fa3..e5c5c4968c4 100644
index 9a8d8b37ca..df9f5c4926 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -156,6 +156,7 @@ static obj_handle_t pipe_server_flush( struct fd *fd, struct async *async, int b
static enum server_fd_type pipe_server_get_fd_type( struct fd *fd );
static obj_handle_t pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async,
int blocking );
+static void pipe_server_queue_async( struct fd *fd, struct async *async, int type, int count );
static const struct object_ops pipe_server_ops =
@@ -665,8 +665,20 @@ static obj_handle_t pipe_client_flush( struct fd *fd, struct async *async, int b
static void pipe_end_queue_async( struct fd *fd, struct async *async, int type, int count )
{
@@ -189,7 +190,7 @@ static const struct fd_ops pipe_server_fd_ops =
no_fd_write, /* write */
pipe_server_flush, /* flush */
pipe_server_ioctl, /* ioctl */
- default_fd_queue_async, /* queue_async */
+ pipe_server_queue_async, /* queue_async */
default_fd_reselect_async /* reselect_async */
};
@@ -201,6 +202,7 @@ static int pipe_client_close_handle( struct object *obj, struct process *process
static void pipe_client_destroy( struct object *obj );
static obj_handle_t pipe_client_flush( struct fd *fd, struct async *async, int blocking );
static enum server_fd_type pipe_client_get_fd_type( struct fd *fd );
+static void pipe_client_queue_async( struct fd *fd, struct async *async, int type, int count );
static const struct object_ops pipe_client_ops =
{
@@ -234,7 +236,7 @@ static const struct fd_ops pipe_client_fd_ops =
no_fd_write, /* write */
pipe_client_flush, /* flush */
default_fd_ioctl, /* ioctl */
- default_fd_queue_async, /* queue_async */
+ pipe_client_queue_async, /* queue_async */
default_fd_reselect_async /* reselect_async */
};
@@ -630,6 +632,20 @@ static obj_handle_t pipe_client_flush( struct fd *fd, struct async *async, int b
return 0;
}
+static void pipe_client_queue_async( struct fd *fd, struct async *async, int type, int count )
+{
+ struct pipe_client *client = get_fd_user( fd );
+ struct pipe_server *server = client->server;
struct pipe_end *pipe_end = get_fd_user( fd );
- if (use_server_io( pipe_end )) no_fd_queue_async( fd, async, type, count );
- else default_fd_queue_async( fd, async, type, count );
+
+ if (!server || !server->pipe_end.fd)
+ if (use_server_io( pipe_end ))
+ {
+ no_fd_queue_async( fd, async, type, count );
+ return;
+ }
+
+ if (!pipe_end->connection)
+ {
+ set_error( STATUS_PIPE_BROKEN );
+ return;
+ }
+
+ default_fd_queue_async( fd, async, type, count );
+}
+
}
static inline int is_overlapped( unsigned int options )
{
return !(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT));
@@ -714,6 +730,20 @@ static obj_handle_t pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct
}
}
+static void pipe_server_queue_async( struct fd *fd, struct async *async, int type, int count )
+{
+ struct pipe_server *server = get_fd_user( fd );
+ struct pipe_client *client = server->client;
+
+ if (!client || !client->pipe_end.fd)
+ {
+ set_error( STATUS_PIPE_BROKEN );
+ return;
+ }
+
+ default_fd_queue_async( fd, async, type, count );
+}
+
static struct pipe_server *get_pipe_server_obj( struct process *process,
obj_handle_t handle, unsigned int access )
{
--
2.11.0