Skip to content

Commit

Permalink
winapi: Run clang format on files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryzee119 committed Jun 15, 2024
1 parent 0b4b1d2 commit 2a2392a
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 109 deletions.
2 changes: 1 addition & 1 deletion lib/winapi/badptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BOOL IsBadWritePtr (LPVOID lp, UINT_PTR ucb)
// The Microsoft implementation then probes each page.
// For Xbox, this is not suitable because `lp` potentially points at MMIO.

//FIXME: Walk allocations in region with NtQueryVirtualMemory and check write permission?
// FIXME: Walk allocations in region with NtQueryVirtualMemory and check write permission?

// We disallow all access for now, because memory is potentially unsafe
return TRUE;
Expand Down
2 changes: 1 addition & 1 deletion lib/winapi/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ void WINAPI OutputDebugStringA (LPCTSTR lpOutputString)

__asm__ __volatile__("mov $1, %%eax\n" // $1 = BREAKPOINT_PRINT
"int $0x2D\n"
"int $3\n": :"c" (&s));
"int $3\n" : : "c"(&s));
}
3 changes: 1 addition & 2 deletions lib/winapi/debugapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include <windef.h>

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

BOOL IsDebuggerPresent (VOID);
Expand Down
3 changes: 1 addition & 2 deletions lib/winapi/errhandlingapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include <winbase.h>

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

VOID RaiseException (DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments, const ULONG_PTR *lpArguments);
Expand Down
7 changes: 4 additions & 3 deletions lib/winapi/fiber.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static __cdecl VOID fls_init (VOID)
InitializeListHead(&fls_nodes_list);
}
#pragma comment(linker, "/include:___fls_init_p")
__attribute__((section(".CRT$XXT"))) void (__cdecl *const __fls_init_p)(void) = fls_init;
__attribute__((section(".CRT$XXT"))) void(__cdecl *const __fls_init_p)(void) = fls_init;

