Based on a patch by Chip Davis.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=30155 Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 22 ++++++-------- dlls/ntoskrnl.exe/tests/ntoskrnl.c | 49 +++++++++++++----------------- server/async.c | 38 ++++++++++++++++++----- server/device.c | 31 +++++++++++++------ server/file.h | 2 ++ server/protocol.def | 1 + 6 files changed, 86 insertions(+), 57 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index b4d038c299b..42976f4905e 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -492,6 +492,7 @@ static NTSTATUS dispatch_irp( DEVICE_OBJECT *device, IRP *irp, struct dispatch_c { struct irp_data *irp_data; LARGE_INTEGER count; + NTSTATUS status;
if (!(irp_data = malloc( sizeof(*irp_data) ))) return STATUS_NO_MEMORY; @@ -508,11 +509,14 @@ static NTSTATUS dispatch_irp( DEVICE_OBJECT *device, IRP *irp, struct dispatch_c
device->CurrentIrp = irp; KeEnterCriticalRegion(); - IoCallDriver( device, irp ); + status = IoCallDriver( device, irp ); KeLeaveCriticalRegion(); device->CurrentIrp = NULL;
- return STATUS_SUCCESS; + if (status != STATUS_PENDING && !irp_data->complete) + ERR( "dispatch routine returned %#x but didn't complete the IRP\n", status ); + + return status; }
/* process a create request for a given file */ @@ -934,6 +938,7 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ) IRP *irp = context.irp_data->irp;
req->user_ptr = wine_server_client_ptr( irp ); + req->status = status;
if (context.irp_data->complete) { @@ -943,19 +948,12 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ) if (irp->Flags & IRP_WRITE_OPERATION) out_buff = NULL; /* do not transfer back input buffer */
- req->prev = wine_server_obj_handle( context.irp_data->handle ); - req->status = irp->IoStatus.u.Status; - req->result = irp->IoStatus.Information; + req->prev = wine_server_obj_handle( context.irp_data->handle ); + req->iosb_status = irp->IoStatus.u.Status; + req->result = irp->IoStatus.Information; if (!NT_ERROR(irp->IoStatus.u.Status) && out_buff) wine_server_add_data( req, out_buff, irp->IoStatus.Information ); } - else - { - if (status == STATUS_SUCCESS) - status = STATUS_PENDING; - - req->status = status; - } } else { diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index b736cfff3ba..7c4b0154781 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -663,19 +663,16 @@ static void do_return_status(ULONG ioctl, struct return_status_params *params) size = 0xdeadf00d; SetLastError(0xdeadf00d); ret = DeviceIoControl(device, ioctl, params, sizeof(*params), buffer, sizeof(buffer), &size, NULL); - todo_wine_if ((params->iosb_status != STATUS_PENDING && NT_SUCCESS(expect_status) != NT_SUCCESS(params->iosb_status)) - || (params->iosb_status == STATUS_PENDING && NT_SUCCESS(expect_status))) + todo_wine_if (params->ret_status == STATUS_PENDING && params->iosb_status == STATUS_PENDING) ok(ret == NT_SUCCESS(expect_status), "got %d\n", ret); if (NT_SUCCESS(expect_status)) { - todo_wine_if (!NT_SUCCESS(params->iosb_status) || params->iosb_status == STATUS_PENDING) + todo_wine_if (params->ret_status == STATUS_PENDING && params->iosb_status == STATUS_PENDING) ok(GetLastError() == 0xdeadf00d, "got error %u\n", GetLastError()); } else { - todo_wine_if (RtlNtStatusToDosError(expect_status) != RtlNtStatusToDosError(params->iosb_status) - || NT_SUCCESS(params->iosb_status)) - ok(GetLastError() == RtlNtStatusToDosError(expect_status), "got error %u\n", GetLastError()); + ok(GetLastError() == RtlNtStatusToDosError(expect_status), "got error %u\n", GetLastError()); } if (NT_ERROR(expect_status)) todo_wine ok(size == 0xdeadf00d, "got size %u\n", size); @@ -690,8 +687,7 @@ static void do_return_status(ULONG ioctl, struct return_status_params *params) io.Information = 0xdeadf00d; ret = NtDeviceIoControlFile(device, NULL, NULL, NULL, &io, ioctl, params, sizeof(*params), buffer, sizeof(buffer)); - todo_wine_if (params->ret_status != params->iosb_status && params->ret_status != STATUS_PENDING) - ok(ret == expect_status, "got %#x\n", ret); + ok(ret == expect_status, "got %#x\n", ret); if (NT_ERROR(params->iosb_status)) { todo_wine ok(io.Status == 0xdeadf00d, "got %#x\n", io.Status); @@ -725,10 +721,9 @@ static void do_return_status(ULONG ioctl, struct return_status_params *params) io.Information = 0xdeadf00d; ret = NtDeviceIoControlFile(file, event, NULL, (void *)456, &io, ioctl, params, sizeof(*params), buffer, sizeof(buffer)); - todo_wine_if (params->ret_status != params->iosb_status) - ok(ret == params->ret_status - || broken(NT_WARNING(params->ret_status) && ret == STATUS_PENDING), /* win10 */ - "got %#x\n", ret); + ok(ret == params->ret_status + || broken(NT_WARNING(params->ret_status) && ret == STATUS_PENDING), /* win10 */ + "got %#x\n", ret); if (!params->pending && NT_ERROR(params->iosb_status)) { todo_wine ok(io.Status == 0xdeadf00d, "got %#x\n", io.Status); @@ -778,10 +773,9 @@ static void do_return_status(ULONG ioctl, struct return_status_params *params) io.Information = 0xdeadf00d; ret = NtDeviceIoControlFile(file, event, NULL, NULL, &io, ioctl, params, sizeof(*params), buffer, sizeof(buffer)); - todo_wine_if (params->ret_status != params->iosb_status) - ok(ret == params->ret_status - || broken(NT_WARNING(params->ret_status) && ret == STATUS_PENDING), /* win10 */ - "got %#x\n", ret); + ok(ret == params->ret_status + || broken(NT_WARNING(params->ret_status) && ret == STATUS_PENDING), /* win10 */ + "got %#x\n", ret); if (!params->pending && NT_ERROR(params->iosb_status)) { todo_wine ok(io.Status == 0xdeadf00d, "got %#x\n", io.Status); @@ -811,10 +805,9 @@ static void do_return_status(ULONG ioctl, struct return_status_params *params) io.Information = 0xdeadf00d; ret = NtDeviceIoControlFile(file, NULL, NULL, NULL, &io, ioctl, params, sizeof(*params), buffer, sizeof(buffer)); - todo_wine_if (params->ret_status != params->iosb_status) - ok(ret == params->ret_status - || broken(NT_WARNING(params->ret_status) && ret == STATUS_PENDING), /* win10 */ - "got %#x\n", ret); + ok(ret == params->ret_status + || broken(NT_WARNING(params->ret_status) && ret == STATUS_PENDING), /* win10 */ + "got %#x\n", ret); if (!params->pending && NT_ERROR(params->iosb_status)) { todo_wine ok(io.Status == 0xdeadf00d, "got %#x\n", io.Status); @@ -848,10 +841,9 @@ static void do_return_status(ULONG ioctl, struct return_status_params *params) io.Information = 0xdeadf00d; ret = NtDeviceIoControlFile(file, event, NULL, (void *)456, &io, ioctl, params, sizeof(*params), buffer, sizeof(buffer)); - todo_wine_if (params->ret_status != params->iosb_status) - ok(ret == params->ret_status - || broken(NT_WARNING(params->ret_status) && ret == STATUS_PENDING), /* win10 */ - "got %#x\n", ret); + ok(ret == params->ret_status + || broken(NT_WARNING(params->ret_status) && ret == STATUS_PENDING), /* win10 */ + "got %#x\n", ret); if (!params->pending && NT_ERROR(params->iosb_status)) { todo_wine ok(io.Status == 0xdeadf00d, "got %#x\n", io.Status); @@ -890,14 +882,16 @@ static void do_return_status(ULONG ioctl, struct return_status_params *params) } else { - todo_wine ok(!ret, "got %#x\n", ret); + todo_wine_if (params->ret_status != STATUS_PENDING) + ok(!ret, "got %#x\n", ret); } if (!ret) { ok(key == 123, "got key %Iu\n", key); ok(value == 456, "got value %Iu\n", value); ok(io.Status == params->iosb_status, "got iosb status %#x\n", io.Status); - ok(io.Information == 3, "got information %Iu\n", io.Information); + todo_wine_if (params->iosb_status == STATUS_PENDING) + ok(io.Information == 3, "got information %Iu\n", io.Information); } }
@@ -919,8 +913,7 @@ static void do_return_status(ULONG ioctl, struct return_status_params *params) io.Information = 0xdeadf00d; ret = NtDeviceIoControlFile(file, NULL, return_status_apc, (void *)456, &io, ioctl, params, sizeof(*params), buffer, sizeof(buffer)); - todo_wine_if (params->ret_status != params->iosb_status) - ok(ret == params->ret_status, "got %#x\n", ret); + ok(ret == params->ret_status, "got %#x\n", ret); if (!params->pending && NT_ERROR(params->iosb_status)) { todo_wine ok(io.Status == 0xdeadf00d, "got %#x\n", io.Status); diff --git a/server/async.c b/server/async.c index 2dbdfc76a59..df30ae3c7da 100644 --- a/server/async.c +++ b/server/async.c @@ -48,6 +48,7 @@ struct async async_data_t data; /* data for async I/O call */ struct iosb *iosb; /* I/O status block */ obj_handle_t wait_handle; /* pre-allocated wait handle */ + unsigned int initial_status; /* status returned from initial request */ unsigned int signaled :1; unsigned int pending :1; /* request successfully queued, but pending */ unsigned int direct_result :1;/* a flag if we're passing result directly from request instead of APC */ @@ -125,7 +126,10 @@ static void async_satisfied( struct object *obj, struct wait_queue_entry *entry async->direct_result = 0; }
- set_wait_status( entry, async->iosb->status ); + if (async->initial_status == STATUS_PENDING && async->blocking) + set_wait_status( entry, async->iosb->status ); + else + set_wait_status( entry, async->initial_status );
/* close wait handle here to avoid extra server round trip */ if (async->wait_handle) @@ -255,6 +259,7 @@ struct async *create_async( struct fd *fd, struct thread *thread, const async_da async->timeout = NULL; async->queue = NULL; async->fd = (struct fd *)grab_object( fd ); + async->initial_status = STATUS_PENDING; async->signaled = 0; async->pending = 1; async->wait_handle = 0; @@ -285,17 +290,31 @@ struct async *create_async( struct fd *fd, struct thread *thread, const async_da return async; }
+/* set the initial status of an async whose status was previously unknown + * the initial status may be STATUS_PENDING */ +void async_set_initial_status( struct async *async, unsigned int status ) +{ + assert( async->unknown_status ); + if (!async->terminated) + { + async->initial_status = status; + async->unknown_status = 0; + } +} + void set_async_pending( struct async *async ) { if (!async->terminated) - { async->pending = 1; - async->unknown_status = 0; - if (!async->blocking && !async->signaled) - { - async->signaled = 1; - wake_up( &async->obj, 0 ); - } +} + +void async_wake_obj( struct async *async ) +{ + assert( !async->unknown_status ); + if (!async->blocking) + { + async->signaled = 1; + wake_up( &async->obj, 0 ); } }
@@ -311,6 +330,8 @@ obj_handle_t async_handoff( struct async *async, data_size_t *result, int force_ return async->wait_handle; }
+ async->initial_status = get_error(); + if (!async->pending && NT_ERROR( get_error() )) { close_handle( async->thread->process, async->wait_handle ); @@ -348,6 +369,7 @@ obj_handle_t async_handoff( struct async *async, data_size_t *result, int force_ async->wait_handle = 0; } } + async->initial_status = async->iosb->status; set_error( async->iosb->status ); return async->wait_handle; } diff --git a/server/device.c b/server/device.c index b0e417a6473..df1a71a5a4d 100644 --- a/server/device.c +++ b/server/device.c @@ -952,18 +952,31 @@ DECL_HANDLER(get_next_device_request) irp = manager->current_call; irp->user_ptr = req->user_ptr;
- if (req->prev) + if (irp->async) { - set_irp_result( irp, req->status, get_req_data(), get_req_data_size(), req->result ); - close_handle( current->process, req->prev ); /* avoid an extra round-trip for close */ + if (req->status == STATUS_PENDING) + set_async_pending( irp->async ); + async_set_initial_status( irp->async, req->status ); + + if (req->prev) + { + set_irp_result( irp, req->iosb_status, get_req_data(), get_req_data_size(), req->result ); + close_handle( current->process, req->prev ); /* avoid an extra round-trip for close */ + } + else + { + async_wake_obj( irp->async ); + if (irp->canceled) + { + /* if it was canceled during dispatch, we couldn't queue cancel + * call without client pointer, so we need to do it now */ + cancel_irp_call( irp ); + } + } } - else if (irp->async) + else { - set_async_pending( irp->async ); - if (irp->canceled) - /* if it was canceled during dispatch, we couldn't queue cancel call without client pointer, - * so we need to do it now */ - cancel_irp_call( irp ); + set_irp_result( irp, req->status, NULL, 0, 0 ); }
free_irp_params( irp ); diff --git a/server/file.h b/server/file.h index 80f2191c050..1d830cd3d6f 100644 --- a/server/file.h +++ b/server/file.h @@ -230,6 +230,8 @@ extern void async_set_result( struct object *obj, unsigned int status, apc_param extern void async_set_completion_callback( struct async *async, async_completion_callback func, void *private ); extern void async_set_unknown_status( struct async *async ); extern void set_async_pending( struct async *async ); +extern void async_set_initial_status( struct async *async, unsigned int status ); +extern void async_wake_obj( struct async *async ); extern int async_waiting( struct async_queue *queue ); extern void async_terminate( struct async *async, unsigned int status ); extern void async_request_complete( struct async *async, unsigned int status, data_size_t result, diff --git a/server/protocol.def b/server/protocol.def index fec212a3ea3..608c481db27 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -3368,6 +3368,7 @@ struct handle_info obj_handle_t prev; /* handle to the previous irp */ unsigned int status; /* status of the previous irp */ client_ptr_t user_ptr; /* user pointer of the previous irp */ + unsigned int iosb_status; /* IOSB status of the previous irp */ data_size_t result; /* IOSB result of the previous irp */ VARARG(data,bytes); /* output data of the previous irp */ @REPLY