Skip to content

Commit baad1df

Browse files
authored
Add several NT functions (#1318)
With these addtions, I could build and run a [sokol](https://github.com/floooh/sokol) application (using OpenGL) on both Linux and Windows.
1 parent 4e44517 commit baad1df

33 files changed

+618
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ COSMOPOLITAN = \
449449
LIBC_NT_BCRYPTPRIMITIVES \
450450
LIBC_NT_COMDLG32 \
451451
LIBC_NT_GDI32 \
452+
LIBC_NT_SHELL32 \
452453
LIBC_NT_IPHLPAPI \
453454
LIBC_NT_KERNEL32 \
454455
LIBC_NT_NTDLL \

libc/nt/BUILD.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ $(LIBC_NT_COMDLG32_A).pkg: \
9191

9292
#───────────────────────────────────────────────────────────────────────────────
9393

94+
LIBC_NT_ARTIFACTS += LIBC_NT_SHELL32_A
95+
LIBC_NT_SHELL32 = $(LIBC_NT_SHELL32_A_DEPS) $(LIBC_NT_SHELL32_A)
96+
LIBC_NT_SHELL32_A = o/$(MODE)/libc/nt/shell32.a
97+
LIBC_NT_SHELL32_A_SRCS := $(wildcard libc/nt/shell32/*.S)
98+
LIBC_NT_SHELL32_A_OBJS = $(LIBC_NT_SHELL32_A_SRCS:%.S=o/$(MODE)/%.o)
99+
LIBC_NT_SHELL32_A_CHECKS = $(LIBC_NT_SHELL32_A).pkg
100+
LIBC_NT_SHELL32_A_DIRECTDEPS = LIBC_NT_KERNEL32
101+
LIBC_NT_SHELL32_A_DEPS := \
102+
$(call uniq,$(foreach x,$(LIBC_NT_SHELL32_A_DIRECTDEPS),$($(x))))
103+
104+
$(LIBC_NT_SHELL32_A): \
105+
libc/nt/shell32/ \
106+
$(LIBC_NT_SHELL32_A).pkg \
107+
$(LIBC_NT_SHELL32_A_OBJS)
108+
109+
$(LIBC_NT_SHELL32_A).pkg: \
110+
$(LIBC_NT_SHELL32_A_OBJS) \
111+
$(foreach x,$(LIBC_NT_SHELL32_A_DIRECTDEPS),$($(x)_A).pkg)
112+
113+
#───────────────────────────────────────────────────────────────────────────────
114+
94115
LIBC_NT_ARTIFACTS += LIBC_NT_GDI32_A
95116
LIBC_NT_GDI32 = $(LIBC_NT_GDI32_A_DEPS) $(LIBC_NT_GDI32_A)
96117
LIBC_NT_GDI32_A = o/$(MODE)/libc/nt/gdi32.a

libc/nt/gdi32/DescribePixelFormat.S

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "libc/nt/codegen.h"
2+
.imp gdi32,__imp_DescribePixelFormat,DescribePixelFormat
3+
4+
.text.windows
5+
.ftrace1
6+
DescribePixelFormat:
7+
.ftrace2
8+
#ifdef __x86_64__
9+
push %rbp
10+
mov %rsp,%rbp
11+
mov __imp_DescribePixelFormat(%rip),%rax
12+
jmp __sysv2nt
13+
#elif defined(__aarch64__)
14+
mov x0,#0
15+
ret
16+
#endif
17+
.endfn DescribePixelFormat,globl
18+
.previous

libc/nt/kernel32/GlobalLock.S

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "libc/nt/codegen.h"
2+
.imp kernel32,__imp_GlobalLock,GlobalLock
3+
4+
.text.windows
5+
.ftrace1
6+
GlobalLock:
7+
.ftrace2
8+
#ifdef __x86_64__
9+
push %rbp
10+
mov %rsp,%rbp
11+
mov %rdi,%rcx
12+
sub $32,%rsp
13+
call *__imp_GlobalLock(%rip)
14+
leave
15+
#elif defined(__aarch64__)
16+
mov x0,#0
17+
#endif
18+
ret
19+
.endfn GlobalLock,globl
20+
.previous

libc/nt/kernel32/GlobalUnlock.S

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "libc/nt/codegen.h"
2+
.imp kernel32,__imp_GlobalUnlock,GlobalUnlock
3+
4+
.text.windows
5+
.ftrace1
6+
GlobalUnlock:
7+
.ftrace2
8+
#ifdef __x86_64__
9+
push %rbp
10+
mov %rsp,%rbp
11+
mov %rdi,%rcx
12+
sub $32,%rsp
13+
call *__imp_GlobalUnlock(%rip)
14+
leave
15+
#elif defined(__aarch64__)
16+
mov x0,#0
17+
#endif
18+
ret
19+
.endfn GlobalUnlock,globl
20+
.previous

libc/nt/master.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ imp 'GetWindowsDirectoryA' GetWindowsDirectoryA kernel32 2
186186
imp 'GlobalAlloc' GlobalAlloc kernel32 2
187187
imp 'GlobalFree' GlobalFree kernel32 1
188188
imp 'GlobalMemoryStatusEx' GlobalMemoryStatusEx kernel32 1
189+
imp 'GlobalLock' GlobalLock kernel32 1
190+
imp 'GlobalUnlock' GlobalUnlock kernel32 1
189191
imp 'HeapAlloc' HeapAlloc kernel32 3
190192
imp 'HeapCompact' HeapCompact kernel32 2
191193
imp 'HeapCreate' HeapCreate kernel32 3
@@ -376,13 +378,17 @@ imp 'TraceSetInformation' TraceSetInformation advapi32 # Windows 7+
376378
#
377379
# Name Actual DLL Arity
378380
imp 'AdjustWindowRect' AdjustWindowRect user32 3
381+
imp 'AdjustWindowRectEx' AdjustWindowRectEx user32 4
379382
imp 'AnimateWindow' AnimateWindow user32 3
380383
imp 'AppendMenuA' AppendMenuA user32 4
381384
imp 'AppendMenu' AppendMenuW user32 4
382385
imp 'BeginPaint' BeginPaint user32 2
383386
imp 'BringWindowToTop' BringWindowToTop user32 1
384387
imp 'CallNextHookEx' CallNextHookEx user32 4
385388
imp 'CloseWindow' CloseWindow user32 1
389+
imp 'ClientToScreen' ClientToScreen user32 2
390+
imp 'ClipCursor' ClipCursor user32 1
391+
imp 'CloseClipboard' CloseClipboard user32 0
386392
imp 'CreateIconIndirect' CreateIconIndirect user32 1
387393
imp 'CreateMenu' CreateMenu user32 0
388394
imp 'CreatePopupMenu' CreatePopupMenu user32 0
@@ -395,12 +401,15 @@ imp 'DestroyWindow' DestroyWindow user32 1
395401
imp 'DispatchMessage' DispatchMessageW user32 1
396402
imp 'DrawText' DrawTextW user32 5
397403
imp 'DrawTextEx' DrawTextExW user32 6
404+
imp 'EmptyClipboard' EmptyClipboard user32 0
398405
imp 'EndPaint' EndPaint user32 2
399406
imp 'EnumChildWindows' EnumChildWindows user32 3
400407
imp 'FillRect' FillRect user32 3
401408
imp 'FindWindow' FindWindowW user32 2
402409
imp 'FindWindowEx' FindWindowExW user32 4
410+
imp 'GetAsyncKeyState' GetAsyncKeyState user32 1
403411
imp 'GetClientRect' GetClientRect user32 2
412+
imp 'GetClipboardData' GetClipboardData user32 1
404413
imp 'GetCursor' GetCursor user32 0
405414
imp 'GetCursorPos' GetCursorPos user32 1
406415
imp 'GetDC' GetDC user32 1
@@ -409,9 +418,12 @@ imp 'GetKeyState' GetKeyState user32 1
409418
imp 'GetKeyboardLayout' GetKeyboardLayout user32 1
410419
imp 'GetMenu' GetMenu user32 1
411420
imp 'GetMessage' GetMessageW user32 4
421+
imp 'GetMonitorInfo' GetMonitorInfoW user32 2
422+
imp 'GetRawInputData' GetRawInputData user32 5
412423
imp 'GetParent' GetParent user32 1
413424
imp 'GetShellWindow' GetShellWindow user32 0
414425
imp 'GetSystemMenu' GetSystemMenu user32 2
426+
imp 'GetSystemMetrics' GetSystemMetrics user32 1
415427
imp 'GetWindow' GetWindow user32 2
416428
imp 'GetWindowPlacement' GetWindowPlacement user32 2
417429
imp 'GetWindowRect' GetWindowRect user32 2
@@ -432,20 +444,30 @@ imp 'MapVirtualKeyEx' MapVirtualKeyExW user32 3
432444
imp 'MessageBox' MessageBoxW user32 4
433445
imp 'MessageBoxEx' MessageBoxExW user32 5
434446
imp 'MoveWindow' MoveWindow user32 6
447+
imp 'MonitorFromPoint' MonitorFromPoint user32 2
448+
imp 'MonitorFromWindow' MonitorFromWindow user32 2
449+
imp 'OpenClipboard' OpenClipboard user32 1
435450
imp 'PeekMessage' PeekMessageW user32 5
451+
imp 'PostMessage' PostMessageW user32 4
436452
imp 'PostQuitMessage' PostQuitMessage user32 1
453+
imp 'PtInRect' PtInRect user32 2
437454
imp 'RedrawWindow' RedrawWindow user32 4
438455
imp 'RegisterClass' RegisterClassW user32 1
439456
imp 'RegisterClassEx' RegisterClassExW user32 1
457+
imp 'RegisterRawInputDevices' RegisterRawInputDevices user32 3
440458
imp 'ReleaseCapture' ReleaseCapture user32 0
441459
imp 'ReleaseDC' ReleaseDC user32 2
460+
imp 'ScreenToClient' ScreenToClient user32 2
461+
imp 'SetClipboardData' SetClipboardData user32 2
462+
imp 'SetCursorPos' SetCursorPos user32 2
442463
imp 'SendMessage' SendMessageW user32 4
443464
imp 'SetCapture' SetCapture user32 1
444465
imp 'SetClassLong' SetClassLongW user32 3
445466
imp 'SetCursor' SetCursor user32 1
446467
imp 'SetParent' SetParent user32 2
447468
imp 'SetTimer' SetTimer user32 4
448469
imp 'SetWindowLong' SetWindowLongW user32 3
470+
imp 'SetWindowLongPtr' SetWindowLongPtrW user32 3
449471
imp 'SetWindowPlacement' SetWindowPlacement user32 2
450472
imp 'SetWindowPos' SetWindowPos user32 7
451473
imp 'SetWindowText' SetWindowTextW user32 2
@@ -454,12 +476,23 @@ imp 'SetWindowsHookEx' SetWindowsHookExW user32 4
454476
imp 'ShowCaret' ShowCaret user32 1
455477
imp 'ShowCursor' ShowCursor user32 1
456478
imp 'ShowWindow' ShowWindow user32 2
479+
imp 'TrackMouseEvent' TrackMouseEvent user32 1
457480
imp 'TrackPopupMenu' TrackPopupMenu user32 7
458481
imp 'TranslateMessage' TranslateMessage user32 1
459482
imp 'UnhookWindowsHook' UnhookWindowsHook user32 2
460483
imp 'UnhookWindowsHookEx' UnhookWindowsHookEx user32 1
484+
imp 'UnregisterClass' UnregisterClassW user32 2
461485
imp 'UpdateWindow' UpdateWindow user32 1
462486
imp 'WaitForInputIdle' WaitForInputIdle user32 2
487+
imp 'WindowFromPoint' WindowFromPoint user32 1
488+
489+
# SHELL32.DLL
490+
#
491+
# Name Actual DLL Arity
492+
imp 'CommandLineToArgv' CommandLineToArgvW shell32 2
493+
imp 'DragAcceptFiles' DragAcceptFiles shell32 2
494+
imp 'DragFinish' DragFinish shell32 1
495+
imp 'DragQueryFile' DragQueryFileW shell32 4
463496

464497
# GDI32.DLL
465498
#
@@ -473,6 +506,7 @@ imp 'CreateDIBSection' CreateDIBSection gdi32 6
473506
imp 'CreateRectRgn' CreateRectRgn gdi32 4
474507
imp 'DeleteDC' DeleteDC gdi32 1
475508
imp 'DeleteObject' DeleteObject gdi32 1
509+
imp 'DescribePixelFormat' DescribePixelFormat gdi32 4
476510
imp 'GetPixel' GetPixel gdi32 3
477511
imp 'RestoreDC' RestoreDC gdi32 2
478512
imp 'SaveDC' SaveDC gdi32 1

libc/nt/shell32/CommandLineToArgvW.S

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "libc/nt/codegen.h"
2+
.imp shell32,__imp_CommandLineToArgvW,CommandLineToArgvW
3+
4+
.text.windows
5+
.ftrace1
6+
CommandLineToArgv:
7+
.ftrace2
8+
#ifdef __x86_64__
9+
push %rbp
10+
mov %rsp,%rbp
11+
mov __imp_CommandLineToArgvW(%rip),%rax
12+
jmp __sysv2nt
13+
#elif defined(__aarch64__)
14+
mov x0,#0
15+
ret
16+
#endif
17+
.endfn CommandLineToArgv,globl
18+
.previous

libc/nt/shell32/DragAcceptFiles.S

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "libc/nt/codegen.h"
2+
.imp shell32,__imp_DragAcceptFiles,DragAcceptFiles
3+
4+
.text.windows
5+
.ftrace1
6+
DragAcceptFiles:
7+
.ftrace2
8+
#ifdef __x86_64__
9+
push %rbp
10+
mov %rsp,%rbp
11+
mov __imp_DragAcceptFiles(%rip),%rax
12+
jmp __sysv2nt
13+
#elif defined(__aarch64__)
14+
mov x0,#0
15+
ret
16+
#endif
17+
.endfn DragAcceptFiles,globl
18+
.previous

libc/nt/shell32/DragFinish.S

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "libc/nt/codegen.h"
2+
.imp shell32,__imp_DragFinish,DragFinish
3+
4+
.text.windows
5+
.ftrace1
6+
DragFinish:
7+
.ftrace2
8+
#ifdef __x86_64__
9+
push %rbp
10+
mov %rsp,%rbp
11+
mov %rdi,%rcx
12+
sub $32,%rsp
13+
call *__imp_DragFinish(%rip)
14+
leave
15+
#elif defined(__aarch64__)
16+
mov x0,#0
17+
#endif
18+
ret
19+
.endfn DragFinish,globl
20+
.previous

libc/nt/shell32/DragQueryFileW.S

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "libc/nt/codegen.h"
2+
.imp shell32,__imp_DragQueryFileW,DragQueryFileW
3+
4+
.text.windows
5+
.ftrace1
6+
DragQueryFile:
7+
.ftrace2
8+
#ifdef __x86_64__
9+
push %rbp
10+
mov %rsp,%rbp
11+
mov __imp_DragQueryFileW(%rip),%rax
12+
jmp __sysv2nt
13+
#elif defined(__aarch64__)
14+
mov x0,#0
15+
ret
16+
#endif
17+
.endfn DragQueryFile,globl
18+
.previous

0 commit comments

Comments
 (0)