On 20 June 2011 15:08, Vitaliy Margolen <wine-de...@kievinfo.com> wrote: > On 06/19/2011 08:15 PM, Austin Lund wrote: >> >> + ret = wine_server_call( req ); >> + shi->Count += reply->handles; >> + len = sizeof(SYSTEM_HANDLE_ENTRY)*shi->Count + >> sizeof(ULONG); >> + shi = RtlReAllocateHeap(GetProcessHeap(), >> HEAP_ZERO_MEMORY, shi, len); > > Please do allocations outside of server call block. And add handling of > failed realloc. Also please double the allocated size, don't reallocate > after each server call. > >> + for (i = shi->Count - reply->handles; i< shi->Count; >> i++) { >> + shi->Handle[i].OwnerPid = reply->pid; >> + } > > Please follow file's curly braces style - none for single line blocks, or on > separate line for multi-line blocks. >
Thanks for the review. Does this patch address these concerns correctly?
From b4b4310cc28560ea30d1ad6a7961f4c5b443c73a Mon Sep 17 00:00:00 2001 From: Austin Lund <austin.l...@gmail.com> Date: Sun, 12 Jun 2011 19:41:18 +1000 Subject: [PATCH 1/2] dlls/ntdll: Add handle count to NtQuerySystemInformation (try 2) Reply-To: wine-devel <wine-devel@winehq.org> --- dlls/ntdll/nt.c | 73 +++++++++++++++++++++++++++++++++++++++++++---- dlls/ntdll/tests/info.c | 8 +---- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c index f9302c1..5e7a711 100644 --- a/dlls/ntdll/nt.c +++ b/dlls/ntdll/nt.c @@ -1655,18 +1655,79 @@ NTSTATUS WINAPI NtQuerySystemInformation( break; case SystemHandleInformation: { - SYSTEM_HANDLE_INFORMATION shi; + SYSTEM_HANDLE_INFORMATION *shi; + HANDLE hSnap = 0; + + FIXME("info_class SYSTEM_HANDLE_INFORMATION partial implementation\n"); + + SERVER_START_REQ( create_snapshot ) + { + req->flags = SNAP_PROCESS; + req->attributes = 0; + if (!(ret = wine_server_call( req ))) + hSnap = wine_server_ptr_handle( reply->handle ); + } + SERVER_END_REQ; + + len = 128; + shi = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, len); + if (shi == NULL) + return STATUS_NO_MEMORY; - memset(&shi, 0, sizeof(shi)); - len = sizeof(shi); + for (;;) + { + int i, handle_count; + process_id_t pid; + + SERVER_START_REQ( next_process ) + { + req->handle = wine_server_obj_handle( hSnap ); + req->reset = 0; + ret = wine_server_call( req ); + handle_count = reply->handles; + pid = reply->pid; + } + SERVER_END_REQ; + + if (ret != STATUS_SUCCESS) break; + + shi->Count += handle_count; + while (sizeof(ULONG) + sizeof(SYSTEM_HANDLE_ENTRY)*shi->Count >= len) + { + len = 2*len; + shi = RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, shi, len); + if (shi == NULL) + return STATUS_NO_MEMORY; + + } + + for (i = shi->Count - handle_count; i < shi->Count; i++) + shi->Handle[i].OwnerPid = pid; + } + + len = sizeof(SYSTEM_HANDLE_ENTRY)*shi->Count + sizeof(ULONG); + shi = RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, shi, len); + if (shi == NULL) + return STATUS_NO_MEMORY; + + if ( ResultLength ) + *ResultLength = len; if ( Length >= len) { if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION; - else memcpy( SystemInformation, &shi, len); + else + { + memcpy(SystemInformation, shi, len); + RtlFreeHeap(GetProcessHeap(), 0, shi); + shi = NULL; + ret = STATUS_SUCCESS; + } } - else ret = STATUS_INFO_LENGTH_MISMATCH; - FIXME("info_class SYSTEM_HANDLE_INFORMATION\n"); + else + ret = STATUS_INFO_LENGTH_MISMATCH; + + if (hSnap) NtClose(hSnap); } break; case SystemCacheInformation: diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c index 2d5c94f..f82bdfd 100644 --- a/dlls/ntdll/tests/info.c +++ b/dlls/ntdll/tests/info.c @@ -468,7 +468,7 @@ static void test_query_handle(void) /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */ status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength); - todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status); + ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status); SystemInformationLength = ReturnLength; shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength); @@ -480,11 +480,7 @@ static void test_query_handle(void) /* Check if we have some return values */ trace("Number of Handles : %d\n", shi->Count); - todo_wine - { - /* our implementation is a stub for now */ - ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count); - } + ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count); } HeapFree( GetProcessHeap(), 0, shi); } -- 1.7.4.1