Adds some NT functions (#1358)

This commit is contained in:
A2va 2025-02-08 17:08:08 +01:00 committed by GitHub
parent 12cb0669fb
commit 42a9ed0131
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 195 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/nt/ipc.h" #include "libc/nt/ipc.h"
#include "libc/nt/memory.h" #include "libc/nt/memory.h"
#include "libc/nt/nls.h"
#include "libc/nt/paint.h" #include "libc/nt/paint.h"
#include "libc/nt/process.h" #include "libc/nt/process.h"
#include "libc/nt/registry.h" #include "libc/nt/registry.h"
@ -1420,6 +1421,15 @@
#define HKEY_CURRENT_CONFIG kNtHkeyCurrentConfig #define HKEY_CURRENT_CONFIG kNtHkeyCurrentConfig
#define HKEY_DYN_DATA kNtHkeyDynData #define HKEY_DYN_DATA kNtHkeyDynData
#define HKEY_CURRENT_USER_LOCAL_SETTINGS kNtHkeyCurrentUserLocalSettings #define HKEY_CURRENT_USER_LOCAL_SETTINGS kNtHkeyCurrentUserLocalSettings
#define KEY_QUERY_VALUE kNtKeyQueryValue
#define KEY_SET_VALUE kNtKeySetValue
#define KEY_CREATE_SUB_KEY kNtKeyCreateSubKey
#define KEY_ENUMERATE_SUB_KEYS kNtKeyEnumerateSubKeys
#define KEY_NOTIFY kNtKeyNotify
#define KEY_CREATE_LINK kNtKeyCreateLink
#define KEY_WOW64_32KEY kNtWow6432Key
#define KEY_WOW64_64KEY kNtWow6464Key
#define KEY_WOW64_RES kNtWow64Res
#define KEY_READ kNtKeyRead #define KEY_READ kNtKeyRead
#define KEY_WRITE kNtKeyWrite #define KEY_WRITE kNtKeyWrite
#define KEY_EXECUTE kNtKeyExecute #define KEY_EXECUTE kNtKeyExecute
@ -4291,6 +4301,13 @@
#define MAKE_HRESULT(sev,fac,code) ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) ) #define MAKE_HRESULT(sev,fac,code) ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
#define MAKE_SCODE(sev,fac,code) ((SCODE) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) ) #define MAKE_SCODE(sev,fac,code) ((SCODE) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
#define CP_ACP 0
#define CP_OEMCP 1
#define CP_MACCP 2
#define CP_THREAD_ACP 3
#define CP_SYMBOL 42
#define CP_UTF7 65000
#define CP_UTF8 65001 #define CP_UTF8 65001
#endif /* COSMOPOLITAN_LIBC_COMPAT_INCLUDE_WINDOWS_H_ */ #endif /* COSMOPOLITAN_LIBC_COMPAT_INCLUDE_WINDOWS_H_ */

View file

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

View file

@ -1,6 +1,16 @@
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_
#define COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_
#define kNtKeyQueryValue 0x00000001
#define kNtKeySetValue 0x00000002
#define kNtKeyCreateSubKey 0x00000004
#define kNtKeyEnumerateSubKeys 0x00000008
#define kNtKeyNotify 0x00000010
#define kNtKeyCreateLink 0x00000020
#define kNtWow6432Key 0x00000200
#define kNtWow6464Key 0x00000100
#define kNtWow64Res 0x00000300
#define kNtKeyRead 0x00020019 #define kNtKeyRead 0x00020019
#define kNtKeyWrite 0x00020006 #define kNtKeyWrite 0x00020006
#define kNtKeyExecute 0x00020019 #define kNtKeyExecute 0x00020019

View file

@ -49,6 +49,7 @@ COSMOPOLITAN_C_START_
intptr_t LoadResource(int64_t hModule, int64_t hResInfo); intptr_t LoadResource(int64_t hModule, int64_t hResInfo);
uint32_t SetHandleCount(uint32_t uNumber); uint32_t SetHandleCount(uint32_t uNumber);
uint32_t GetLogicalDrives(void); uint32_t GetLogicalDrives(void);
uint32_t GetLogicalDriveStringsA(uint32_t nBufferLength, char *lpBuffer);
bool32 FlushFileBuffers(int64_t hFile); bool32 FlushFileBuffers(int64_t hFile);
int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess, int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess,
@ -205,6 +206,7 @@ uint32_t GetFinalPathNameByHandle(int64_t hFile, char16_t *out_path,
uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength, uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength,
char16_t *lpBuffer, char16_t **lpFilePart); char16_t *lpBuffer, char16_t **lpFilePart);
uint32_t GetShortPathName(const char16_t *lpszLongPath, char16_t *out_lpszShortPath, uint32_t cchBuffer);
bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped, bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped,
uint32_t *lpNumberOfBytesTransferred, bool32 bWait); uint32_t *lpNumberOfBytesTransferred, bool32 bWait);

19
libc/nt/kernel32/GetACP.S Normal file
View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -129,10 +129,12 @@ imp 'GetFileTime' GetFileTime kernel32 4
imp 'GetFileType' GetFileType kernel32 1 imp 'GetFileType' GetFileType kernel32 1
imp 'GetFinalPathNameByHandle' GetFinalPathNameByHandleW kernel32 4 imp 'GetFinalPathNameByHandle' GetFinalPathNameByHandleW kernel32 4
imp 'GetFullPathName' GetFullPathNameW kernel32 4 imp 'GetFullPathName' GetFullPathNameW kernel32 4
imp 'GetShortPathName' GetShortPathNameW kernel32 3
imp 'GetHandleInformation' GetHandleInformation kernel32 2 imp 'GetHandleInformation' GetHandleInformation kernel32 2
imp 'GetLargestConsoleWindowSize' GetLargestConsoleWindowSize kernel32 1 imp 'GetLargestConsoleWindowSize' GetLargestConsoleWindowSize kernel32 1
imp 'GetLastError' GetLastError kernel32 0 imp 'GetLastError' GetLastError kernel32 0
imp 'GetLogicalDrives' GetLogicalDrives kernel32 0 imp 'GetLogicalDrives' GetLogicalDrives kernel32 0
imp 'GetLogicalDriveStringsA' GetLogicalDriveStringsA kernel32 2
imp 'GetMaximumProcessorCount' GetMaximumProcessorCount kernel32 1 # Windows 7+ imp 'GetMaximumProcessorCount' GetMaximumProcessorCount kernel32 1 # Windows 7+
imp 'GetModuleFileName' GetModuleFileNameW kernel32 3 imp 'GetModuleFileName' GetModuleFileNameW kernel32 3
imp 'GetModuleHandle' GetModuleHandleA kernel32 1 imp 'GetModuleHandle' GetModuleHandleA kernel32 1
@ -186,6 +188,9 @@ imp 'GetVolumeInformationByHandle' GetVolumeInformationByHandleW kernel32
imp 'GetVolumePathName' GetVolumePathNameW kernel32 3 imp 'GetVolumePathName' GetVolumePathNameW kernel32 3
imp 'GetWindowsDirectory' GetWindowsDirectoryW kernel32 2 imp 'GetWindowsDirectory' GetWindowsDirectoryW kernel32 2
imp 'GetWindowsDirectoryA' GetWindowsDirectoryA kernel32 2 imp 'GetWindowsDirectoryA' GetWindowsDirectoryA kernel32 2
imp 'GetOEMCP' GetOEMCP kernel32 0
imp 'GetACP' GetACP kernel32 0
imp 'GetCPInfoEx' GetCPInfoExW kernel32 3
imp 'GlobalAlloc' GlobalAlloc kernel32 2 imp 'GlobalAlloc' GlobalAlloc kernel32 2
imp 'GlobalFree' GlobalFree kernel32 1 imp 'GlobalFree' GlobalFree kernel32 1
imp 'GlobalLock' GlobalLock kernel32 1 imp 'GlobalLock' GlobalLock kernel32 1
@ -356,6 +361,7 @@ imp 'RegLoadKey' RegLoadKeyW advapi32 3
imp 'RegNotifyChangeKeyValue' RegNotifyChangeKeyValue advapi32 5 imp 'RegNotifyChangeKeyValue' RegNotifyChangeKeyValue advapi32 5
imp 'RegOpenCurrentUser' RegOpenCurrentUser advapi32 2 imp 'RegOpenCurrentUser' RegOpenCurrentUser advapi32 2
imp 'RegOpenKeyEx' RegOpenKeyExW advapi32 5 imp 'RegOpenKeyEx' RegOpenKeyExW advapi32 5
imp 'RegOpenKeyExA' RegOpenKeyExA advapi32 5
imp 'RegOpenUserClassesRoot' RegOpenUserClassesRoot advapi32 4 imp 'RegOpenUserClassesRoot' RegOpenUserClassesRoot advapi32 4
imp 'RegOverridePredefKey' RegOverridePredefKey advapi32 2 imp 'RegOverridePredefKey' RegOverridePredefKey advapi32 2
imp 'RegQueryInfoKey' RegQueryInfoKeyW advapi32 12 imp 'RegQueryInfoKey' RegQueryInfoKeyW advapi32 12

35
libc/nt/nls.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef COSMOPOLITAN_LIBC_NT_NLS_H_
#define COSMOPOLITAN_LIBC_NT_NLS_H_
#include "libc/nt/struct/cpinfoex.h"
/* ░░░░
cosmopolitan § new technology » internationalization
*/
COSMOPOLITAN_C_START_
uint32_t GetOEMCP();
uint32_t GetACP();
bool32 GetCPInfoEx(uint32_t CodePage, uint32_t dwFlags, struct NtCpInfoEx *out_lpCPInfoEx) paramsnonnull((3));
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NT_NLS_H_ */

View file

@ -51,6 +51,8 @@ int RegOpenKey(int64_t hKey, const char16_t *opt_lpSubKey,
int RegOpenKeyEx(int64_t hKey, const char16_t *opt_lpSubKey, int RegOpenKeyEx(int64_t hKey, const char16_t *opt_lpSubKey,
uint32_t opt_ulOptions, int samDesired, int64_t *out_phkResult) uint32_t opt_ulOptions, int samDesired, int64_t *out_phkResult)
paramsnonnull((5)); paramsnonnull((5));
int RegOpenKeyExA(int64_t hKey, const char *opt_lpSubKey, uint32_t opt_ulOptions,
int samDesired, int64_t *out_phkResult) paramsnonnull((5));
int RegCloseKey(int64_t hKey); int RegCloseKey(int64_t hKey);
int RegGetValue(int64_t hkey, const char16_t *opt_lpSubKey, int RegGetValue(int64_t hkey, const char16_t *opt_lpSubKey,

13
libc/nt/struct/cpinfoex.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_CPINFOEX_H_
#define COSMOPOLITAN_LIBC_NT_STRUCT_CPINFOEX_H_
struct NtCpInfoEx {
uint32_t MaxCharSize;
uint8_t DefaultChar[2];
uint8_t LeadByte[12];
char16_t UnicodeDefaultChar;
uint32_t CodePage;
char16_t CodePageName[260];
};
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_CPINFOEX_H_ */