Commit 14fbecee authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Add set_ntstatus() helper.

parent aaecc404
......@@ -51,12 +51,10 @@ static RTL_ATOM_TABLE get_local_table(DWORD entries)
if (!local_table)
{
NTSTATUS status;
RTL_ATOM_TABLE table = NULL;
if ((status = RtlCreateAtomTable( entries, &table )))
SetLastError( RtlNtStatusToDosError( status ) );
else if (InterlockedCompareExchangePointer((void*)&local_table, table, NULL) != NULL)
if (!set_ntstatus( RtlCreateAtomTable( entries, &table ))) return NULL;
if (InterlockedCompareExchangePointer((void*)&local_table, table, NULL) != NULL)
RtlDestroyAtomTable( table );
}
......@@ -118,15 +116,7 @@ ATOM WINAPI GlobalAddAtomA( LPCSTR str /* [in] String to add */ )
WCHAR buffer[MAX_ATOM_LEN];
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN );
if (!len) SetLastError( ERROR_INVALID_PARAMETER );
else
{
NTSTATUS status = NtAddAtom( buffer, len * sizeof(WCHAR), &atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
atom = 0;
}
}
else if (!set_ntstatus( NtAddAtom( buffer, len * sizeof(WCHAR), &atom ))) atom = 0;
}
}
__EXCEPT_PAGE_FAULT
......@@ -163,12 +153,7 @@ ATOM WINAPI AddAtomA( LPCSTR str /* [in] String to add */ )
if (!len) SetLastError( ERROR_INVALID_PARAMETER );
else if ((table = get_local_table( 0 )))
{
NTSTATUS status = RtlAddAtomToAtomTable( table, buffer, &atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
atom = 0;
}
if (!set_ntstatus( RtlAddAtomToAtomTable( table, buffer, &atom ))) return 0;
}
}
return atom;
......@@ -182,13 +167,10 @@ ATOM WINAPI AddAtomA( LPCSTR str /* [in] String to add */ )
ATOM WINAPI GlobalAddAtomW( LPCWSTR str )
{
ATOM atom = 0;
NTSTATUS status;
if (!check_integral_atom( str, &atom ) &&
(status = NtAddAtom( str, strlenW( str ) * sizeof(WCHAR), &atom )))
if (!check_integral_atom( str, &atom ))
{
SetLastError( RtlNtStatusToDosError( status ) );
atom = 0;
if (!set_ntstatus( NtAddAtom( str, strlenW( str ) * sizeof(WCHAR), &atom ))) return 0;
}
return atom;
}
......@@ -206,12 +188,7 @@ ATOM WINAPI AddAtomW( LPCWSTR str )
if (!check_integral_atom( str, &atom ) && (table = get_local_table( 0 )))
{
NTSTATUS status = RtlAddAtomToAtomTable( table, str, &atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
atom = 0;
}
if (!set_ntstatus( RtlAddAtomToAtomTable( table, str, &atom ))) return 0;
}
return atom;
}
......@@ -231,12 +208,7 @@ ATOM WINAPI GlobalDeleteAtom( ATOM atom /* [in] Atom to delete */ )
{
if (atom >= MAXINTATOM)
{
NTSTATUS status = NtDeleteAtom( atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
return atom;
}
if (!set_ntstatus( NtDeleteAtom( atom ))) return atom;
}
return 0;
}
......@@ -254,18 +226,12 @@ ATOM WINAPI GlobalDeleteAtom( ATOM atom /* [in] Atom to delete */ )
*/
ATOM WINAPI DeleteAtom( ATOM atom /* [in] Atom to delete */ )
{
NTSTATUS status;
RTL_ATOM_TABLE table;
if (atom >= MAXINTATOM)
{
if (!(table = get_local_table( 0 ))) return atom;
status = RtlDeleteAtomFromAtomTable( table, atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
return atom;
}
if (!set_ntstatus( RtlDeleteAtomFromAtomTable( table, atom ))) return atom;
}
return 0;
}
......@@ -290,15 +256,7 @@ ATOM WINAPI GlobalFindAtomA( LPCSTR str /* [in] Pointer to string to search for
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN );
if (!len) SetLastError( ERROR_INVALID_PARAMETER );
else
{
NTSTATUS status = NtFindAtom( buffer, len * sizeof(WCHAR), &atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
atom = 0;
}
}
else if (!set_ntstatus( NtFindAtom( buffer, len * sizeof(WCHAR), &atom ))) return 0;
}
return atom;
}
......@@ -326,12 +284,7 @@ ATOM WINAPI FindAtomA( LPCSTR str /* [in] Pointer to string to find */ )
if (!len) SetLastError( ERROR_INVALID_PARAMETER );
else if ((table = get_local_table( 0 )))
{
NTSTATUS status = RtlLookupAtomInAtomTable( table, buffer, &atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
atom = 0;
}
if (!set_ntstatus( RtlLookupAtomInAtomTable( table, buffer, &atom ))) return 0;
}
}
return atom;
......@@ -349,12 +302,7 @@ ATOM WINAPI GlobalFindAtomW( LPCWSTR str )
if (!check_integral_atom( str, &atom ))
{
NTSTATUS status = NtFindAtom( str, strlenW( str ) * sizeof(WCHAR), &atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
atom = 0;
}
if (!set_ntstatus( NtFindAtom( str, strlenW( str ) * sizeof(WCHAR), &atom ))) return 0;
}
return atom;
}
......@@ -368,17 +316,11 @@ ATOM WINAPI GlobalFindAtomW( LPCWSTR str )
ATOM WINAPI FindAtomW( LPCWSTR str )
{
ATOM atom = 0;
NTSTATUS status;
RTL_ATOM_TABLE table;
if ((table = get_local_table( 0 )))
{
status = RtlLookupAtomInAtomTable( table, str, &atom );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
atom = 0;
}
if (!set_ntstatus( RtlLookupAtomInAtomTable( table, str, &atom ))) return 0;
}
return atom;
}
......@@ -466,7 +408,6 @@ UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
char ptr[sizeof(ATOM_BASIC_INFORMATION) + MAX_ATOM_LEN * sizeof(WCHAR)];
ATOM_BASIC_INFORMATION* abi = (ATOM_BASIC_INFORMATION*)ptr;
ULONG ptr_size = sizeof(ATOM_BASIC_INFORMATION) + MAX_ATOM_LEN * sizeof(WCHAR);
NTSTATUS status;
UINT length = 0;
if (count <= 0)
......@@ -474,22 +415,20 @@ UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
SetLastError( ERROR_MORE_DATA );
return 0;
}
status = NtQueryInformationAtom( atom, AtomBasicInformation, (void*)ptr, ptr_size, NULL );
if (status) SetLastError( RtlNtStatusToDosError( status ) );
else
if (!set_ntstatus( NtQueryInformationAtom( atom, AtomBasicInformation, (void*)ptr, ptr_size, NULL )))
return 0;
length = min( abi->NameLength / sizeof(WCHAR), count);
memcpy( buffer, abi->Name, length * sizeof(WCHAR) );
/* yes, the string will not be null terminated if the passed buffer
* is one WCHAR too small (and it's not an error)
*/
if (length < abi->NameLength / sizeof(WCHAR))
{
length = min( abi->NameLength / sizeof(WCHAR), count);
memcpy( buffer, abi->Name, length * sizeof(WCHAR) );
/* yes, the string will not be null terminated if the passed buffer
* is one WCHAR too small (and it's not an error)
*/
if (length < abi->NameLength / sizeof(WCHAR))
{
SetLastError( ERROR_MORE_DATA );
length = count;
}
else if (length < count) buffer[length] = '\0';
SetLastError( ERROR_MORE_DATA );
length = count;
}
else if (length < count) buffer[length] = '\0';
return length;
}
......@@ -501,7 +440,6 @@ UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
*/
UINT WINAPI GetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
{
NTSTATUS status;
RTL_ATOM_TABLE table;
DWORD length;
WCHAR tmp[MAX_ATOM_LEN + 1];
......@@ -513,12 +451,7 @@ UINT WINAPI GetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
}
if (!(table = get_local_table( 0 ))) return 0;
length = sizeof(tmp);
status = RtlQueryAtomInAtomTable( table, atom, NULL, NULL, tmp, &length );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
return 0;
}
if (!set_ntstatus( RtlQueryAtomInAtomTable( table, atom, NULL, NULL, tmp, &length ))) return 0;
length = min(length, (count - 1) * sizeof(WCHAR));
if (length) memcpy(buffer, tmp, length);
else SetLastError( ERROR_INSUFFICIENT_BUFFER );
......
......@@ -57,16 +57,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(reg);
VOID WINAPI GetSystemInfo(
LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
{
NTSTATUS nts;
SYSTEM_CPU_INFORMATION sci;
TRACE("si=0x%p\n", si);
if ((nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
{
SetLastError(RtlNtStatusToDosError(nts));
return;
}
if (!set_ntstatus( NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL ))) return;
si->u.s.wProcessorArchitecture = sci.Architecture;
si->u.s.wReserved = 0;
......
......@@ -75,16 +75,11 @@ static LPWSTR load_message( HMODULE module, UINT id, WORD lang )
{
const MESSAGE_RESOURCE_ENTRY *mre;
WCHAR *buffer;
NTSTATUS status;
TRACE("module = %p, id = %08x\n", module, id );
if (!module) module = GetModuleHandleW( NULL );
if ((status = RtlFindMessage( module, RT_MESSAGETABLE, lang, id, &mre )) != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return NULL;
}
if (!set_ntstatus( RtlFindMessage( module, RT_MESSAGETABLE, lang, id, &mre ))) return NULL;
if (mre->Flags & MESSAGE_RESOURCE_UNICODE)
{
......
......@@ -44,6 +44,12 @@ static inline obj_handle_t console_handle_unmap(HANDLE h)
return wine_server_obj_handle( h != INVALID_HANDLE_VALUE ? (HANDLE)((UINT_PTR)h ^ 3) : INVALID_HANDLE_VALUE );
}
static inline BOOL set_ntstatus( NTSTATUS status )
{
if (status) SetLastError( RtlNtStatusToDosError( status ));
return !status;
}
/* Some Wine specific values for Console inheritance (params->ConsoleHandle) */
#define KERNEL32_CONSOLE_ALLOC ((HANDLE)1)
#define KERNEL32_CONSOLE_SHELL ((HANDLE)2)
......
......@@ -1858,9 +1858,7 @@ BOOL WINAPI SetLocaleInfoW( LCID lcid, LCTYPE lctype, LPCWSTR data )
}
NtClose( hkey );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
return set_ntstatus( status );
}
......
......@@ -356,7 +356,6 @@ BOOL WINAPI GetBinaryTypeW( LPCWSTR name, LPDWORD type )
BOOL WINAPI GetBinaryTypeA( LPCSTR lpApplicationName, LPDWORD lpBinaryType )
{
ANSI_STRING app_nameA;
NTSTATUS status;
TRACE("%s\n", debugstr_a(lpApplicationName));
......@@ -366,13 +365,10 @@ BOOL WINAPI GetBinaryTypeA( LPCSTR lpApplicationName, LPDWORD lpBinaryType )
return FALSE;
RtlInitAnsiString(&app_nameA, lpApplicationName);
status = RtlAnsiStringToUnicodeString(&NtCurrentTeb()->StaticUnicodeString,
&app_nameA, FALSE);
if (!status)
return GetBinaryTypeW(NtCurrentTeb()->StaticUnicodeString.Buffer, lpBinaryType);
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
if (!set_ntstatus( RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
&app_nameA, FALSE )))
return FALSE;
return GetBinaryTypeW(NtCurrentTeb()->StaticUnicodeString.Buffer, lpBinaryType);
}
/***********************************************************************
......@@ -886,9 +882,6 @@ HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryW(LPCWSTR libnameW)
*/
BOOL WINAPI DECLSPEC_HOTPATCH FreeLibrary(HINSTANCE hLibModule)
{
BOOL retv = FALSE;
NTSTATUS nts;
if (!hLibModule)
{
SetLastError( ERROR_INVALID_HANDLE );
......@@ -923,10 +916,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeLibrary(HINSTANCE hLibModule)
return UnmapViewOfFile( ptr );
}
if ((nts = LdrUnloadDll( hLibModule )) == STATUS_SUCCESS) retv = TRUE;
else SetLastError( RtlNtStatusToDosError( nts ) );
return retv;
return set_ntstatus( LdrUnloadDll( hLibModule ));
}
/***********************************************************************
......@@ -944,7 +934,6 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeLibrary(HINSTANCE hLibModule)
*/
FARPROC get_proc_address( HMODULE hModule, LPCSTR function )
{
NTSTATUS nts;
FARPROC fp;
if (!hModule) hModule = NtCurrentTeb()->Peb->ImageBaseAddress;
......@@ -954,15 +943,12 @@ FARPROC get_proc_address( HMODULE hModule, LPCSTR function )
ANSI_STRING str;
RtlInitAnsiString( &str, function );
nts = LdrGetProcedureAddress( hModule, &str, 0, (void**)&fp );
if (!set_ntstatus( LdrGetProcedureAddress( hModule, &str, 0, (void**)&fp ))) return NULL;
}
else
nts = LdrGetProcedureAddress( hModule, NULL, LOWORD(function), (void**)&fp );
if (nts != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError( nts ) );
fp = NULL;
}
if (!set_ntstatus( LdrGetProcedureAddress( hModule, NULL, LOWORD(function), (void**)&fp )))
return NULL;
return fp;
}
......
......@@ -1136,21 +1136,18 @@ BOOL WINAPI RemoveDirectoryW( LPCWSTR path )
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
status = NtOpenFile( &handle, DELETE | SYNCHRONIZE, &attr, &io,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
if (status != STATUS_SUCCESS)
if (!set_ntstatus( NtOpenFile( &handle, DELETE | SYNCHRONIZE, &attr, &io,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT )))
{
SetLastError( RtlNtStatusToDosError(status) );
RtlFreeUnicodeString( &nt_name );
return FALSE;
}
status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, FALSE );
RtlFreeUnicodeString( &nt_name );
if (status != STATUS_SUCCESS)
if (!set_ntstatus( status ))
{
SetLastError( RtlNtStatusToDosError(status) );
NtClose( handle );
return FALSE;
}
......@@ -1249,9 +1246,7 @@ UINT WINAPI GetSystemWow64DirectoryA( LPSTR path, UINT count )
*/
BOOLEAN WINAPI Wow64EnableWow64FsRedirection( BOOLEAN enable )
{
NTSTATUS status = RtlWow64EnableFsRedirection( enable );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
return set_ntstatus( RtlWow64EnableFsRedirection( enable ));
}
......@@ -1289,16 +1284,10 @@ WCHAR * CDECL wine_get_dos_file_name( LPCSTR str )
{
UNICODE_STRING nt_name;
ANSI_STRING unix_name;
NTSTATUS status;
DWORD len;
RtlInitAnsiString( &unix_name, str );
status = wine_unix_to_nt_file_name( &unix_name, &nt_name );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
return NULL;
}
if (!set_ntstatus( wine_unix_to_nt_file_name( &unix_name, &nt_name ))) return NULL;
if (nt_name.Buffer[5] == ':')
{
/* get rid of the \??\ prefix */
......
......@@ -3151,18 +3151,12 @@ void WINAPI ExitProcess( DWORD status )
*/
BOOL WINAPI GetExitCodeProcess( HANDLE hProcess, LPDWORD lpExitCode )
{
NTSTATUS status;
PROCESS_BASIC_INFORMATION pbi;
status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi,
sizeof(pbi), NULL);
if (status == STATUS_SUCCESS)
{
if (lpExitCode) *lpExitCode = pbi.ExitStatus;
return TRUE;
}
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
if (!set_ntstatus( NtQueryInformationProcess( hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), NULL )))
return FALSE;
if (lpExitCode) *lpExitCode = pbi.ExitStatus;
return TRUE;
}
......@@ -3250,16 +3244,8 @@ HANDLE WINAPI CreateSocketHandle(void)
*/
BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD_PTR affmask )
{
NTSTATUS status;
status = NtSetInformationProcess(hProcess, ProcessAffinityMask,
&affmask, sizeof(DWORD_PTR));
if (status)
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
return TRUE;
return set_ntstatus( NtSetInformationProcess( hProcess, ProcessAffinityMask,
&affmask, sizeof(DWORD_PTR) ));
}
......@@ -3268,24 +3254,21 @@ BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD_PTR affmask )
*/
BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess, PDWORD_PTR process_mask, PDWORD_PTR system_mask )
{
NTSTATUS status = STATUS_SUCCESS;
if (process_mask)
{
if ((status = NtQueryInformationProcess( hProcess, ProcessAffinityMask,
process_mask, sizeof(*process_mask), NULL )))
SetLastError( RtlNtStatusToDosError(status) );
if (!set_ntstatus( NtQueryInformationProcess( hProcess, ProcessAffinityMask,
process_mask, sizeof(*process_mask), NULL )))
return FALSE;
}
if (system_mask && status == STATUS_SUCCESS)
if (system_mask)
{
SYSTEM_BASIC_INFORMATION info;
if ((status = NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )))
SetLastError( RtlNtStatusToDosError(status) );
else
*system_mask = info.ActiveProcessorsAffinityMask;
if (!set_ntstatus( NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )))
return FALSE;
*system_mask = info.ActiveProcessorsAffinityMask;
}
return !status;
return TRUE;
}
......@@ -3385,12 +3368,7 @@ BOOL WINAPI GetProcessWorkingSetSize(HANDLE process, SIZE_T *minset, SIZE_T *max
*/
BOOL WINAPI GetProcessIoCounters(HANDLE hProcess, PIO_COUNTERS ioc)
{
NTSTATUS status;
status = NtQueryInformationProcess(hProcess, ProcessIoCounters,
ioc, sizeof(*ioc), NULL);
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
return set_ntstatus( NtQueryInformationProcess(hProcess, ProcessIoCounters, ioc, sizeof(*ioc), NULL ));
}
/******************************************************************
......@@ -3492,8 +3470,7 @@ BOOL WINAPI QueryFullProcessImageNameW(HANDLE hProcess, DWORD dwFlags, LPWSTR lp
cleanup:
HeapFree(GetProcessHeap(), 0, dynamic_buffer);
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
return set_ntstatus( status );
}
/***********************************************************************
......@@ -3532,10 +3509,9 @@ BOOL WINAPI K32EnumProcesses(DWORD *lpdwProcessIDs, DWORD cb, DWORD *lpcbUsed)
status = NtQuerySystemInformation(SystemProcessInformation, buf, size, NULL);
} while(status == STATUS_INFO_LENGTH_MISMATCH);
if (status != STATUS_SUCCESS)
if (!set_ntstatus( status ))
{
HeapFree(GetProcessHeap(), 0, buf);
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}
......@@ -3561,18 +3537,9 @@ BOOL WINAPI K32EnumProcesses(DWORD *lpdwProcessIDs, DWORD cb, DWORD *lpcbUsed)
*/
BOOL WINAPI K32QueryWorkingSet( HANDLE process, LPVOID buffer, DWORD size )
{
NTSTATUS status;
TRACE( "(%p, %p, %d)\n", process, buffer, size );
status = NtQueryVirtualMemory( process, NULL, MemoryWorkingSetList, buffer, size, NULL );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
return FALSE;
}
return TRUE;
return set_ntstatus( NtQueryVirtualMemory( process, NULL, MemoryWorkingSetList, buffer, size, NULL ));
}
/***********************************************************************
......@@ -3580,18 +3547,9 @@ BOOL WINAPI K32QueryWorkingSet( HANDLE process, LPVOID buffer, DWORD size )
*/
BOOL WINAPI K32QueryWorkingSetEx( HANDLE process, LPVOID buffer, DWORD size )
{
NTSTATUS status;
TRACE( "(%p, %p, %d)\n", process, buffer, size );
status = NtQueryVirtualMemory( process, NULL, MemoryWorkingSetList, buffer, size, NULL );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
return FALSE;
}
return TRUE;
return set_ntstatus( NtQueryVirtualMemory( process, NULL, MemoryWorkingSetList, buffer, size, NULL ));
}
/***********************************************************************
......@@ -3603,7 +3561,6 @@ BOOL WINAPI K32QueryWorkingSetEx( HANDLE process, LPVOID buffer, DWORD size )
BOOL WINAPI K32GetProcessMemoryInfo(HANDLE process,
PPROCESS_MEMORY_COUNTERS pmc, DWORD cb)
{
NTSTATUS status;
VM_COUNTERS vmc;
if (cb < sizeof(PROCESS_MEMORY_COUNTERS))
......@@ -3612,14 +3569,8 @@ BOOL WINAPI K32GetProcessMemoryInfo(HANDLE process,
return FALSE;
}
status = NtQueryInformationProcess(process, ProcessVmCounters,
&vmc, sizeof(vmc), NULL);
if (status)
{
SetLastError(RtlNtStatusToDosError(status));
if (!set_ntstatus( NtQueryInformationProcess( process, ProcessVmCounters, &vmc, sizeof(vmc), NULL )))
return FALSE;
}
pmc->cb = sizeof(PROCESS_MEMORY_COUNTERS);
pmc->PageFaultCount = vmc.PageFaultCount;
......@@ -3848,31 +3799,25 @@ BOOL WINAPI GetNumaProximityNode(ULONG proximity_id, PUCHAR node_number)
*/
BOOL WINAPI GetProcessDEPPolicy(HANDLE process, LPDWORD flags, PBOOL permanent)
{
NTSTATUS status;
ULONG dep_flags;
TRACE("(%p %p %p)\n", process, flags, permanent);
status = NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
&dep_flags, sizeof(dep_flags), NULL );
if (!status)
{
if (flags)
{
*flags = 0;
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE)
*flags |= PROCESS_DEP_ENABLE;
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION)
*flags |= PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION;
}
if (permanent)
*permanent = (dep_flags & MEM_EXECUTE_OPTION_PERMANENT) != 0;
if (!set_ntstatus( NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
&dep_flags, sizeof(dep_flags), NULL )))
return FALSE;
if (flags)
{
*flags = 0;
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE)
*flags |= PROCESS_DEP_ENABLE;
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION)
*flags |= PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION;
}
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
if (permanent) *permanent = (dep_flags & MEM_EXECUTE_OPTION_PERMANENT) != 0;
return TRUE;
}
/**********************************************************************
......
......@@ -348,27 +348,14 @@ static BOOL TIME_GetSpecificTimeZoneKey( const WCHAR *key_name, HANDLE *result )
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
RtlInitUnicodeString( &nameW, Time_ZonesW );
status = NtOpenKey( &time_zones_key, KEY_READ, &attr );
if (status)
{
WARN("Unable to open the time zones key\n");
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
if (!set_ntstatus( NtOpenKey( &time_zones_key, KEY_READ, &attr ))) return FALSE;
attr.RootDirectory = time_zones_key;
RtlInitUnicodeString( &nameW, key_name );
status = NtOpenKey( result, KEY_READ, &attr );
NtClose( time_zones_key );
if (status)
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
return TRUE;
return set_ntstatus( status );
}
static BOOL reg_query_value(HKEY hkey, LPCWSTR name, DWORD type, void *data, DWORD count)
......@@ -376,19 +363,15 @@ static BOOL reg_query_value(HKEY hkey, LPCWSTR name, DWORD type, void *data, DWO
UNICODE_STRING nameW;
char buf[256];
KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buf;
NTSTATUS status;
if (count > sizeof(buf) - sizeof(KEY_VALUE_PARTIAL_INFORMATION))
return FALSE;
RtlInitUnicodeString(&nameW, name);
if ((status = NtQueryValueKey(hkey, &nameW, KeyValuePartialInformation,
buf, sizeof(buf), &count)))
{
SetLastError( RtlNtStatusToDosError(status) );
if (!set_ntstatus( NtQueryValueKey(hkey, &nameW, KeyValuePartialInformation,
buf, sizeof(buf), &count)))
return FALSE;
}
if (info->Type != type)
{
......@@ -625,13 +608,8 @@ BOOL WINAPI GetTimeZoneInformationForYear( USHORT wYear,
*/
BOOL WINAPI SetTimeZoneInformation( const TIME_ZONE_INFORMATION *tzinfo )
{
NTSTATUS status;
TRACE("(%p)\n", tzinfo);
status = RtlSetTimeZoneInformation( (const RTL_TIME_ZONE_INFORMATION *)tzinfo );
if ( status != STATUS_SUCCESS )
SetLastError( RtlNtStatusToDosError(status) );
return !status;
return set_ntstatus( RtlSetTimeZoneInformation( (const RTL_TIME_ZONE_INFORMATION *)tzinfo ));
}
/***********************************************************************
......@@ -1188,18 +1166,13 @@ BOOL WINAPI GetSystemTimes(LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFIL
LARGE_INTEGER idle_time, kernel_time, user_time;
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi;
SYSTEM_BASIC_INFORMATION sbi;
NTSTATUS status;
ULONG ret_size;
int i;
TRACE("(%p,%p,%p)\n", lpIdleTime, lpKernelTime, lpUserTime);
status = NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), &ret_size );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
if (!set_ntstatus( NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), &ret_size )))
return FALSE;
}
sppi = HeapAlloc( GetProcessHeap(), 0,
sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * sbi.NumberOfProcessors);
......@@ -1209,12 +1182,10 @@ BOOL WINAPI GetSystemTimes(LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFIL
return FALSE;
}
status = NtQuerySystemInformation( SystemProcessorPerformanceInformation, sppi, sizeof(*sppi) * sbi.NumberOfProcessors,
&ret_size );
if (status != STATUS_SUCCESS)
if (!set_ntstatus( NtQuerySystemInformation( SystemProcessorPerformanceInformation, sppi,
sizeof(*sppi) * sbi.NumberOfProcessors, &ret_size )))
{
HeapFree( GetProcessHeap(), 0, sppi );
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
......@@ -1253,16 +1224,11 @@ BOOL WINAPI GetSystemTimes(LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFIL
*/
DWORD WINAPI GetDynamicTimeZoneInformation(DYNAMIC_TIME_ZONE_INFORMATION *tzinfo)
{
NTSTATUS status;
HANDLE time_zone_key;
TRACE("(%p)\n", tzinfo);
status = RtlQueryDynamicTimeZoneInformation( (RTL_DYNAMIC_TIME_ZONE_INFORMATION*)tzinfo );
if ( status != STATUS_SUCCESS )
{
SetLastError( RtlNtStatusToDosError(status) );
if (!set_ntstatus( RtlQueryDynamicTimeZoneInformation( (RTL_DYNAMIC_TIME_ZONE_INFORMATION*)tzinfo )))
return TIME_ZONE_ID_INVALID;
}
if (!TIME_GetSpecificTimeZoneKey( tzinfo->TimeZoneKeyName, &time_zone_key ))
return TIME_ZONE_ID_INVALID;
......
......@@ -144,12 +144,7 @@ static BOOL open_device_root( LPCWSTR root, HANDLE *handle )
status = NtOpenFile( handle, SYNCHRONIZE, &attr, &io, 0,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
RtlFreeUnicodeString( &nt_name );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
return TRUE;
return set_ntstatus( status );
}
/* query the type of a drive from the mount manager */
......@@ -781,19 +776,14 @@ BOOL WINAPI GetVolumeInformationW( LPCWSTR root, LPWSTR label, DWORD label_len,
/* we couldn't open the device, fallback to default strategy */
status = NtOpenFile( &handle, SYNCHRONIZE, &attr, &io, 0, FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
if (!set_ntstatus( NtOpenFile( &handle, SYNCHRONIZE, &attr, &io, 0,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT )))
goto done;
}
status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsDeviceInformation );
NtClose( handle );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
goto done;
}
if (!set_ntstatus( status )) goto done;
if (info.DeviceType == FILE_DEVICE_CD_ROM_FILE_SYSTEM) type = FS_ISO9660;
if (label && label_len) get_filesystem_label( &nt_name, label, label_len );
......@@ -1260,11 +1250,7 @@ DWORD WINAPI QueryDosDeviceW( LPCWSTR devname, LPWSTR target, DWORD bufsize )
strcatW( buffer, devname );
status = read_nt_symlink( buffer, target, bufsize );
HeapFree( GetProcessHeap(), 0, buffer );
if (status)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
if (!set_ntstatus( status )) return 0;
ret = strlenW( target ) + 1;
if (ret < bufsize) target[ret++] = 0; /* add an extra null */
return ret;
......@@ -1536,11 +1522,7 @@ BOOL WINAPI GetDiskFreeSpaceExW( LPCWSTR root, PULARGE_INTEGER avail,
status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsSizeInformation );
NtClose( handle );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
if (!set_ntstatus( status )) return FALSE;
units = info.SectorsPerAllocationUnit * info.BytesPerSector;
if (total) total->QuadPart = info.TotalAllocationUnits.QuadPart * units;
......@@ -1586,11 +1568,7 @@ BOOL WINAPI GetDiskFreeSpaceW( LPCWSTR root, LPDWORD cluster_sectors,
status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsSizeInformation );
NtClose( handle );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
if (!set_ntstatus( status )) return FALSE;
units = info.SectorsPerAllocationUnit * info.BytesPerSector;
......@@ -1796,10 +1774,7 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu
cleanup:
HeapFree( GetProcessHeap(), 0, volumenameW );
if (status != STATUS_SUCCESS)
SetLastError( RtlNtStatusToDosError(status) );
return (status == STATUS_SUCCESS);
return set_ntstatus( status );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment