diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index 004095b02f5e67f77c5e71d4ac042615a4cc39e9..8ece976c3ce283d6c8f712701c2b23b0049979ed 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -1008,9 +1008,28 @@ NTSTATUS WINAPI NtDelayExecution( BOOLEAN alertable, const LARGE_INTEGER *timeou NTSTATUS WINAPI NtCreateIoCompletion( PHANDLE CompletionPort, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, ULONG NumberOfConcurrentThreads ) { - FIXME("(%p, %x, %p, %d)\n", CompletionPort, DesiredAccess, + NTSTATUS status; + + TRACE("(%p, %x, %p, %d)\n", CompletionPort, DesiredAccess, ObjectAttributes, NumberOfConcurrentThreads); - return STATUS_NOT_IMPLEMENTED; + + if (!CompletionPort) + return STATUS_INVALID_PARAMETER; + + SERVER_START_REQ( create_completion ) + { + req->access = DesiredAccess; + req->attributes = ObjectAttributes ? ObjectAttributes->Attributes : 0; + req->rootdir = ObjectAttributes ? ObjectAttributes->RootDirectory : NULL; + req->concurrent = NumberOfConcurrentThreads; + if (ObjectAttributes && ObjectAttributes->ObjectName) + wine_server_add_data( req, ObjectAttributes->ObjectName->Buffer, + ObjectAttributes->ObjectName->Length ); + if (!(status = wine_server_call( req ))) + *CompletionPort = reply->handle; + } + SERVER_END_REQ; + return status; } /****************************************************************** @@ -1028,11 +1047,24 @@ NTSTATUS WINAPI NtCreateIoCompletion( PHANDLE CompletionPort, ACCESS_MASK Desire */ NTSTATUS WINAPI NtSetIoCompletion( HANDLE CompletionPort, ULONG_PTR CompletionKey, ULONG_PTR CompletionValue, NTSTATUS Status, - ULONG NumberOfBytesToTransfer ) + ULONG NumberOfBytesTransferred ) { - FIXME("(%p, %lx, %lx, %x, %d)\n", CompletionPort, CompletionKey, - CompletionValue, Status, NumberOfBytesToTransfer); - return STATUS_NOT_IMPLEMENTED; + NTSTATUS status; + + TRACE("(%p, %lx, %lx, %x, %d)\n", CompletionPort, CompletionKey, + CompletionValue, Status, NumberOfBytesTransferred); + + SERVER_START_REQ( add_completion ) + { + req->handle = CompletionPort; + req->ckey = CompletionKey; + req->cvalue = CompletionValue; + req->status = Status; + req->information = NumberOfBytesTransferred; + status = wine_server_call( req ); + } + SERVER_END_REQ; + return status; } /****************************************************************** @@ -1053,9 +1085,31 @@ NTSTATUS WINAPI NtRemoveIoCompletion( HANDLE CompletionPort, PULONG_PTR Completi PULONG_PTR CompletionValue, PIO_STATUS_BLOCK iosb, PLARGE_INTEGER WaitTime ) { - FIXME("(%p, %p, %p, %p, %p)\n", CompletionPort, CompletionKey, + NTSTATUS status; + + TRACE("(%p, %p, %p, %p, %p)\n", CompletionPort, CompletionKey, CompletionValue, iosb, WaitTime); - return STATUS_NOT_IMPLEMENTED; + + for(;;) + { + SERVER_START_REQ( remove_completion ) + { + req->handle = CompletionPort; + if (!(status = wine_server_call( req ))) + { + *CompletionKey = reply->ckey; + *CompletionValue = reply->cvalue; + iosb->Information = reply->information; + iosb->u.Status = reply->status; + } + } + SERVER_END_REQ; + if (status != STATUS_PENDING) break; + + status = NtWaitForSingleObject( CompletionPort, FALSE, WaitTime ); + if (status != WAIT_OBJECT_0) break; + } + return status; } /****************************************************************** @@ -1073,8 +1127,24 @@ NTSTATUS WINAPI NtRemoveIoCompletion( HANDLE CompletionPort, PULONG_PTR Completi NTSTATUS WINAPI NtOpenIoCompletion( PHANDLE CompletionPort, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes ) { - FIXME("(%p, 0x%x, %p)\n", CompletionPort, DesiredAccess, ObjectAttributes); - return STATUS_NOT_IMPLEMENTED; + NTSTATUS status; + + TRACE("(%p, 0x%x, %p)\n", CompletionPort, DesiredAccess, ObjectAttributes); + + if (!CompletionPort || !ObjectAttributes || !ObjectAttributes->ObjectName) + return STATUS_INVALID_PARAMETER; + + SERVER_START_REQ( open_completion ) + { + req->access = DesiredAccess; + req->rootdir = ObjectAttributes->RootDirectory; + wine_server_add_data( req, ObjectAttributes->ObjectName->Buffer, + ObjectAttributes->ObjectName->Length ); + if (!(status = wine_server_call( req ))) + *CompletionPort = reply->handle; + } + SERVER_END_REQ; + return status; } /****************************************************************** @@ -1094,7 +1164,36 @@ NTSTATUS WINAPI NtOpenIoCompletion( PHANDLE CompletionPort, ACCESS_MASK DesiredA NTSTATUS WINAPI NtQueryIoCompletion( HANDLE CompletionPort, IO_COMPLETION_INFORMATION_CLASS InformationClass, PVOID CompletionInformation, ULONG BufferLength, PULONG RequiredLength ) { - FIXME("(%p, %d, %p, 0x%x, %p)\n", CompletionPort, InformationClass, CompletionInformation, - BufferLength, RequiredLength); - return STATUS_NOT_IMPLEMENTED; + NTSTATUS status; + + TRACE("(%p, %d, %p, 0x%x, %p)\n", CompletionPort, InformationClass, CompletionInformation, + BufferLength, RequiredLength); + + if (!CompletionInformation) return STATUS_INVALID_PARAMETER; + switch( InformationClass ) + { + case IoCompletionBasicInformation: + { + ULONG *info = (ULONG *)CompletionInformation; + + if (RequiredLength) *RequiredLength = sizeof(*info); + if (BufferLength != sizeof(*info)) + status = STATUS_INFO_LENGTH_MISMATCH; + else + { + SERVER_START_REQ( query_completion ) + { + req->handle = CompletionPort; + if (!(status = wine_server_call( req ))) + *info = reply->depth; + } + SERVER_END_REQ; + } + } + break; + default: + status = STATUS_INVALID_PARAMETER; + break; + } + return status; } diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index b79fda48dd648908c3da56bfcac117e3a32f5fc4..e37f25c8e6194f8b6bd98a92fa98656167c087de 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -4078,6 +4078,84 @@ struct get_token_statistics_reply }; + +struct create_completion_request +{ + struct request_header __header; + unsigned int access; + unsigned int attributes; + unsigned int concurrent; + obj_handle_t rootdir; + /* VARARG(filename,string); */ +}; +struct create_completion_reply +{ + struct reply_header __header; + obj_handle_t handle; +}; + + + +struct open_completion_request +{ + struct request_header __header; + unsigned int access; + unsigned int attributes; + obj_handle_t rootdir; + /* VARARG(filename,string); */ +}; +struct open_completion_reply +{ + struct reply_header __header; + obj_handle_t handle; +}; + + + +struct add_completion_request +{ + struct request_header __header; + obj_handle_t handle; + unsigned long ckey; + unsigned long cvalue; + unsigned long information; + unsigned int status; +}; +struct add_completion_reply +{ + struct reply_header __header; +}; + + + +struct remove_completion_request +{ + struct request_header __header; + obj_handle_t handle; +}; +struct remove_completion_reply +{ + struct reply_header __header; + unsigned long ckey; + unsigned long cvalue; + unsigned long information; + unsigned int status; +}; + + + +struct query_completion_request +{ + struct request_header __header; + obj_handle_t handle; +}; +struct query_completion_reply +{ + struct reply_header __header; + unsigned int depth; +}; + + enum request { REQ_new_process, @@ -4300,6 +4378,11 @@ enum request REQ_get_next_device_request, REQ_make_process_system, REQ_get_token_statistics, + REQ_create_completion, + REQ_open_completion, + REQ_add_completion, + REQ_remove_completion, + REQ_query_completion, REQ_NB_REQUESTS }; @@ -4527,6 +4610,11 @@ union generic_request struct get_next_device_request_request get_next_device_request_request; struct make_process_system_request make_process_system_request; struct get_token_statistics_request get_token_statistics_request; + struct create_completion_request create_completion_request; + struct open_completion_request open_completion_request; + struct add_completion_request add_completion_request; + struct remove_completion_request remove_completion_request; + struct query_completion_request query_completion_request; }; union generic_reply { @@ -4752,8 +4840,13 @@ union generic_reply struct get_next_device_request_reply get_next_device_request_reply; struct make_process_system_reply make_process_system_reply; struct get_token_statistics_reply get_token_statistics_reply; + struct create_completion_reply create_completion_reply; + struct open_completion_reply open_completion_reply; + struct add_completion_reply add_completion_reply; + struct remove_completion_reply remove_completion_reply; + struct query_completion_reply query_completion_reply; }; -#define SERVER_PROTOCOL_VERSION 313 +#define SERVER_PROTOCOL_VERSION 314 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */ diff --git a/server/Makefile.in b/server/Makefile.in index bc0a6bd837f0f8b3e27cc583415d667dcef5aee6..4853b65d0851ca70ef9a74d0466b4c1206415293 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -12,6 +12,7 @@ C_SRCS = \ change.c \ class.c \ clipboard.c \ + completion.c \ console.c \ context_alpha.c \ context_i386.c \ diff --git a/server/completion.c b/server/completion.c new file mode 100644 index 0000000000000000000000000000000000000000..f024b44a076f6c5a5e4dec83278d4cc793fb9466 --- /dev/null +++ b/server/completion.c @@ -0,0 +1,242 @@ +/* + * Server-side IO completion ports implementation + * + * Copyright (C) 2007 Andrey Turkin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +/* FIXMEs: + * - built-in wait queues used which means: + * + threads are awaken FIFO and not LIFO as native does + * + "max concurrent active threads" parameter not used + * + completion handle is waitable, while native isn't + */ + +#include "config.h" +#include "wine/port.h" + +#include <stdio.h> + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winternl.h" + +#include "wine/unicode.h" +#include "object.h" +#include "handle.h" +#include "request.h" + + +struct completion +{ + struct object obj; + struct list queue; + unsigned int depth; +}; + +static void completion_dump( struct object*, int ); +static void completion_destroy( struct object * ); +static int completion_signaled( struct object *obj, struct thread *thread ); + +static const struct object_ops completion_ops = +{ + sizeof(struct completion), /* size */ + completion_dump, /* dump */ + add_queue, /* add_queue */ + remove_queue, /* remove_queue */ + completion_signaled, /* signaled */ + no_satisfied, /* satisfied */ + no_signal, /* signal */ + no_get_fd, /* get_fd */ + no_map_access, /* map_access */ + no_lookup_name, /* lookup_name */ + no_open_file, /* open_file */ + no_close_handle, /* close_handle */ + completion_destroy /* destroy */ +}; + +struct comp_msg +{ + struct list queue_entry; + unsigned long ckey; + unsigned long cvalue; + unsigned long information; + unsigned int status; +}; + +static void completion_destroy( struct object *obj) +{ + struct completion *completion = (struct completion *) obj; + struct comp_msg *tmp, *next; + + LIST_FOR_EACH_ENTRY_SAFE( tmp, next, &completion->queue, struct comp_msg, queue_entry ) + { + free( tmp ); + } +} + +static void completion_dump( struct object *obj, int verbose ) +{ + struct completion *completion = (struct completion *) obj; + + assert( obj->ops == &completion_ops ); + fprintf( stderr, "Completion " ); + dump_object_name( &completion->obj ); + fprintf( stderr, " (%u packets pending)\n", completion->depth ); +} + +static int completion_signaled( struct object *obj, struct thread *thread ) +{ + struct completion *completion = (struct completion *)obj; + + return !list_empty( &completion->queue ); +} + +static struct completion *create_completion( struct directory *root, const struct unicode_str *name, unsigned int attr, unsigned int concurrent ) +{ + struct completion *completion; + + if ((completion = create_named_object_dir( root, name, attr, &completion_ops ))) + { + if (get_error() != STATUS_OBJECT_NAME_EXISTS) + { + list_init( &completion->queue ); + completion->depth = 0; + } + } + + return completion; +} + +static struct completion *get_completion_obj( struct process *process, obj_handle_t handle, unsigned int access ) +{ + return (struct completion *) get_handle_obj( process, handle, access, &completion_ops ); +} + +static void add_completion( struct completion *completion, unsigned long ckey, unsigned long cvalue, unsigned int status, unsigned long information ) +{ + struct comp_msg *msg = mem_alloc( sizeof( *msg ) ); + + if (!msg) + return; + + msg->ckey = ckey; + msg->cvalue = cvalue; + msg->status = status; + msg->information = information; + + list_add_tail( &completion->queue, &msg->queue_entry ); + completion->depth++; + wake_up( &completion->obj, 1 ); +} + +/* create a completion */ +DECL_HANDLER(create_completion) +{ + struct completion *completion; + struct unicode_str name; + struct directory *root = NULL; + + reply->handle = 0; + + get_req_unicode_str( &name ); + if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) + return; + + if ( (completion = create_completion( root, &name, req->attributes, req->concurrent )) != NULL ) + { + reply->handle = alloc_handle( current->process, completion, req->access, req->attributes ); + release_object( completion ); + } + + if (root) release_object( root ); +} + +/* open a completion */ +DECL_HANDLER(open_completion) +{ + struct completion *completion; + struct unicode_str name; + struct directory *root = NULL; + + reply->handle = 0; + + get_req_unicode_str( &name ); + if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) + return; + + if ( (completion = open_object_dir( root, &name, req->attributes, &completion_ops )) != NULL ) + { + reply->handle = alloc_handle( current->process, completion, req->access, req->attributes ); + release_object( completion ); + } + + if (root) release_object( root ); +} + + +/* add completion to completion port */ +DECL_HANDLER(add_completion) +{ + struct completion* completion = get_completion_obj( current->process, req->handle, IO_COMPLETION_MODIFY_STATE ); + + if (!completion) return; + + add_completion( completion, req->ckey, req->cvalue, req->status, req->information ); + + release_object( completion ); +} + +/* get completion from completion port */ +DECL_HANDLER(remove_completion) +{ + struct completion* completion = get_completion_obj( current->process, req->handle, IO_COMPLETION_MODIFY_STATE ); + struct list *entry; + struct comp_msg *msg; + + if (!completion) return; + + entry = list_head( &completion->queue ); + if (!entry) + set_error( STATUS_PENDING ); + else + { + list_remove( entry ); + completion->depth--; + msg = LIST_ENTRY( entry, struct comp_msg, queue_entry ); + reply->ckey = msg->ckey; + reply->cvalue = msg->cvalue; + reply->status = msg->status; + reply->information = msg->information; + free( msg ); + } + + release_object( completion ); +} + +/* get queue depth for completion port */ +DECL_HANDLER(query_completion) +{ + struct completion* completion = get_completion_obj( current->process, req->handle, IO_COMPLETION_QUERY_STATE ); + + if (!completion) return; + + reply->depth = completion->depth; + + release_object( completion ); +} diff --git a/server/protocol.def b/server/protocol.def index 784a9f9e094877f3d8b39f7c3fe5f6044c119a95..8eec8a7596c42281e7d3abfca24d88cf750eb7a5 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -2931,3 +2931,55 @@ enum message_type int group_count; /* the number of groups the token is a member of */ int privilege_count; /* the number of privileges the token has */ @END + + +/* Create I/O completion port */ +@REQ(create_completion) + unsigned int access; /* desired access to a port */ + unsigned int attributes; /* object attributes */ + unsigned int concurrent; /* max number of concurrent active threads */ + obj_handle_t rootdir; /* root directory */ + VARARG(filename,string); /* port name */ +@REPLY + obj_handle_t handle; /* port handle */ +@END + + +/* Open I/O completion port */ +@REQ(open_completion) + unsigned int access; /* desired access to a port */ + unsigned int attributes; /* object attributes */ + obj_handle_t rootdir; /* root directory */ + VARARG(filename,string); /* port name */ +@REPLY + obj_handle_t handle; /* port handle */ +@END + + +/* add completion to completion port */ +@REQ(add_completion) + obj_handle_t handle; /* port handle */ + unsigned long ckey; /* completion key */ + unsigned long cvalue; /* completion value */ + unsigned long information; /* IO_STATUS_BLOCK Information */ + unsigned int status; /* completion result */ +@END + + +/* get completion from completion port queue */ +@REQ(remove_completion) + obj_handle_t handle; /* port handle */ +@REPLY + unsigned long ckey; /* completion key */ + unsigned long cvalue; /* completion value */ + unsigned long information; /* IO_STATUS_BLOCK Information */ + unsigned int status; /* completion result */ +@END + + +/* get completion queue depth */ +@REQ(query_completion) + obj_handle_t handle; /* port handle */ +@REPLY + unsigned int depth; /* completion queue depth */ +@END diff --git a/server/request.h b/server/request.h index fe94d2e37772114d421fb66388b03d885815157e..741156596eacd3667bee0124e3e6d11b7c3ae84e 100644 --- a/server/request.h +++ b/server/request.h @@ -330,6 +330,11 @@ DECL_HANDLER(delete_device); DECL_HANDLER(get_next_device_request); DECL_HANDLER(make_process_system); DECL_HANDLER(get_token_statistics); +DECL_HANDLER(create_completion); +DECL_HANDLER(open_completion); +DECL_HANDLER(add_completion); +DECL_HANDLER(remove_completion); +DECL_HANDLER(query_completion); #ifdef WANT_REQUEST_HANDLERS @@ -556,6 +561,11 @@ static const req_handler req_handlers[REQ_NB_REQUESTS] = (req_handler)req_get_next_device_request, (req_handler)req_make_process_system, (req_handler)req_get_token_statistics, + (req_handler)req_create_completion, + (req_handler)req_open_completion, + (req_handler)req_add_completion, + (req_handler)req_remove_completion, + (req_handler)req_query_completion, }; #endif /* WANT_REQUEST_HANDLERS */ diff --git a/server/trace.c b/server/trace.c index e6ff06dca18a9f9f1578961068f51d89972a7482..b43141351378f3388ced373ca3aee832c0ee7131 100644 --- a/server/trace.c +++ b/server/trace.c @@ -3567,6 +3567,67 @@ static void dump_get_token_statistics_reply( const struct get_token_statistics_r fprintf( stderr, " privilege_count=%d", req->privilege_count ); } +static void dump_create_completion_request( const struct create_completion_request *req ) +{ + fprintf( stderr, " access=%08x,", req->access ); + fprintf( stderr, " attributes=%08x,", req->attributes ); + fprintf( stderr, " concurrent=%08x,", req->concurrent ); + fprintf( stderr, " rootdir=%p,", req->rootdir ); + fprintf( stderr, " filename=" ); + dump_varargs_string( cur_size ); +} + +static void dump_create_completion_reply( const struct create_completion_reply *req ) +{ + fprintf( stderr, " handle=%p", req->handle ); +} + +static void dump_open_completion_request( const struct open_completion_request *req ) +{ + fprintf( stderr, " access=%08x,", req->access ); + fprintf( stderr, " attributes=%08x,", req->attributes ); + fprintf( stderr, " rootdir=%p,", req->rootdir ); + fprintf( stderr, " filename=" ); + dump_varargs_string( cur_size ); +} + +static void dump_open_completion_reply( const struct open_completion_reply *req ) +{ + fprintf( stderr, " handle=%p", req->handle ); +} + +static void dump_add_completion_request( const struct add_completion_request *req ) +{ + fprintf( stderr, " handle=%p,", req->handle ); + fprintf( stderr, " ckey=%lx,", req->ckey ); + fprintf( stderr, " cvalue=%lx,", req->cvalue ); + fprintf( stderr, " information=%lx,", req->information ); + fprintf( stderr, " status=%08x", req->status ); +} + +static void dump_remove_completion_request( const struct remove_completion_request *req ) +{ + fprintf( stderr, " handle=%p", req->handle ); +} + +static void dump_remove_completion_reply( const struct remove_completion_reply *req ) +{ + fprintf( stderr, " ckey=%lx,", req->ckey ); + fprintf( stderr, " cvalue=%lx,", req->cvalue ); + fprintf( stderr, " information=%lx,", req->information ); + fprintf( stderr, " status=%08x", req->status ); +} + +static void dump_query_completion_request( const struct query_completion_request *req ) +{ + fprintf( stderr, " handle=%p", req->handle ); +} + +static void dump_query_completion_reply( const struct query_completion_reply *req ) +{ + fprintf( stderr, " depth=%08x", req->depth ); +} + static const dump_func req_dumpers[REQ_NB_REQUESTS] = { (dump_func)dump_new_process_request, (dump_func)dump_get_new_process_info_request, @@ -3788,6 +3849,11 @@ static const dump_func req_dumpers[REQ_NB_REQUESTS] = { (dump_func)dump_get_next_device_request_request, (dump_func)dump_make_process_system_request, (dump_func)dump_get_token_statistics_request, + (dump_func)dump_create_completion_request, + (dump_func)dump_open_completion_request, + (dump_func)dump_add_completion_request, + (dump_func)dump_remove_completion_request, + (dump_func)dump_query_completion_request, }; static const dump_func reply_dumpers[REQ_NB_REQUESTS] = { @@ -4011,6 +4077,11 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = { (dump_func)dump_get_next_device_request_reply, (dump_func)dump_make_process_system_reply, (dump_func)dump_get_token_statistics_reply, + (dump_func)dump_create_completion_reply, + (dump_func)dump_open_completion_reply, + (dump_func)0, + (dump_func)dump_remove_completion_reply, + (dump_func)dump_query_completion_reply, }; static const char * const req_names[REQ_NB_REQUESTS] = { @@ -4234,6 +4305,11 @@ static const char * const req_names[REQ_NB_REQUESTS] = { "get_next_device_request", "make_process_system", "get_token_statistics", + "create_completion", + "open_completion", + "add_completion", + "remove_completion", + "query_completion", }; static const struct