Clean up more WIN32 APIs

This commit is contained in:
Justine Tunney 2023-07-30 16:00:58 -07:00
parent 44b88d659d
commit 929478c524
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
60 changed files with 74 additions and 962 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -9,6 +9,41 @@
# KERNEL32.DLL
#
# Name Actual DLL Arity
imp '' CancelIoEx kernel32 2
imp '' CloseHandle kernel32 1
imp '' CreateDirectoryW kernel32 2
imp '' CreateFileMappingNumaW kernel32 7
imp '' CreateFileMappingW kernel32 6
imp '' CreateFileW kernel32 7
imp '' CreateNamedPipeW kernel32 8
imp '' CreatePipe kernel32 4
imp '' CreateProcessW kernel32 10
imp '' CreateSymbolicLinkW kernel32 3
imp '' CreateThread kernel32 6
imp '' DeleteFileW kernel32 1
imp '' DeviceIoControl kernel32 8
imp '' FindClose kernel32 1
imp '' FindFirstFileW kernel32 2
imp '' FindNextFileW kernel32 2
imp '' FlushFileBuffers kernel32 1
imp '' FlushViewOfFile kernel32 2
imp '' GenerateConsoleCtrlEvent kernel32 2
imp '' GetExitCodeProcess kernel32 2
imp '' GetFileAttributesW kernel32 1
imp '' LockFileEx kernel32 6
imp '' MapViewOfFileEx kernel32 6
imp '' MapViewOfFileExNuma kernel32 7
imp '' MoveFileExW kernel32 3
imp '' OpenProcess kernel32 3
imp '' ReOpenFile kernel32 4 # TODO(jart): 6.2 and higher
imp '' RemoveDirectoryW kernel32 1
imp '' SetCurrentDirectoryW kernel32 1
imp '' TerminateProcess kernel32 2
imp '' UnlockFileEx kernel32 5
imp '' UnmapViewOfFile kernel32 1
imp '' VirtualProtect kernel32 4
imp '' WaitForMultipleObjects kernel32 4
imp '' WaitForSingleObject kernel32 2
imp 'AcquireSRWLockExclusive' AcquireSRWLockExclusive kernel32 1
imp 'AcquireSRWLockShared' AcquireSRWLockShared kernel32 1
imp 'AddVectoredContinueHandler' AddVectoredContinueHandler kernel32 2
@ -259,41 +294,6 @@ imp 'WriteConsoleOutputCharacter' WriteConsoleOutputCharacterW kernel32 5
imp 'WriteFile' WriteFile kernel32 5
imp 'WriteFileEx' WriteFileEx kernel32 5
imp 'WriteFileGather' WriteFileGather kernel32 5
imp '__CancelIoEx' CancelIoEx kernel32 2
imp '__CloseHandle' CloseHandle kernel32 1
imp '__CreateDirectory' CreateDirectoryW kernel32 2
imp '__CreateFile' CreateFileW kernel32 7
imp '__CreateFileMapping' CreateFileMappingW kernel32 6
imp '__CreateFileMappingNuma' CreateFileMappingNumaW kernel32 7
imp '__CreateNamedPipe' CreateNamedPipeW kernel32 8
imp '__CreatePipe' CreatePipe kernel32 4
imp '__CreateProcess' CreateProcessW kernel32 10
imp '__CreateSymbolicLink' CreateSymbolicLinkW kernel32 3
imp '__CreateThread' CreateThread kernel32 6
imp '__DeleteFile' DeleteFileW kernel32 1
imp '__DeviceIoControl' DeviceIoControl kernel32 8
imp '__FindClose' FindClose kernel32 1
imp '__FindFirstFile' FindFirstFileW kernel32 2
imp '__FindNextFile' FindNextFileW kernel32 2
imp '__FlushFileBuffers' FlushFileBuffers kernel32 1
imp '__FlushViewOfFile' FlushViewOfFile kernel32 2
imp '__GenerateConsoleCtrlEvent' GenerateConsoleCtrlEvent kernel32 2
imp '__GetExitCodeProcess' GetExitCodeProcess kernel32 2
imp '__GetFileAttributes' GetFileAttributesW kernel32 1
imp '__LockFileEx' LockFileEx kernel32 6
imp '__MapViewOfFileEx' MapViewOfFileEx kernel32 6
imp '__MapViewOfFileExNuma' MapViewOfFileExNuma kernel32 7
imp '__MoveFileEx' MoveFileExW kernel32 3
imp '__OpenProcess' OpenProcess kernel32 3
imp '__ReOpenFile' ReOpenFile kernel32 4 # TODO(jart): 6.2 and higher
imp '__RemoveDirectory' RemoveDirectoryW kernel32 1
imp '__SetCurrentDirectory' SetCurrentDirectoryW kernel32 1
imp '__TerminateProcess' TerminateProcess kernel32 2
imp '__UnlockFileEx' UnlockFileEx kernel32 5
imp '__UnmapViewOfFile' UnmapViewOfFile kernel32 1
imp '__VirtualProtect' VirtualProtect kernel32 4
imp '__WaitForMultipleObjects' WaitForMultipleObjects kernel32 4
imp '__WaitForSingleObject' WaitForSingleObject kernel32 2
# ADVAPI32.DLL
#
@ -490,6 +490,27 @@ imp 'WSARecvEx' WSARecvEx MsWSock 4
# WS2_32.DLL
#
# Name Actual DLL Arity
imp '' WSAGetOverlappedResult ws2_32 5
imp '' WSARecv ws2_32 7
imp '' WSARecvFrom ws2_32 9
imp '' WSAWaitForMultipleEvents ws2_32 5
imp '' accept ws2_32 3 # we're using WSAAccept()
imp '' bind ws2_32 3
imp '' closesocket ws2_32 1
imp '' getpeername ws2_32 3
imp '' getsockname ws2_32 3
imp '' getsockopt ws2_32 5
imp '' ioctlsocket ws2_32 3
imp '' listen ws2_32 2
imp '' recv ws2_32 4 # we're using WSARecvFrom()
imp '' recvfrom ws2_32 6 # we're using WSARecvFrom()
imp '' select ws2_32 5
imp '' send ws2_32 4 # we're using WSASendTo()
imp '' sendto ws2_32 6 # we're using WSASendTo()
imp '' setsockopt ws2_32 5
imp '' shutdown ws2_32 2
imp '' socket ws2_32 3
imp '' socket ws2_32 3
imp 'FreeAddrInfo' FreeAddrInfoW ws2_32 1
imp 'FreeAddrInfoEx' FreeAddrInfoExW ws2_32 1
imp 'GetAddrInfo' GetAddrInfoW ws2_32 4
@ -542,27 +563,6 @@ imp 'WSASetLastError' WSASetLastError ws2_32 1
imp 'WSASetService' WSASetServiceW ws2_32 3
imp 'WSASocket' WSASocketW ws2_32 6
imp 'WSAStartup' WSAStartup ws2_32 2
imp '__sys_socket_nt' socket ws2_32 3
imp '__sys_accept_nt' accept ws2_32 3 # we're using WSAAccept()
imp '__sys_bind_nt' bind ws2_32 3
imp '__sys_closesocket_nt' closesocket ws2_32 1
imp '__sys_getpeername_nt' getpeername ws2_32 3
imp '__sys_getsockname_nt' getsockname ws2_32 3
imp '__sys_getsockopt_nt' getsockopt ws2_32 5
imp '__sys_ioctlsocket_nt' ioctlsocket ws2_32 3
imp '__sys_listen_nt' listen ws2_32 2
imp '__sys_recvfrom_nt' recvfrom ws2_32 6 # we're using WSARecvFrom()
imp '__sys_select_nt' select ws2_32 5
imp '__sys_sendto_nt' sendto ws2_32 6 # we're using WSASendTo()
imp '__sys_setsockopt_nt' setsockopt ws2_32 5
imp '__sys_shutdown_nt' shutdown ws2_32 2
imp '__sys_socket_nt' socket ws2_32 3
imp '__WSARecv' WSARecv ws2_32 7
imp '__WSARecvFrom' WSARecvFrom ws2_32 9
imp '__WSAWaitForMultipleEvents' WSAWaitForMultipleEvents ws2_32 5
imp '__sys_recv_nt' recv ws2_32 4 # we're using WSARecvFrom()
imp '__sys_send_nt' send ws2_32 4 # we're using WSASendTo()
imp '__WSAGetOverlappedResult' WSAGetOverlappedResult ws2_32 5
# IPHLPAPI.DLL
#

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -21,6 +21,7 @@
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nt/thunk/msabi.h"
#include "libc/nt/winsock.h"
#include "libc/sock/internal.h"
#include "libc/sock/struct/sockaddr.h"
@ -30,6 +31,8 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/sock.h"
__msabi extern typeof(__sys_closesocket_nt) *const __imp_closesocket;
union AcceptExAddr {
struct sockaddr_storage addr;
char buf[sizeof(struct sockaddr_storage) + 16];
@ -70,7 +73,7 @@ textwindows int sys_accept_nt(struct Fd *fd, struct sockaddr_storage *addr,
if (__wsablock(fd, &overlapped, &completion_flags, kSigOpRestartable,
sockfd->rcvtimeo) == -1) {
WSACloseEvent(overlapped.hEvent);
__sys_closesocket_nt(handle);
__imp_closesocket(handle);
free(sockfd2);
return -1;
}

View file

@ -28,7 +28,7 @@ __msabi extern typeof(__sys_bind_nt) *const __imp_bind;
textwindows int sys_bind_nt(struct Fd *fd, const void *addr,
uint32_t addrsize) {
unassert(fd->kind == kFdSocket);
if (__sys_bind_nt(fd->handle, addr, addrsize) != -1) {
if (__imp_bind(fd->handle, addr, addrsize) != -1) {
return 0;
} else {
return __winsockerr();

View file

@ -22,6 +22,7 @@
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/errors.h"
#include "libc/nt/thunk/msabi.h"
#include "libc/nt/winsock.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"
@ -30,10 +31,14 @@
#include "libc/sock/syscall_fd.internal.h"
#include "libc/sysv/errfuns.h"
__msabi extern typeof(__sys_getsockname_nt) *const __imp_getsockname;
__msabi extern typeof(__sys_getpeername_nt) *const __imp_getpeername;
static int __getsockpeername(int fd, struct sockaddr *out_addr,
uint32_t *inout_addrsize, const char *name,
int impl_sysv(int, void *, uint32_t *),
int impl_win32(uint64_t, void *, uint32_t *)) {
int (*__msabi impl_win32)(uint64_t, void *,
uint32_t *)) {
int rc;
struct sockaddr_storage ss = {0};
uint32_t size = sizeof(ss);
@ -41,8 +46,7 @@ static int __getsockpeername(int fd, struct sockaddr *out_addr,
if (IsWindows()) {
if (__isfdkind(fd, kFdSocket)) {
if ((rc = impl_win32(g_fds.p[fd].handle, &ss, &size))) {
if (impl_win32 == __sys_getsockname_nt &&
WSAGetLastError() == WSAEINVAL) {
if (impl_win32 == __imp_getsockname && WSAGetLastError() == WSAEINVAL) {
// The socket has not been bound to an address with bind, or
// ADDR_ANY is specified in bind but connection has not yet
// occurred. -MSDN
@ -78,7 +82,7 @@ static int __getsockpeername(int fd, struct sockaddr *out_addr,
*/
int getsockname(int fd, struct sockaddr *out_addr, uint32_t *inout_addrsize) {
return __getsockpeername(fd, out_addr, inout_addrsize, "getsockname",
__sys_getsockname, __sys_getsockname_nt);
__sys_getsockname, __imp_getsockname);
}
/**
@ -88,5 +92,5 @@ int getsockname(int fd, struct sockaddr *out_addr, uint32_t *inout_addrsize) {
*/
int getpeername(int fd, struct sockaddr *out_addr, uint32_t *inout_addrsize) {
return __getsockpeername(fd, out_addr, inout_addrsize, "getpeername",
__sys_getpeername, __sys_getpeername_nt);
__sys_getpeername, __imp_getpeername);
}

View file

@ -24,6 +24,7 @@
#include "libc/mem/mem.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/iphlpapi.h"
#include "libc/nt/thunk/msabi.h"
#include "libc/nt/winsock.h"
#include "libc/sock/internal.h"
#include "libc/sock/yoink.inc"
@ -35,6 +36,8 @@
#include "libc/sysv/consts/sock.h"
#include "libc/sysv/consts/sol.h"
__msabi extern typeof(__sys_setsockopt_nt) *const __imp_setsockopt;
/*
* ioctl(SIOCGIFCONFIG) for Windows need to access the following
* functions through weak reference. This ensure those symbols are not
@ -59,7 +62,7 @@ textwindows int sys_socket_nt(int family, int type, int protocol) {
// pydoc of this file third_party/python/Lib/test/support/__init__.py
// this needs to happen right after socket is called or it won't work
if (family == AF_INET || family == AF_INET6) {
unassert(__sys_setsockopt_nt(h, SOL_SOCKET, -5, &yes, 4) != -1);
unassert(__imp_setsockopt(h, SOL_SOCKET, -5, &yes, 4) != -1);
}
oflags = O_RDWR;