Skip to content

Commit

Permalink
Add several NT functions (#1318)
Browse files Browse the repository at this point in the history
With these addtions, I could build and run a
[sokol](https://github.com/floooh/sokol) application (using OpenGL) on
both Linux and Windows.
  • Loading branch information
bullno1 authored Oct 28, 2024
1 parent 4e44517 commit baad1df
Show file tree
Hide file tree
Showing 33 changed files with 618 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ COSMOPOLITAN = \
LIBC_NT_BCRYPTPRIMITIVES \
LIBC_NT_COMDLG32 \
LIBC_NT_GDI32 \
LIBC_NT_SHELL32 \
LIBC_NT_IPHLPAPI \
LIBC_NT_KERNEL32 \
LIBC_NT_NTDLL \
Expand Down
21 changes: 21 additions & 0 deletions libc/nt/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ $(LIBC_NT_COMDLG32_A).pkg: \

#───────────────────────────────────────────────────────────────────────────────

LIBC_NT_ARTIFACTS += LIBC_NT_SHELL32_A
LIBC_NT_SHELL32 = $(LIBC_NT_SHELL32_A_DEPS) $(LIBC_NT_SHELL32_A)
LIBC_NT_SHELL32_A = o/$(MODE)/libc/nt/shell32.a
LIBC_NT_SHELL32_A_SRCS := $(wildcard libc/nt/shell32/*.S)
LIBC_NT_SHELL32_A_OBJS = $(LIBC_NT_SHELL32_A_SRCS:%.S=o/$(MODE)/%.o)
LIBC_NT_SHELL32_A_CHECKS = $(LIBC_NT_SHELL32_A).pkg
LIBC_NT_SHELL32_A_DIRECTDEPS = LIBC_NT_KERNEL32
LIBC_NT_SHELL32_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_NT_SHELL32_A_DIRECTDEPS),$($(x))))

$(LIBC_NT_SHELL32_A): \
libc/nt/shell32/ \
$(LIBC_NT_SHELL32_A).pkg \
$(LIBC_NT_SHELL32_A_OBJS)

$(LIBC_NT_SHELL32_A).pkg: \
$(LIBC_NT_SHELL32_A_OBJS) \
$(foreach x,$(LIBC_NT_SHELL32_A_DIRECTDEPS),$($(x)_A).pkg)

#───────────────────────────────────────────────────────────────────────────────

LIBC_NT_ARTIFACTS += LIBC_NT_GDI32_A
LIBC_NT_GDI32 = $(LIBC_NT_GDI32_A_DEPS) $(LIBC_NT_GDI32_A)
LIBC_NT_GDI32_A = o/$(MODE)/libc/nt/gdi32.a
Expand Down
18 changes: 18 additions & 0 deletions libc/nt/gdi32/DescribePixelFormat.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "libc/nt/codegen.h"
.imp gdi32,__imp_DescribePixelFormat,DescribePixelFormat

.text.windows
.ftrace1
DescribePixelFormat:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_DescribePixelFormat(%rip),%rax
jmp __sysv2nt
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn DescribePixelFormat,globl
.previous
20 changes: 20 additions & 0 deletions libc/nt/kernel32/GlobalLock.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "libc/nt/codegen.h"
.imp kernel32,__imp_GlobalLock,GlobalLock

.text.windows
.ftrace1
GlobalLock:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov %rdi,%rcx
sub $32,%rsp
call *__imp_GlobalLock(%rip)
leave
#elif defined(__aarch64__)
mov x0,#0
#endif
ret
.endfn GlobalLock,globl
.previous
20 changes: 20 additions & 0 deletions libc/nt/kernel32/GlobalUnlock.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "libc/nt/codegen.h"
.imp kernel32,__imp_GlobalUnlock,GlobalUnlock

.text.windows
.ftrace1
GlobalUnlock:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov %rdi,%rcx
sub $32,%rsp
call *__imp_GlobalUnlock(%rip)
leave
#elif defined(__aarch64__)
mov x0,#0
#endif
ret
.endfn GlobalUnlock,globl
.previous
34 changes: 34 additions & 0 deletions libc/nt/master.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ imp 'GetWindowsDirectoryA' GetWindowsDirectoryA kernel32 2
imp 'GlobalAlloc' GlobalAlloc kernel32 2
imp 'GlobalFree' GlobalFree kernel32 1
imp 'GlobalMemoryStatusEx' GlobalMemoryStatusEx kernel32 1
imp 'GlobalLock' GlobalLock kernel32 1
imp 'GlobalUnlock' GlobalUnlock kernel32 1
imp 'HeapAlloc' HeapAlloc kernel32 3
imp 'HeapCompact' HeapCompact kernel32 2
imp 'HeapCreate' HeapCreate kernel32 3
Expand Down Expand Up @@ -376,13 +378,17 @@ imp 'TraceSetInformation' TraceSetInformation advapi32 # Windows 7+
#
# Name Actual DLL Arity
imp 'AdjustWindowRect' AdjustWindowRect user32 3
imp 'AdjustWindowRectEx' AdjustWindowRectEx user32 4
imp 'AnimateWindow' AnimateWindow user32 3
imp 'AppendMenuA' AppendMenuA user32 4
imp 'AppendMenu' AppendMenuW user32 4
imp 'BeginPaint' BeginPaint user32 2
imp 'BringWindowToTop' BringWindowToTop user32 1
imp 'CallNextHookEx' CallNextHookEx user32 4
imp 'CloseWindow' CloseWindow user32 1
imp 'ClientToScreen' ClientToScreen user32 2
imp 'ClipCursor' ClipCursor user32 1
imp 'CloseClipboard' CloseClipboard user32 0
imp 'CreateIconIndirect' CreateIconIndirect user32 1
imp 'CreateMenu' CreateMenu user32 0
imp 'CreatePopupMenu' CreatePopupMenu user32 0
Expand All @@ -395,12 +401,15 @@ imp 'DestroyWindow' DestroyWindow user32 1
imp 'DispatchMessage' DispatchMessageW user32 1
imp 'DrawText' DrawTextW user32 5
imp 'DrawTextEx' DrawTextExW user32 6
imp 'EmptyClipboard' EmptyClipboard user32 0
imp 'EndPaint' EndPaint user32 2
imp 'EnumChildWindows' EnumChildWindows user32 3
imp 'FillRect' FillRect user32 3
imp 'FindWindow' FindWindowW user32 2
imp 'FindWindowEx' FindWindowExW user32 4
imp 'GetAsyncKeyState' GetAsyncKeyState user32 1
imp 'GetClientRect' GetClientRect user32 2
imp 'GetClipboardData' GetClipboardData user32 1
imp 'GetCursor' GetCursor user32 0
imp 'GetCursorPos' GetCursorPos user32 1
imp 'GetDC' GetDC user32 1
Expand All @@ -409,9 +418,12 @@ imp 'GetKeyState' GetKeyState user32 1
imp 'GetKeyboardLayout' GetKeyboardLayout user32 1
imp 'GetMenu' GetMenu user32 1
imp 'GetMessage' GetMessageW user32 4
imp 'GetMonitorInfo' GetMonitorInfoW user32 2
imp 'GetRawInputData' GetRawInputData user32 5
imp 'GetParent' GetParent user32 1
imp 'GetShellWindow' GetShellWindow user32 0
imp 'GetSystemMenu' GetSystemMenu user32 2
imp 'GetSystemMetrics' GetSystemMetrics user32 1
imp 'GetWindow' GetWindow user32 2
imp 'GetWindowPlacement' GetWindowPlacement user32 2
imp 'GetWindowRect' GetWindowRect user32 2
Expand All @@ -432,20 +444,30 @@ imp 'MapVirtualKeyEx' MapVirtualKeyExW user32 3
imp 'MessageBox' MessageBoxW user32 4
imp 'MessageBoxEx' MessageBoxExW user32 5
imp 'MoveWindow' MoveWindow user32 6
imp 'MonitorFromPoint' MonitorFromPoint user32 2
imp 'MonitorFromWindow' MonitorFromWindow user32 2
imp 'OpenClipboard' OpenClipboard user32 1
imp 'PeekMessage' PeekMessageW user32 5
imp 'PostMessage' PostMessageW user32 4
imp 'PostQuitMessage' PostQuitMessage user32 1
imp 'PtInRect' PtInRect user32 2
imp 'RedrawWindow' RedrawWindow user32 4
imp 'RegisterClass' RegisterClassW user32 1
imp 'RegisterClassEx' RegisterClassExW user32 1
imp 'RegisterRawInputDevices' RegisterRawInputDevices user32 3
imp 'ReleaseCapture' ReleaseCapture user32 0
imp 'ReleaseDC' ReleaseDC user32 2
imp 'ScreenToClient' ScreenToClient user32 2
imp 'SetClipboardData' SetClipboardData user32 2
imp 'SetCursorPos' SetCursorPos user32 2
imp 'SendMessage' SendMessageW user32 4
imp 'SetCapture' SetCapture user32 1
imp 'SetClassLong' SetClassLongW user32 3
imp 'SetCursor' SetCursor user32 1
imp 'SetParent' SetParent user32 2
imp 'SetTimer' SetTimer user32 4
imp 'SetWindowLong' SetWindowLongW user32 3
imp 'SetWindowLongPtr' SetWindowLongPtrW user32 3
imp 'SetWindowPlacement' SetWindowPlacement user32 2
imp 'SetWindowPos' SetWindowPos user32 7
imp 'SetWindowText' SetWindowTextW user32 2
Expand All @@ -454,12 +476,23 @@ imp 'SetWindowsHookEx' SetWindowsHookExW user32 4
imp 'ShowCaret' ShowCaret user32 1
imp 'ShowCursor' ShowCursor user32 1
imp 'ShowWindow' ShowWindow user32 2
imp 'TrackMouseEvent' TrackMouseEvent user32 1
imp 'TrackPopupMenu' TrackPopupMenu user32 7
imp 'TranslateMessage' TranslateMessage user32 1
imp 'UnhookWindowsHook' UnhookWindowsHook user32 2
imp 'UnhookWindowsHookEx' UnhookWindowsHookEx user32 1
imp 'UnregisterClass' UnregisterClassW user32 2
imp 'UpdateWindow' UpdateWindow user32 1
imp 'WaitForInputIdle' WaitForInputIdle user32 2
imp 'WindowFromPoint' WindowFromPoint user32 1

# SHELL32.DLL
#
# Name Actual DLL Arity
imp 'CommandLineToArgv' CommandLineToArgvW shell32 2
imp 'DragAcceptFiles' DragAcceptFiles shell32 2
imp 'DragFinish' DragFinish shell32 1
imp 'DragQueryFile' DragQueryFileW shell32 4

# GDI32.DLL
#
Expand All @@ -473,6 +506,7 @@ imp 'CreateDIBSection' CreateDIBSection gdi32 6
imp 'CreateRectRgn' CreateRectRgn gdi32 4
imp 'DeleteDC' DeleteDC gdi32 1
imp 'DeleteObject' DeleteObject gdi32 1
imp 'DescribePixelFormat' DescribePixelFormat gdi32 4
imp 'GetPixel' GetPixel gdi32 3
imp 'RestoreDC' RestoreDC gdi32 2
imp 'SaveDC' SaveDC gdi32 1
Expand Down
18 changes: 18 additions & 0 deletions libc/nt/shell32/CommandLineToArgvW.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "libc/nt/codegen.h"
.imp shell32,__imp_CommandLineToArgvW,CommandLineToArgvW

.text.windows
.ftrace1
CommandLineToArgv:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_CommandLineToArgvW(%rip),%rax
jmp __sysv2nt
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn CommandLineToArgv,globl
.previous
18 changes: 18 additions & 0 deletions libc/nt/shell32/DragAcceptFiles.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "libc/nt/codegen.h"
.imp shell32,__imp_DragAcceptFiles,DragAcceptFiles

.text.windows
.ftrace1
DragAcceptFiles:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_DragAcceptFiles(%rip),%rax
jmp __sysv2nt
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn DragAcceptFiles,globl
.previous
20 changes: 20 additions & 0 deletions libc/nt/shell32/DragFinish.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "libc/nt/codegen.h"
.imp shell32,__imp_DragFinish,DragFinish

.text.windows
.ftrace1
DragFinish:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov %rdi,%rcx
sub $32,%rsp
call *__imp_DragFinish(%rip)
leave
#elif defined(__aarch64__)
mov x0,#0
#endif
ret
.endfn DragFinish,globl
.previous
18 changes: 18 additions & 0 deletions libc/nt/shell32/DragQueryFileW.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "libc/nt/codegen.h"
.imp shell32,__imp_DragQueryFileW,DragQueryFileW

.text.windows
.ftrace1
DragQueryFile:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_DragQueryFileW(%rip),%rax
jmp __sysv2nt
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn DragQueryFile,globl
.previous
18 changes: 18 additions & 0 deletions libc/nt/user32/AdjustWindowRectEx.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "libc/nt/codegen.h"
.imp user32,__imp_AdjustWindowRectEx,AdjustWindowRectEx

.text.windows
.ftrace1
AdjustWindowRectEx:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_AdjustWindowRectEx(%rip),%rax
jmp __sysv2nt
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn AdjustWindowRectEx,globl
.previous
18 changes: 18 additions & 0 deletions libc/nt/user32/ClientToScreen.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "libc/nt/codegen.h"
.imp user32,__imp_ClientToScreen,ClientToScreen

.text.windows
.ftrace1
ClientToScreen:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov __imp_ClientToScreen(%rip),%rax
jmp __sysv2nt
#elif defined(__aarch64__)
mov x0,#0
ret
#endif
.endfn ClientToScreen,globl
.previous
20 changes: 20 additions & 0 deletions libc/nt/user32/ClipCursor.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "libc/nt/codegen.h"
.imp user32,__imp_ClipCursor,ClipCursor

.text.windows
.ftrace1
ClipCursor:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov %rdi,%rcx
sub $32,%rsp
call *__imp_ClipCursor(%rip)
leave
#elif defined(__aarch64__)
mov x0,#0
#endif
ret
.endfn ClipCursor,globl
.previous
19 changes: 19 additions & 0 deletions libc/nt/user32/CloseClipboard.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "libc/nt/codegen.h"
.imp user32,__imp_CloseClipboard,CloseClipboard

.text.windows
.ftrace1
CloseClipboard:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
sub $32,%rsp
call *__imp_CloseClipboard(%rip)
leave
#elif defined(__aarch64__)
mov x0,#0
#endif
ret
.endfn CloseClipboard,globl
.previous
19 changes: 19 additions & 0 deletions libc/nt/user32/EmptyClipboard.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "libc/nt/codegen.h"
.imp user32,__imp_EmptyClipboard,EmptyClipboard

.text.windows
.ftrace1
EmptyClipboard:
.ftrace2
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
sub $32,%rsp
call *__imp_EmptyClipboard(%rip)
leave
#elif defined(__aarch64__)
mov x0,#0
#endif
ret
.endfn EmptyClipboard,globl
.previous
Loading

0 comments on commit baad1df

Please sign in to comment.