From 039bacb0c9edcba8dab5f3243105b1b1dd2d897e Mon Sep 17 00:00:00 2001 From: Bernhard Loos Date: Mon, 26 Sep 2011 13:57:15 +0200 Subject: [PATCH] server: Store sharing state for named pipes. --- dlls/kernel32/sync.c | 15 ++++++++------- dlls/ntdll/file.c | 1 + include/wine/server_protocol.h | 6 ++++-- server/named_pipe.c | 2 ++ server/protocol.def | 1 + server/request.h | 13 +++++++------ server/trace.c | 1 + 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c index 3f627a461f7..96302585732 100644 --- a/dlls/kernel32/sync.c +++ b/dlls/kernel32/sync.c @@ -1346,7 +1346,7 @@ HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode, HANDLE handle; UNICODE_STRING nt_name; OBJECT_ATTRIBUTES attr; - DWORD access, options; + DWORD access, options, sharing; BOOLEAN pipe_type, read_mode, non_block; NTSTATUS status; IO_STATUS_BLOCK iosb; @@ -1379,15 +1379,15 @@ HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode, switch(dwOpenMode & 3) { case PIPE_ACCESS_INBOUND: - options = FILE_PIPE_INBOUND; + sharing = FILE_SHARE_WRITE; access = GENERIC_READ; break; case PIPE_ACCESS_OUTBOUND: - options = FILE_PIPE_OUTBOUND; + sharing = FILE_SHARE_READ; access = GENERIC_WRITE; break; case PIPE_ACCESS_DUPLEX: - options = FILE_PIPE_FULL_DUPLEX; + sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; access = GENERIC_READ | GENERIC_WRITE; break; default: @@ -1395,6 +1395,7 @@ HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode, return INVALID_HANDLE_VALUE; } access |= SYNCHRONIZE; + options = 0; if (dwOpenMode & FILE_FLAG_WRITE_THROUGH) options |= FILE_WRITE_THROUGH; if (!(dwOpenMode & FILE_FLAG_OVERLAPPED)) options |= FILE_SYNCHRONOUS_IO_NONALERT; pipe_type = (dwPipeMode & PIPE_TYPE_MESSAGE) ? TRUE : FALSE; @@ -1406,7 +1407,7 @@ HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode, SetLastError(0); - status = NtCreateNamedPipeFile(&handle, access, &attr, &iosb, 0, + status = NtCreateNamedPipeFile(&handle, access, &attr, &iosb, sharing, FILE_OVERWRITE_IF, options, pipe_type, read_mode, non_block, nMaxInstances, nInBufferSize, nOutBufferSize, &timeout); @@ -1847,8 +1848,8 @@ BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe, GetCurrentProcessId(), ++index); RtlInitUnicodeString(&nt_name, name); status = NtCreateNamedPipeFile(&hr, GENERIC_READ | SYNCHRONIZE, &attr, &iosb, - 0, FILE_OVERWRITE_IF, - FILE_SYNCHRONOUS_IO_NONALERT | FILE_PIPE_INBOUND, + FILE_SHARE_WRITE, FILE_OVERWRITE_IF, + FILE_SYNCHRONOUS_IO_NONALERT, FALSE, FALSE, FALSE, 1, size, size, &timeout); if (status) diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c index 4d49956c34d..278da5db720 100644 --- a/dlls/ntdll/file.c +++ b/dlls/ntdll/file.c @@ -2781,6 +2781,7 @@ NTSTATUS WINAPI NtCreateNamedPipeFile( PHANDLE handle, ULONG access, req->attributes = attr->Attributes; req->rootdir = wine_server_obj_handle( attr->RootDirectory ); req->options = options; + req->sharing = sharing; req->flags = (pipe_type) ? NAMED_PIPE_MESSAGE_STREAM_WRITE : 0 | (read_mode) ? NAMED_PIPE_MESSAGE_STREAM_READ : 0 | diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index ee438b4e0da..9db7f78f00c 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -3030,13 +3030,15 @@ struct create_named_pipe_request unsigned int attributes; obj_handle_t rootdir; unsigned int options; + unsigned int sharing; unsigned int maxinstances; unsigned int outsize; unsigned int insize; + char __pad_44[4]; timeout_t timeout; unsigned int flags; /* VARARG(name,unicode_str); */ - char __pad_52[4]; + char __pad_60[4]; }; struct create_named_pipe_reply { @@ -5635,6 +5637,6 @@ union generic_reply struct set_suspend_context_reply set_suspend_context_reply; }; -#define SERVER_PROTOCOL_VERSION 425 +#define SERVER_PROTOCOL_VERSION 426 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */ diff --git a/server/named_pipe.c b/server/named_pipe.c index 29d5c5efdf8..9a37acbeb90 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -91,6 +91,7 @@ struct named_pipe { struct object obj; /* object header */ unsigned int flags; + unsigned int sharing; unsigned int maxinstances; unsigned int outsize; unsigned int insize; @@ -960,6 +961,7 @@ DECL_HANDLER(create_named_pipe) pipe->maxinstances = req->maxinstances; pipe->timeout = req->timeout; pipe->flags = req->flags; + pipe->sharing = req->sharing; } else { diff --git a/server/protocol.def b/server/protocol.def index 123f16a4cc1..71524a45fa0 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -2186,6 +2186,7 @@ enum message_type unsigned int attributes; /* object attributes */ obj_handle_t rootdir; /* root directory */ unsigned int options; + unsigned int sharing; unsigned int maxinstances; unsigned int outsize; unsigned int insize; diff --git a/server/request.h b/server/request.h index d2ca2f662b8..2d4528a7d32 100644 --- a/server/request.h +++ b/server/request.h @@ -1477,12 +1477,13 @@ C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, access) == 12 ); C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, attributes) == 16 ); C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, rootdir) == 20 ); C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, options) == 24 ); -C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, maxinstances) == 28 ); -C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, outsize) == 32 ); -C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, insize) == 36 ); -C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, timeout) == 40 ); -C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, flags) == 48 ); -C_ASSERT( sizeof(struct create_named_pipe_request) == 56 ); +C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, sharing) == 28 ); +C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, maxinstances) == 32 ); +C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, outsize) == 36 ); +C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, insize) == 40 ); +C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, timeout) == 48 ); +C_ASSERT( FIELD_OFFSET(struct create_named_pipe_request, flags) == 56 ); +C_ASSERT( sizeof(struct create_named_pipe_request) == 64 ); C_ASSERT( FIELD_OFFSET(struct create_named_pipe_reply, handle) == 8 ); C_ASSERT( sizeof(struct create_named_pipe_reply) == 16 ); C_ASSERT( FIELD_OFFSET(struct get_named_pipe_info_request, handle) == 12 ); diff --git a/server/trace.c b/server/trace.c index 37ea21639a1..670958a7c4b 100644 --- a/server/trace.c +++ b/server/trace.c @@ -2607,6 +2607,7 @@ static void dump_create_named_pipe_request( const struct create_named_pipe_reque fprintf( stderr, ", attributes=%08x", req->attributes ); fprintf( stderr, ", rootdir=%04x", req->rootdir ); fprintf( stderr, ", options=%08x", req->options ); + fprintf( stderr, ", sharing=%08x", req->sharing ); fprintf( stderr, ", maxinstances=%08x", req->maxinstances ); fprintf( stderr, ", outsize=%08x", req->outsize ); fprintf( stderr, ", insize=%08x", req->insize );