VOID fls_register_thread (VOID)
{
Expand Down Expand Up @@ -70,11 +70,12 @@ DWORD FlsAlloc (PFLS_CALLBACK_FUNCTION lpCallback)
EnterCriticalSection(&fls_lock);

for (size_t i = 0; i < (FLS_MAXIMUM_AVAILABLE / 32); i++) {
if (fls_bitmap[i] == 0xFFFFFFFF) continue;
if (fls_bitmap[i] == 0xFFFFFFFF)
continue;

unsigned int index = __builtin_ctz(~fls_bitmap[i]);
fls_bitmap[i] |= (1 << index);
retval = i*32 + index;
retval = i * 32 + index;
fls_dtors[retval] = lpCallback;
break;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/winapi/fibersapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include <winbase.h>

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

DWORD FlsAlloc (PFLS_CALLBACK_FUNCTION lpCallback);
Expand Down
3 changes: 1 addition & 2 deletions lib/winapi/fileapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include <winnt.h>

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

DWORD GetFileAttributesA (LPCSTR lpFileName);
Expand Down
6 changes: 3 additions & 3 deletions lib/winapi/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ HANDLE CreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
if (status == STATUS_OBJECT_NAME_COLLISION) {
SetLastError(ERROR_FILE_EXISTS);
} else if (status == STATUS_FILE_IS_A_DIRECTORY) {
if (lpFileName[path.Length-1] == '\\') {
if (lpFileName[path.Length - 1] == '\\') {
SetLastError(ERROR_PATH_NOT_FOUND);
} else {
SetLastError(ERROR_ACCESS_DENIED);
Expand Down Expand Up @@ -190,7 +190,7 @@ BOOL WriteFile (HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPD
lpOverlapped->InternalHigh = 0;

status = NtWriteFile(hFile, lpOverlapped->hEvent, NULL, NULL, (PIO_STATUS_BLOCK)&lpOverlapped->Internal,
(PVOID)lpBuffer, nNumberOfBytesToWrite, &overlappedOffset);
(PVOID)lpBuffer, nNumberOfBytesToWrite, &overlappedOffset);

// The write can finish immediately. Handle this case
if (NT_SUCCESS(status) && status != STATUS_PENDING) {
Expand Down Expand Up @@ -341,7 +341,7 @@ BOOL SetFilePointerEx (HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTE
case FILE_CURRENT:
status = NtQueryInformationFile(hFile, &ioStatusBlock, &positionInfo, sizeof(positionInfo), FilePositionInformation);

if(!NT_SUCCESS(status)) {
if (!NT_SUCCESS(status)) {
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}
Expand Down
45 changes: 23 additions & 22 deletions lib/winapi/filemanip.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,26 +356,26 @@ BOOL CopyFileA (LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExi
InitializeObjectAttributes(&objectAttributes, &targetPath, OBJ_CASE_INSENSITIVE, ObDosDevicesDirectory(), NULL);

status = NtCreateFile(
&targetHandle,
FILE_GENERIC_WRITE,
&objectAttributes,
&ioStatusBlock,
&networkOpenInformation.AllocationSize,
networkOpenInformation.FileAttributes,
0,
bFailIfExists ? FILE_CREATE : FILE_SUPERSEDE,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE | FILE_SEQUENTIAL_ONLY);
&targetHandle,
FILE_GENERIC_WRITE,
&objectAttributes,
&ioStatusBlock,
&networkOpenInformation.AllocationSize,
networkOpenInformation.FileAttributes,
0,
bFailIfExists ? FILE_CREATE : FILE_SUPERSEDE,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE | FILE_SEQUENTIAL_ONLY);
if (!NT_SUCCESS(status)) {
NtClose(sourceHandle);
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}

status = NtAllocateVirtualMemory(&readBuffer,
0,
&readBufferRegionSize,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
0,
&readBufferRegionSize,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
NtClose(sourceHandle);
NtClose(targetHandle);
Expand Down Expand Up @@ -418,11 +418,11 @@ BOOL CopyFileA (LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExi
fileBasicInformation.LastWriteTime = networkOpenInformation.LastWriteTime;
fileBasicInformation.FileAttributes = networkOpenInformation.FileAttributes;
status = NtSetInformationFile(
targetHandle,
&ioStatusBlock,
&fileBasicInformation,
sizeof(fileBasicInformation),
FileBasicInformation);
targetHandle,
&ioStatusBlock,
&fileBasicInformation,
sizeof(fileBasicInformation),
FileBasicInformation);
if (!NT_SUCCESS(status)) {
SetLastError(RtlNtStatusToDosError(status));
NtClose(sourceHandle);
Expand All @@ -439,8 +439,8 @@ BOOL CopyFileA (LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExi

status = NtClose(targetHandle);
if (!NT_SUCCESS(status)) {
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}
return TRUE;
}
Expand Down Expand Up @@ -555,7 +555,8 @@ DWORD GetLogicalDrives (VOID)
ANSI_STRING path;
HANDLE handle;
OBJECT_ATTRIBUTES attributes;
struct {
struct
{
OBJECT_DIRECTORY_INFORMATION objDirInfo;
CHAR filenameBuf[2];
} objDirInfoBuf;
Expand Down Expand Up @@ -614,7 +615,7 @@ DWORD GetLogicalDriveStringsA (DWORD nBufferLength, LPSTR lpBuffer)
}

if (nBufferLength == 0 || nBufferLength < requiredBufLength) {
return requiredBufLength+1;
return requiredBufLength + 1;
}

for (int bit = 0; bit < 26; bit++) {
Expand Down
9 changes: 5 additions & 4 deletions lib/winapi/findfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
#include <winerror.h>
#include <fileapi.h>

struct FileInfo {
struct FileInfo
{
FILE_DIRECTORY_INFORMATION dirInfo;
// Reserve path buffer minus the null-terminator and the first byte provided by dirInfo
char filename[MAX_PATH-2];
char filename[MAX_PATH - 2];
};

static void dirtofind (FILE_DIRECTORY_INFORMATION *dirInfo, LPWIN32_FIND_DATAA lpFindFileData)
{
lpFindFileData->dwFileAttributes = dirInfo->FileAttributes;
lpFindFileData->ftCreationTime.dwLowDateTime = dirInfo->CreationTime.LowPart;
lpFindFileData->ftCreationTime.dwHighDateTime = dirInfo->CreationTime.HighPart;
lpFindFileData->ftLastAccessTime.dwLowDateTime = dirInfo->LastAccessTime.LowPart;
lpFindFileData->ftLastAccessTime.dwLowDateTime = dirInfo->LastAccessTime.LowPart;
lpFindFileData->ftLastAccessTime.dwHighDateTime = dirInfo->LastAccessTime.HighPart;
lpFindFileData->ftLastWriteTime.dwLowDateTime = dirInfo->LastWriteTime.LowPart;
lpFindFileData->ftLastWriteTime.dwLowDateTime = dirInfo->LastWriteTime.LowPart;
lpFindFileData->ftLastWriteTime.dwHighDateTime = dirInfo->LastWriteTime.HighPart;
lpFindFileData->nFileSizeHigh = dirInfo->EndOfFile.HighPart;
lpFindFileData->nFileSizeLow = dirInfo->EndOfFile.LowPart;
Expand Down
20 changes: 10 additions & 10 deletions lib/winapi/handleapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#include <winbase.h>
#include <xboxkrnl/xboxkrnl.h>

BOOL CloseHandle (HANDLE hObject)
{
NTSTATUS status = NtClose(hObject);
BOOL CloseHandle (HANDLE hObject)
{
NTSTATUS status = NtClose(hObject);

if (NT_SUCCESS(status)) {
return TRUE;
} else {
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}
}
if (NT_SUCCESS(status)) {
return TRUE;
} else {
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}
}
3 changes: 1 addition & 2 deletions lib/winapi/handleapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include <windef.h>

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

BOOL CloseHandle (HANDLE hObject);
Expand Down
47 changes: 24 additions & 23 deletions lib/winapi/minwinbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <windef.h>
#include <xboxkrnl/ntstatus.h>

typedef struct _FILETIME {
typedef struct _FILETIME
{
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME, *LPFILETIME;
Expand All @@ -35,28 +36,28 @@ typedef struct _SYSTEMTIME
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;

#define STILL_ACTIVE STATUS_PENDING
#define EXCEPTION_ACCESS_VIOLATION STATUS_ACCESS_VIOLATION
#define EXCEPTION_DATATYPE_MISALIGNMENT STATUS_DATATYPE_MISALIGNMENT
#define EXCEPTION_BREAKPOINT STATUS_BREAKPOINT
#define EXCEPTION_SINGLE_STEP STATUS_SINGLE_STEP
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED STATUS_ARRAY_BOUNDS_EXCEEDED
#define EXCEPTION_FLT_DENORMAL_OPERAND STATUS_FLOAT_DENORMAL_OPERAND
#define EXCEPTION_FLT_DIVIDE_BY_ZERO STATUS_FLOAT_DIVIDE_BY_ZERO
#define EXCEPTION_FLT_INEXACT_RESULT STATUS_FLOAT_INEXACT_RESULT
#define EXCEPTION_FLT_INVALID_OPERATION STATUS_FLOAT_INVALID_OPERATION
#define EXCEPTION_FLT_OVERFLOW STATUS_FLOAT_OVERFLOW
#define EXCEPTION_FLT_STACK_CHECK STATUS_FLOAT_STACK_CHECK
#define EXCEPTION_FLT_UNDERFLOW STATUS_FLOAT_UNDERFLOW
#define EXCEPTION_INT_DIVIDE_BY_ZERO STATUS_INTEGER_DIVIDE_BY_ZERO
#define EXCEPTION_INT_OVERFLOW STATUS_INTEGER_OVERFLOW
#define EXCEPTION_PRIV_INSTRUCTION STATUS_PRIVILEGED_INSTRUCTION
#define EXCEPTION_IN_PAGE_ERROR STATUS_IN_PAGE_ERROR
#define EXCEPTION_ILLEGAL_INSTRUCTION STATUS_ILLEGAL_INSTRUCTION
#define STILL_ACTIVE STATUS_PENDING
#define EXCEPTION_ACCESS_VIOLATION STATUS_ACCESS_VIOLATION
#define EXCEPTION_DATATYPE_MISALIGNMENT STATUS_DATATYPE_MISALIGNMENT
#define EXCEPTION_BREAKPOINT STATUS_BREAKPOINT
#define EXCEPTION_SINGLE_STEP STATUS_SINGLE_STEP
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED STATUS_ARRAY_BOUNDS_EXCEEDED
#define EXCEPTION_FLT_DENORMAL_OPERAND STATUS_FLOAT_DENORMAL_OPERAND
#define EXCEPTION_FLT_DIVIDE_BY_ZERO STATUS_FLOAT_DIVIDE_BY_ZERO
#define EXCEPTION_FLT_INEXACT_RESULT STATUS_FLOAT_INEXACT_RESULT
#define EXCEPTION_FLT_INVALID_OPERATION STATUS_FLOAT_INVALID_OPERATION
#define EXCEPTION_FLT_OVERFLOW STATUS_FLOAT_OVERFLOW
#define EXCEPTION_FLT_STACK_CHECK STATUS_FLOAT_STACK_CHECK
#define EXCEPTION_FLT_UNDERFLOW STATUS_FLOAT_UNDERFLOW
#define EXCEPTION_INT_DIVIDE_BY_ZERO STATUS_INTEGER_DIVIDE_BY_ZERO
#define EXCEPTION_INT_OVERFLOW STATUS_INTEGER_OVERFLOW
#define EXCEPTION_PRIV_INSTRUCTION STATUS_PRIVILEGED_INSTRUCTION
#define EXCEPTION_IN_PAGE_ERROR STATUS_IN_PAGE_ERROR
#define EXCEPTION_ILLEGAL_INSTRUCTION STATUS_ILLEGAL_INSTRUCTION
#define EXCEPTION_NONCONTINUABLE_EXCEPTION STATUS_NONCONTINUABLE_EXCEPTION
#define EXCEPTION_STACK_OVERFLOW STATUS_STACK_OVERFLOW
#define EXCEPTION_INVALID_DISPOSITION STATUS_INVALID_DISPOSITION
#define EXCEPTION_GUARD_PAGE STATUS_GUARD_PAGE_VIOLATION
#define EXCEPTION_INVALID_HANDLE STATUS_INVALID_HANDLE

This comment has been minimized.

Copy link
@JayFoxRox

JayFoxRox Jun 15, 2024

Member

I'd prefer if the formatting would preserve this custom alignment (in this instance)

#define EXCEPTION_STACK_OVERFLOW STATUS_STACK_OVERFLOW
#define EXCEPTION_INVALID_DISPOSITION STATUS_INVALID_DISPOSITION
#define EXCEPTION_GUARD_PAGE STATUS_GUARD_PAGE_VIOLATION
#define EXCEPTION_INVALID_HANDLE STATUS_INVALID_HANDLE

#endif
9 changes: 4 additions & 5 deletions lib/winapi/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

typedef unsigned (__stdcall *_beginthreadex_proc_type)(void *);
typedef unsigned(__stdcall *_beginthreadex_proc_type)(void *);

uintptr_t __cdecl _beginthreadex (void *_Security, unsigned _StackSize, _beginthreadex_proc_type _StartAddress, void *_ArgList, unsigned _InitFlag, unsigned *_ThrdAddr);
void __cdecl _endthreadex (unsigned _ReturnCode);
uintptr_t __cdecl _beginthreadex(void *_Security, unsigned _StackSize, _beginthreadex_proc_type _StartAddress, void *_ArgList, unsigned _InitFlag, unsigned *_ThrdAddr);
void __cdecl _endthreadex(unsigned _ReturnCode);

#ifdef __cplusplus
}
Expand Down
5 changes: 2 additions & 3 deletions lib/winapi/processthreadsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
#include <windef.h>

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

typedef DWORD (__stdcall *LPTHREAD_START_ROUTINE) (LPVOID lpThreadParameter);
typedef DWORD(__stdcall *LPTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
HANDLE CreateThread (LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
VOID ExitThread (DWORD dwExitCode);
BOOL GetExitCodeThread (HANDLE hThread, LPDWORD lpExitCode);
Expand Down
3 changes: 1 addition & 2 deletions lib/winapi/shlobj_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include <winnt.h>

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

#ifndef CSIDL_APPDATA
Expand Down
8 changes: 5 additions & 3 deletions lib/winapi/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ BOOL InitOnceComplete (LPINIT_ONCE lpInitOnce, DWORD dwFlags, LPVOID lpContext)
// init done, waiters continue because they were spinning in InitOnceBeginInitialize
return TRUE;
case INITONCE_ASYNC_IN_PROGRESS:
if(!(dwFlags & INIT_ONCE_ASYNC)) {
if (!(dwFlags & INIT_ONCE_ASYNC)) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
Expand Down Expand Up @@ -453,7 +453,8 @@ DWORD WaitForSingleObjectEx (HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertab
while (true) {
NTSTATUS status = NtWaitForSingleObjectEx(hHandle, UserMode, bAlertable, &duration);

if (status == STATUS_ALERTED) continue;
if (status == STATUS_ALERTED)
continue;

if (!NT_SUCCESS(status)) {
SetLastError(RtlNtStatusToDosError(status));
Expand All @@ -477,7 +478,8 @@ DWORD WaitForMultipleObjectsEx (DWORD nCount, const HANDLE *lpHandles, BOOL bWai
while (true) {
NTSTATUS status = NtWaitForMultipleObjectsEx(nCount, lpHandles, bWaitAll ? WaitAll : WaitAny, UserMode, bAlertable, &duration);

if (status == STATUS_ALERTED) continue;
if (status == STATUS_ALERTED)
continue;

This comment has been minimized.

Copy link
@JayFoxRox

JayFoxRox Jun 15, 2024

Member

Condition without scope can quickly lead to bugs, if someone were to comment out the continue (as the condition would still affect the next statement in line 484). I usually prefer to always have the scope (or at least keep statement on the same line).

(Same thing also in lib/winapi/fiber.c and possibly elsewhere)


if (!NT_SUCCESS(status)) {
SetLastError(RtlNtStatusToDosError(status));
Expand Down
1 change: 0 additions & 1 deletion lib/winapi/synchapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ VOID WakeAllConditionVariable (PCONDITION_VARIABLE ConditionVariable);
// UninitializeConditionVariable is an nxdk extension to free associated system resources
VOID UninitializeConditionVariable (PCONDITION_VARIABLE ConditionVariable);


void AcquireSRWLockExclusive (PSRWLOCK SRWLock);
void AcquireSRWLockShared (PSRWLOCK SRWLock);
void InitializeSRWLock (PSRWLOCK SRWLock);
Expand Down
Loading

0 comments on commit 2a2392a

Please sign in to comment.