Add win32 apis

This commit is contained in:
A2va 2025-03-26 13:57:10 +01:00
parent afc986f741
commit 6330b6826e
7 changed files with 87 additions and 0 deletions

View file

@ -381,6 +381,9 @@
#define _FILE_STREAM_INFORMATION NtFileStreamInformation
#define FILE_STREAM_INFORMATION struct NtFileStreamInformation
#define PFILE_STREAM_INFORMATION struct NtFileStreamInformation*
#define _FILE_NOTIFY_INFORMATION NtFileNotifyInformation
#define FILE_NOTIFY_INFORMATION struct NtFileNotifyInformation
#define PFILE_NOTIFY_INFORMATION struct NtFileNotifyInformation*
#define _KERNEL_USER_TIMES NtKernelUserTimes
#define KERNEL_USER_TIMES struct NtKernelUserTimes
#define PKERNEL_USER_TIMES struct NtKernelUserTimes*
@ -1361,6 +1364,9 @@
#define WSAEVENT HANDLE
#define GROUP uint32_t
#define _OVERLAPPED NtOverlapped
#define OVERLAPPED struct NtOverlapped
#define LOVERLAPPED struct NtOverlapped*
#define WSAOVERLAPPED OVERLAPPED
#define INVALID_SOCKET -1ULL
#define SOCKET_ERROR -1

39
libc/nt/base.h Normal file
View file

@ -0,0 +1,39 @@
#ifndef COSMOPOLITAN_LIBC_NT_BASE_H_
#define COSMOPOLITAN_LIBC_NT_BASE_H_
#include "struct/overlapped.h"
/* ░░░░
cosmopolitan § new technology » string
*/
COSMOPOLITAN_C_START_
typedef void (*NtOverlappedCompletionRoutine)(
uint32_t dwErrorCode, uint32_t dwNumberOfBytesTransfered,
struct NtOverlapped *lpOverlapped);
uint32_t FormatMessageW(uint32_t dwFlags, const void* lpSource, uint32_t dwMessageId, uint32_t dwLanguageId, char16_t *lpBuffer, uint32_t nSize, va_list *Arguments);
bool32 ReadDirectoryChangesW(int64_t hDirectory, void *lpBuffer, uint32_t nBufferLength, bool32 bWatchSubtree, uint32_t dwNotifyFilter, uint32_t *lpBytesReturned, struct NtOverlapped *lpOverlapped, NtOverlappedCompletionRoutine lpCompletionRoutine);
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NT_BASE_H_ */

View file

@ -49,6 +49,7 @@ COSMOPOLITAN_C_START_
intptr_t LoadResource(int64_t hModule, int64_t hResInfo);
uint32_t SetHandleCount(uint32_t uNumber);
uint32_t GetLogicalDrives(void);
unsigned int GetDriveTypeA(const char *lpRootPathName);
uint32_t GetLogicalDriveStringsA(uint32_t nBufferLength, char *lpBuffer);
bool32 FlushFileBuffers(int64_t hFile);

View file

@ -0,0 +1,20 @@
#include "libc/nt/codegen.h"
.imp kernel32,__imp_GetDriveTypeA,GetDriveTypeA
.text.windows
.ftrace1
GetDriveTypeA:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov %rdi,%rcx
sub $32,%rsp
call *__imp_GetDriveTypeA(%rip)
leave
#elif defined(__aarch64__)
mov x0,#0
#endif
ret
.endfn GetDriveTypeA,globl
.previous

View file

@ -0,0 +1,18 @@
#include "libc/nt/codegen.h"
.imp kernel32,__imp_ReadDirectoryChangesW,ReadDirectoryChangesW
.text.windows
.ftrace1
ReadDirectoryChanges:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_ReadDirectoryChangesW(%rip),%rax
jmp __sysv2nt8
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn ReadDirectoryChanges,globl
.previous

View file

@ -117,6 +117,7 @@ imp 'GetCurrentProcessorNumberEx' GetCurrentProcessorNumberEx kernel32 1
imp 'GetCurrentThread' GetCurrentThread kernel32 0
imp 'GetCurrentThreadId' GetCurrentThreadId kernel32 0
imp 'GetDynamicTimeZoneInformation' GetDynamicTimeZoneInformation kernel32 1
imp 'GetDriveTypeA' GetDriveTypeA kernel32 1
imp 'GetEnvironmentStrings' GetEnvironmentStringsW kernel32 1
imp 'GetEnvironmentVariable' GetEnvironmentVariableW kernel32 3
imp 'GetExitCodeThread' GetExitCodeThread kernel32 2
@ -239,6 +240,7 @@ imp 'ReadConsoleOutputCharacter' ReadConsoleOutputCharacterW kernel32 5
imp 'ReadFile' ReadFile kernel32 5
imp 'ReadFileEx' ReadFileEx kernel32 5
imp 'ReadFileScatter' ReadFileScatter kernel32 5
imp 'ReadDirectoryChanges' ReadDirectoryChangesW kernel32 8
imp 'RegisterWaitForSingleObject' RegisterWaitForSingleObject kernel32 6
imp 'ReleaseMutex' ReleaseMutex kernel32 1
imp 'ReleaseSRWLockExclusive' ReleaseSRWLockExclusive kernel32 1

View file

@ -94,6 +94,7 @@ int WideCharToMultiByte(unsigned int CodePage, uint32_t dwFlags,
uint16_t *lpWideCharStr, int cchWideChar,
char *lpMultiByteStr, int cbMultiByte,
uint16_t *lpDefaultChar, int *lpUsedDefaultChar);
int MutliByteToWideChar(unsigned int CodePage, uint32_t dwFlags, const char *lpMultiByteStr, int cbMultiByte, uint16_t *lpWideCharStr, int cchWideChar);
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NT_WINDOWS_H_ */