kernelbase: Use set_ntstatus() in more places.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-09-27 12:42:16 +02:00
parent 0bfee2c6eb
commit 31d522ea53
5 changed files with 43 additions and 135 deletions

View File

@ -573,7 +573,6 @@ BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceTypesExA( HMODULE module, ENUMRESTYPEP
BOOL ret = FALSE; BOOL ret = FALSE;
LPSTR type = NULL; LPSTR type = NULL;
DWORD len = 0, newlen; DWORD len = 0, newlen;
NTSTATUS status;
const IMAGE_RESOURCE_DIRECTORY *resdir; const IMAGE_RESOURCE_DIRECTORY *resdir;
const IMAGE_RESOURCE_DIRECTORY_ENTRY *et; const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
const IMAGE_RESOURCE_DIR_STRING_U *str; const IMAGE_RESOURCE_DIR_STRING_U *str;
@ -588,11 +587,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceTypesExA( HMODULE module, ENUMRESTYPEP
if (!module) module = GetModuleHandleW( 0 ); if (!module) module = GetModuleHandleW( 0 );
if ((status = LdrFindResourceDirectory_U( module, NULL, 0, &resdir )) != STATUS_SUCCESS) if (!set_ntstatus( LdrFindResourceDirectory_U( module, NULL, 0, &resdir ))) return FALSE;
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1); et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1);
for (i = 0; i < resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries; i++) for (i = 0; i < resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries; i++)
{ {
@ -630,7 +626,6 @@ BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceTypesExW( HMODULE module, ENUMRESTYPEP
int i, len = 0; int i, len = 0;
BOOL ret = FALSE; BOOL ret = FALSE;
LPWSTR type = NULL; LPWSTR type = NULL;
NTSTATUS status;
const IMAGE_RESOURCE_DIRECTORY *resdir; const IMAGE_RESOURCE_DIRECTORY *resdir;
const IMAGE_RESOURCE_DIRECTORY_ENTRY *et; const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
const IMAGE_RESOURCE_DIR_STRING_U *str; const IMAGE_RESOURCE_DIR_STRING_U *str;
@ -642,11 +637,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceTypesExW( HMODULE module, ENUMRESTYPEP
if (!module) module = GetModuleHandleW( 0 ); if (!module) module = GetModuleHandleW( 0 );
if ((status = LdrFindResourceDirectory_U( module, NULL, 0, &resdir )) != STATUS_SUCCESS) if (!set_ntstatus( LdrFindResourceDirectory_U( module, NULL, 0, &resdir ))) return FALSE;
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1); et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1);
for (i = 0; i < resdir->NumberOfNamedEntries + resdir->NumberOfIdEntries; i++) for (i = 0; i < resdir->NumberOfNamedEntries + resdir->NumberOfIdEntries; i++)
{ {
@ -735,15 +727,14 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeResource( HGLOBAL handle )
*/ */
HGLOBAL WINAPI DECLSPEC_HOTPATCH LoadResource( HINSTANCE module, HRSRC rsrc ) HGLOBAL WINAPI DECLSPEC_HOTPATCH LoadResource( HINSTANCE module, HRSRC rsrc )
{ {
NTSTATUS status; void *ret;
void *ret = NULL;
TRACE( "%p %p\n", module, rsrc ); TRACE( "%p %p\n", module, rsrc );
if (!rsrc) return 0; if (!rsrc) return 0;
if (!module) module = GetModuleHandleW( 0 ); if (!module) module = GetModuleHandleW( 0 );
status = LdrAccessResource( module, (IMAGE_RESOURCE_DATA_ENTRY *)rsrc, &ret, NULL ); if (!set_ntstatus( LdrAccessResource( module, (IMAGE_RESOURCE_DATA_ENTRY *)rsrc, &ret, NULL )))
if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) ); return 0;
return ret; return ret;
} }
@ -795,16 +786,11 @@ void WINAPI DECLSPEC_HOTPATCH AddRefActCtx( HANDLE context )
*/ */
HANDLE WINAPI DECLSPEC_HOTPATCH CreateActCtxW( PCACTCTXW ctx ) HANDLE WINAPI DECLSPEC_HOTPATCH CreateActCtxW( PCACTCTXW ctx )
{ {
NTSTATUS status;
HANDLE context; HANDLE context;
TRACE( "%p %08x\n", ctx, ctx ? ctx->dwFlags : 0 ); TRACE( "%p %08x\n", ctx, ctx ? ctx->dwFlags : 0 );
if ((status = RtlCreateActivationContext( &context, ctx ))) if (!set_ntstatus( RtlCreateActivationContext( &context, ctx ))) return INVALID_HANDLE_VALUE;
{
SetLastError( RtlNtStatusToDosError(status) );
return INVALID_HANDLE_VALUE;
}
return context; return context;
} }

View File

@ -202,23 +202,13 @@ BOOL WINAPI QuirkIsEnabled3(void *unk1, void *unk2)
BOOL WINAPI WaitOnAddress(volatile void *addr, void *cmp, SIZE_T size, DWORD timeout) BOOL WINAPI WaitOnAddress(volatile void *addr, void *cmp, SIZE_T size, DWORD timeout)
{ {
LARGE_INTEGER to; LARGE_INTEGER to;
NTSTATUS status;
if (timeout != INFINITE) if (timeout != INFINITE)
{ {
to.QuadPart = -(LONGLONG)timeout * 10000; to.QuadPart = -(LONGLONG)timeout * 10000;
status = RtlWaitOnAddress((const void *)addr, cmp, size, &to); return set_ntstatus( RtlWaitOnAddress( (const void *)addr, cmp, size, &to ));
} }
else return set_ntstatus( RtlWaitOnAddress( (const void *)addr, cmp, size, NULL ));
status = RtlWaitOnAddress((const void *)addr, cmp, size, NULL);
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
return TRUE;
} }
HRESULT WINAPI QISearch(void *base, const QITAB *table, REFIID riid, void **obj) HRESULT WINAPI QISearch(void *base, const QITAB *table, REFIID riid, void **obj)

View File

@ -51,12 +51,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(heap);
BOOL WINAPI DECLSPEC_HOTPATCH FlushViewOfFile( const void *base, SIZE_T size ) BOOL WINAPI DECLSPEC_HOTPATCH FlushViewOfFile( const void *base, SIZE_T size )
{ {
NTSTATUS status = NtFlushVirtualMemory( GetCurrentProcess(), &base, &size, 0 ); NTSTATUS status = NtFlushVirtualMemory( GetCurrentProcess(), &base, &size, 0 );
if (status)
{
if (status == STATUS_NOT_MAPPED_DATA) status = STATUS_SUCCESS; if (status == STATUS_NOT_MAPPED_DATA) status = STATUS_SUCCESS;
else SetLastError( RtlNtStatusToDosError(status) ); return set_ntstatus( status );
}
return !status;
} }

View File

@ -148,18 +148,12 @@ static HANDLE normalize_handle_if_console( HANDLE handle )
HANDLE WINAPI DECLSPEC_HOTPATCH RegisterWaitForSingleObjectEx( HANDLE handle, WAITORTIMERCALLBACK callback, HANDLE WINAPI DECLSPEC_HOTPATCH RegisterWaitForSingleObjectEx( HANDLE handle, WAITORTIMERCALLBACK callback,
PVOID context, ULONG timeout, ULONG flags ) PVOID context, ULONG timeout, ULONG flags )
{ {
NTSTATUS status;
HANDLE ret; HANDLE ret;
TRACE( "%p %p %p %d %d\n", handle, callback, context, timeout, flags ); TRACE( "%p %p %p %d %d\n", handle, callback, context, timeout, flags );
handle = normalize_handle_if_console( handle ); handle = normalize_handle_if_console( handle );
status = RtlRegisterWait( &ret, handle, callback, context, timeout, flags ); if (!set_ntstatus( RtlRegisterWait( &ret, handle, callback, context, timeout, flags ))) return NULL;
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return NULL;
}
return ret; return ret;
} }
@ -388,18 +382,12 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW( DWORD access, BOOL inherit, LPCWSTR
HANDLE ret; HANDLE ret;
UNICODE_STRING nameW; UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
NTSTATUS status;
if (!is_version_nt()) access = EVENT_ALL_ACCESS; if (!is_version_nt()) access = EVENT_ALL_ACCESS;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0; if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
status = NtOpenEvent( &ret, access, &attr ); if (!set_ntstatus( NtOpenEvent( &ret, access, &attr ))) return 0;
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return ret; return ret;
} }
@ -505,18 +493,12 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexW( DWORD access, BOOL inherit, LPCWSTR
HANDLE ret; HANDLE ret;
UNICODE_STRING nameW; UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
NTSTATUS status;
if (!is_version_nt()) access = MUTEX_ALL_ACCESS; if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0; if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
status = NtOpenMutant( &ret, access, &attr ); if (!set_ntstatus( NtOpenMutant( &ret, access, &attr ))) return 0;
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return ret; return ret;
} }
@ -575,18 +557,12 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreW( DWORD access, BOOL inherit, LPCW
HANDLE ret; HANDLE ret;
UNICODE_STRING nameW; UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
NTSTATUS status;
if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS; if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0; if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
status = NtOpenSemaphore( &ret, access, &attr ); if (!set_ntstatus( NtOpenSemaphore( &ret, access, &attr ))) return 0;
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return ret; return ret;
} }
@ -646,18 +622,12 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenWaitableTimerW( DWORD access, BOOL inherit,
HANDLE handle; HANDLE handle;
UNICODE_STRING nameW; UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
NTSTATUS status;
if (!is_version_nt()) access = TIMER_ALL_ACCESS; if (!is_version_nt()) access = TIMER_ALL_ACCESS;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0; if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
status = NtOpenTimer( &handle, access, &attr ); if (!set_ntstatus( NtOpenTimer( &handle, access, &attr ))) return 0;
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return handle; return handle;
} }
@ -709,13 +679,8 @@ BOOL WINAPI DECLSPEC_HOTPATCH CancelWaitableTimer( HANDLE handle )
HANDLE WINAPI DECLSPEC_HOTPATCH CreateTimerQueue(void) HANDLE WINAPI DECLSPEC_HOTPATCH CreateTimerQueue(void)
{ {
HANDLE q; HANDLE q;
NTSTATUS status = RtlCreateTimerQueue( &q );
if (status != STATUS_SUCCESS) if (!set_ntstatus( RtlCreateTimerQueue( &q ))) return NULL;
{
SetLastError( RtlNtStatusToDosError( status ));
return NULL;
}
return q; return q;
} }
@ -864,7 +829,6 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenFileMappingW( DWORD access, BOOL inherit, LP
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW; UNICODE_STRING nameW;
HANDLE ret; HANDLE ret;
NTSTATUS status;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0; if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
@ -876,12 +840,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenFileMappingW( DWORD access, BOOL inherit, LP
if (!NtOpenSection( &ret, access | SECTION_MAP_READ | SECTION_MAP_WRITE, &attr )) return ret; if (!NtOpenSection( &ret, access | SECTION_MAP_READ | SECTION_MAP_WRITE, &attr )) return ret;
} }
status = NtOpenSection( &ret, access, &attr ); if (!set_ntstatus( NtOpenSection( &ret, access, &attr ))) return 0;
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return ret; return ret;
} }
@ -929,19 +888,15 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateIoCompletionPort( HANDLE handle, HANDLE po
{ {
FILE_COMPLETION_INFORMATION info; FILE_COMPLETION_INFORMATION info;
IO_STATUS_BLOCK iosb; IO_STATUS_BLOCK iosb;
NTSTATUS status;
HANDLE ret = port; HANDLE ret = port;
TRACE( "(%p, %p, %08lx, %08x)\n", handle, port, key, threads ); TRACE( "(%p, %p, %08lx, %08x)\n", handle, port, key, threads );
if (!port) if (!port)
{ {
if ((status = NtCreateIoCompletion( &ret, IO_COMPLETION_ALL_ACCESS, NULL, threads ))) if (!set_ntstatus( NtCreateIoCompletion( &ret, IO_COMPLETION_ALL_ACCESS, NULL, threads )))
{
SetLastError( RtlNtStatusToDosError(status) );
return 0; return 0;
} }
}
else if (handle == INVALID_HANDLE_VALUE) else if (handle == INVALID_HANDLE_VALUE)
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
@ -952,10 +907,9 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateIoCompletionPort( HANDLE handle, HANDLE po
{ {
info.CompletionPort = ret; info.CompletionPort = ret;
info.CompletionKey = key; info.CompletionKey = key;
if ((status = NtSetInformationFile( handle, &iosb, &info, sizeof(info), FileCompletionInformation ))) if (!set_ntstatus( NtSetInformationFile( handle, &iosb, &info, sizeof(info), FileCompletionInformation )))
{ {
if (!port) CloseHandle( ret ); if (!port) CloseHandle( ret );
SetLastError( RtlNtStatusToDosError(status) );
return 0; return 0;
} }
} }
@ -1163,11 +1117,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateNamedPipeW( LPCWSTR name, DWORD open_mode,
FILE_OVERWRITE_IF, options, pipe_type, FILE_OVERWRITE_IF, options, pipe_type,
read_mode, non_block, instances, in_buff, out_buff, &time ); read_mode, non_block, instances, in_buff, out_buff, &time );
RtlFreeUnicodeString( &nt_name ); RtlFreeUnicodeString( &nt_name );
if (status) if (!set_ntstatus( status )) return INVALID_HANDLE_VALUE;
{
handle = INVALID_HANDLE_VALUE;
SetLastError( RtlNtStatusToDosError(status) );
}
return handle; return handle;
} }
@ -1243,14 +1193,10 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetNamedPipeInfo( HANDLE pipe, LPDWORD flags, LPDW
{ {
FILE_PIPE_LOCAL_INFORMATION info; FILE_PIPE_LOCAL_INFORMATION info;
IO_STATUS_BLOCK iosb; IO_STATUS_BLOCK iosb;
NTSTATUS status;
status = NtQueryInformationFile( pipe, &iosb, &info, sizeof(info), FilePipeLocalInformation ); if (!set_ntstatus( NtQueryInformationFile( pipe, &iosb, &info, sizeof(info), FilePipeLocalInformation )))
if (status)
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE; return FALSE;
}
if (flags) if (flags)
{ {
*flags = (info.NamedPipeEnd & FILE_PIPE_SERVER_END) ? PIPE_SERVER_END : PIPE_CLIENT_END; *flags = (info.NamedPipeEnd & FILE_PIPE_SERVER_END) ? PIPE_SERVER_END : PIPE_CLIENT_END;

View File

@ -74,7 +74,6 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateRemoteThreadEx( HANDLE process, SECURITY_A
{ {
HANDLE handle; HANDLE handle;
CLIENT_ID client_id; CLIENT_ID client_id;
NTSTATUS status;
SIZE_T stack_reserve = 0, stack_commit = 0; SIZE_T stack_reserve = 0, stack_commit = 0;
if (attributes) FIXME("thread attributes ignored\n"); if (attributes) FIXME("thread attributes ignored\n");
@ -82,11 +81,11 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateRemoteThreadEx( HANDLE process, SECURITY_A
if (flags & STACK_SIZE_PARAM_IS_A_RESERVATION) stack_reserve = stack; if (flags & STACK_SIZE_PARAM_IS_A_RESERVATION) stack_reserve = stack;
else stack_commit = stack; else stack_commit = stack;
status = RtlCreateUserThread( process, sa ? sa->lpSecurityDescriptor : NULL, TRUE, if (!set_ntstatus( RtlCreateUserThread( process, sa ? sa->lpSecurityDescriptor : NULL, TRUE,
NULL, stack_reserve, stack_commit, NULL, stack_reserve, stack_commit,
(PRTL_THREAD_START_ROUTINE)start, param, &handle, &client_id ); (PRTL_THREAD_START_ROUTINE)start, param, &handle, &client_id )))
if (status == STATUS_SUCCESS) return 0;
{
if (id) *id = HandleToULong( client_id.UniqueThread ); if (id) *id = HandleToULong( client_id.UniqueThread );
if (sa && sa->nLength >= sizeof(*sa) && sa->bInheritHandle) if (sa && sa->nLength >= sizeof(*sa) && sa->bInheritHandle)
SetHandleInformation( handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT ); SetHandleInformation( handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT );
@ -100,12 +99,6 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateRemoteThreadEx( HANDLE process, SECURITY_A
handle = 0; handle = 0;
} }
} }
}
else
{
SetLastError( RtlNtStatusToDosError(status) );
handle = 0;
}
return handle; return handle;
} }
@ -292,12 +285,10 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetThreadTimes( HANDLE thread, LPFILETIME creation
LPFILETIME kerneltime, LPFILETIME usertime ) LPFILETIME kerneltime, LPFILETIME usertime )
{ {
KERNEL_USER_TIMES times; KERNEL_USER_TIMES times;
NTSTATUS status = NtQueryInformationThread( thread, ThreadTimes, &times, sizeof(times), NULL);
if (status) if (!set_ntstatus( NtQueryInformationThread( thread, ThreadTimes, &times, sizeof(times), NULL )))
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE; return FALSE;
}
if (creationtime) if (creationtime)
{ {
creationtime->dwLowDateTime = times.CreateTime.u.LowPart; creationtime->dwLowDateTime = times.CreateTime.u.LowPart;
@ -857,7 +848,6 @@ LPVOID WINAPI DECLSPEC_HOTPATCH CreateFiberEx( SIZE_T stack_commit, SIZE_T stack
{ {
struct fiber_data *fiber; struct fiber_data *fiber;
INITIAL_TEB stack; INITIAL_TEB stack;
NTSTATUS status;
if (!(fiber = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*fiber) ))) if (!(fiber = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*fiber) )))
{ {
@ -865,9 +855,8 @@ LPVOID WINAPI DECLSPEC_HOTPATCH CreateFiberEx( SIZE_T stack_commit, SIZE_T stack
return NULL; return NULL;
} }
if ((status = RtlCreateUserStack( stack_commit, stack_reserve, 0, 1, 1, &stack ))) if (!set_ntstatus( RtlCreateUserStack( stack_commit, stack_reserve, 0, 1, 1, &stack )))
{ {
SetLastError( RtlNtStatusToDosError(status) );
HeapFree( GetProcessHeap(), 0, fiber ); HeapFree( GetProcessHeap(), 0, fiber );
return NULL; return NULL;
} }