Files
nt-lite/code/user/syscall/syscall_stubs.asm
T
maksw 73abd6f90d isolate POSIX builds from the host UCRT, wire lwext4 and ntfs-3g as ext4.sys and ntfs.sys, split the FAT driver into directory/file/async/driver/mount units, add posixsrv and dwm plus input/console/desktop syscall clients and a pile of new smoke targets, rename serial.sys to cereal.sys, name HDA/USB/lwIP/AHCI workers, harden ATA probing/reset/removal around actual hardware deadlines, absent-channel detection, diagnostics and explicit worker lifetime, redo ACPI S5 shutdown around GAS/MMIO and HW-reduced firmware, scan SSDTs for _S5 and deal with Intel SMI sleep trapping, make serial and SMP timeouts use real monotonic deadlines, add thread names and fix terminal thread teardown, scheduler and APC prepare/commit races, make advisory file locks queryable and preserve split ranges and add mutable file append state, add shared-memory pipes with kernel-assisted wait/wake, introduce capability-scoped input and display managers, split surface map rights into read/write, add explicit unmap and replace present with commit/generation/damage tracking while keeping physical presentation under the display manager, decouple native exception classes from Win32 exception numbers and translate them in kernel32, add opaque process startup data, bump the resource protocol to v3 with namespace directories, symlinks and enumeration and service control to v2 with generic READY handle exports, add the new POSIX errno/status surface and rebuild fds around posixsrv-owned shared open descriptions, descriptor-local flags, exact inheritance snapshots, dup/fcntl/record locks and shared-ring pipes, add waitpid, POSIX credentials/groups/sessions/passwd/group lookups and move sockets onto stable open descriptions, port the shells and apps to the new console/input services and surface commit API, teach init to load services.ini and start/supervise RSSRV, DWM and generic services under restricted capabilities while publishing their endpoints through RSSRV, split RSSRV into namespace, volume, display, session, input, console and resource components and make /SystemRoot a real symlink to the independently published system volume, shift the syscall table again, expand lock/resource/surface/POSIX/service/thread smoke coverage, make docs scream ASK QUESTIONS and DISCUSS at LLMs, replace MIT No Attribution with WTFPL+.
2026-09-16 10:33:20 +02:00

298 lines
14 KiB
NASM

; syscall_stubs.asm - user-mode INT 0x40 stubs for syscall.dll and syscall_s.lib (MASM64)
;
; Calling convention:
; RAX = syscall number.
; RCX = arg 0.
; RDX = arg 1.
; R8 = arg 2.
; R9 = arg 3.
;
; Syscalls never consume stack arguments. Operations that need more than four
; logical arguments use a request structure.
INCLUDE syscall_nr.inc
SYS_USER_APC_FRAME_Magic EQU 0
SYS_USER_APC_FRAME_ReturnToken EQU 8
SYS_USER_APC_FRAME_Routine EQU 16
SYS_USER_APC_FRAME_NormalContext EQU 24
SYS_USER_APC_FRAME_SystemArgument1 EQU 32
SYS_USER_APC_FRAME_SystemArgument2 EQU 40
.CODE
; ---------------------------------------------------------------------------
SYSCALL_STUB MACRO name, nr
PUBLIC Sys&name
IFDEF NTL_SYSCALL_STATIC
Sys&name PROC
ELSE
Sys&name PROC EXPORT
ENDIF
mov rax, nr
int 40h
ret
Sys&name ENDP
ENDM
; ---------------------------------------------------------------------------
; Process & thread lifecycle
; ---------------------------------------------------------------------------
SYSCALL_STUB ExitProcess, SYS_EXIT_PROCESS
SYSCALL_STUB ExitThread, SYS_EXIT_THREAD
SYSCALL_STUB CreateProcessObject, SYS_CREATE_PROCESS_OBJECT
SYSCALL_STUB AllocProcessVm, SYS_ALLOC_PROCESS_VM
SYSCALL_STUB ProtectProcessVm, SYS_PROTECT_PROCESS_VM
SYSCALL_STUB StartProcess, SYS_START_PROCESS
SYSCALL_STUB WaitSingle, SYS_WAIT_SINGLE
SYSCALL_STUB WaitMany, SYS_WAIT_MANY
SYSCALL_STUB OpenInputQueue, SYS_OPEN_INPUT_QUEUE
SYSCALL_STUB GetProcessExitCode, SYS_GET_PROCESS_EXIT_CODE
SYSCALL_STUB OpenProcess, SYS_OPEN_PROCESS
SYSCALL_STUB KillProcess, SYS_KILL_PROCESS
SYSCALL_STUB GetProcessList, SYS_GET_PROCESS_LIST
SYSCALL_STUB GetProcessPid, SYS_GET_PROCESS_PID
SYSCALL_STUB GetThreadList, SYS_GET_THREAD_LIST
SYSCALL_STUB CreateThread, SYS_CREATE_THREAD
SYSCALL_STUB ResumeThread, SYS_RESUME_THREAD
SYSCALL_STUB GetCurrentTid, SYS_GET_CURRENT_TID
SYSCALL_STUB GetCurrentPid, SYS_GET_CURRENT_PID
SYSCALL_STUB SetThreadPriority, SYS_SET_THREAD_PRIORITY
SYSCALL_STUB SetThreadName, SYS_SET_THREAD_NAME
SYSCALL_STUB QueryThreadName, SYS_QUERY_THREAD_NAME
SYSCALL_STUB Yield, SYS_YIELD
SYSCALL_STUB Sleep, SYS_SLEEP
SYSCALL_STUB SetUserApcDispatcher, SYS_SET_USER_APC_DISPATCHER
SYSCALL_STUB ApcReturn, SYS_APC_RETURN
SYSCALL_STUB SetExceptionDispatcher, SYS_SET_EXCEPTION_DISPATCHER
SYSCALL_STUB GetExceptionDispatcher, SYS_GET_EXCEPTION_DISPATCHER
SYSCALL_STUB ContinueException, SYS_CONTINUE_EXCEPTION
SYSCALL_STUB RaiseException, SYS_RAISE_EXCEPTION
; ---------------------------------------------------------------------------
; User APC dispatcher
; ---------------------------------------------------------------------------
PUBLIC SysUserApcDispatcher
IFDEF NTL_SYSCALL_STATIC
SysUserApcDispatcher PROC
ELSE
SysUserApcDispatcher PROC EXPORT
ENDIF
; Kernel enters here with RSP pointing at SYS_USER_APC_FRAME. There is no
; return address because this is an IRET redirection. Preserve RBX because
; the original user context resumes after SysApcReturn.
push rbx
lea rbx, [rsp + 8] ; original injected RSP = frame pointer
sub rsp, 32 ; shadow space; RSP is already call-aligned
mov rcx, [rbx + SYS_USER_APC_FRAME_NormalContext]
mov rdx, [rbx + SYS_USER_APC_FRAME_SystemArgument1]
mov r8, [rbx + SYS_USER_APC_FRAME_SystemArgument2]
mov rax, [rbx + SYS_USER_APC_FRAME_Routine]
call rax
add rsp, 32
mov rcx, rbx ; SysApcReturn(frame)
mov rbx, [rsp] ; restore original user RBX
add rsp, 8
mov rax, SYS_APC_RETURN
int 40h
SysUserApcDispatcher_Failed:
jmp SysUserApcDispatcher_Failed
SysUserApcDispatcher ENDP
; ---------------------------------------------------------------------------
; Virtual memory and handles
; ---------------------------------------------------------------------------
SYSCALL_STUB AllocVm, SYS_ALLOC_VM
SYSCALL_STUB FreeVm, SYS_FREE_VM
SYSCALL_STUB ProtectVm, SYS_PROTECT_VM
SYSCALL_STUB QueryVm, SYS_QUERY_VM
SYSCALL_STUB CloseHandle, SYS_CLOSE_HANDLE
SYSCALL_STUB DuplicateHandle, SYS_DUPLICATE_HANDLE
SYSCALL_STUB DeriveHandle, SYS_DERIVE_HANDLE
SYSCALL_STUB RevokeHandle, SYS_REVOKE_HANDLE
SYSCALL_STUB DeriveSecurityContext, SYS_DERIVE_SECURITY_CONTEXT
SYSCALL_STUB QuerySecurityContext, SYS_QUERY_SECURITY_CONTEXT
; ---------------------------------------------------------------------------
; Synchronization objects
; ---------------------------------------------------------------------------
SYSCALL_STUB CreateMutex, SYS_CREATE_MUTEX
SYSCALL_STUB TryAcquireMutex, SYS_TRY_ACQUIRE_MUTEX
SYSCALL_STUB ReleaseMutex, SYS_RELEASE_MUTEX
SYSCALL_STUB CreateSem, SYS_CREATE_SEM
SYSCALL_STUB TryWaitSem, SYS_TRY_WAIT_SEM
SYSCALL_STUB SignalSem, SYS_SIGNAL_SEM
SYSCALL_STUB CreateEvent, SYS_CREATE_EVENT
SYSCALL_STUB SignalEvent, SYS_SIGNAL_EVENT
SYSCALL_STUB ClearEvent, SYS_CLEAR_EVENT
; ---------------------------------------------------------------------------
; Queues and named queues
; ---------------------------------------------------------------------------
SYSCALL_STUB CreateQueue, SYS_CREATE_QUEUE
SYSCALL_STUB SendQueue, SYS_SEND_QUEUE
SYSCALL_STUB RecvQueue, SYS_RECV_QUEUE
SYSCALL_STUB PublishQueue, SYS_PUBLISH_QUEUE
SYSCALL_STUB UnpublishQueue, SYS_UNPUBLISH_QUEUE
SYSCALL_STUB OpenNamedQueue, SYS_OPEN_NAMED_QUEUE
SYSCALL_STUB OpenNamedQueueOwnerProcess, SYS_OPEN_NAMED_QUEUE_OWNER_PROCESS
; ---------------------------------------------------------------------------
; LPC-like Ports and well-known system services
; ---------------------------------------------------------------------------
SYSCALL_STUB CreatePort, SYS_CREATE_PORT
SYSCALL_STUB ConnectPort, SYS_CONNECT_PORT
SYSCALL_STUB AcceptPort, SYS_ACCEPT_PORT
SYSCALL_STUB SendPort, SYS_SEND_PORT
SYSCALL_STUB ReceivePort, SYS_RECEIVE_PORT
SYSCALL_STUB CallPort, SYS_CALL_PORT
SYSCALL_STUB ReplyPort, SYS_REPLY_PORT
SYSCALL_STUB DisconnectPort, SYS_DISCONNECT_PORT
SYSCALL_STUB RegisterSystemService, SYS_REGISTER_SYSTEM_SERVICE
SYSCALL_STUB UnregisterSystemService, SYS_UNREGISTER_SYSTEM_SERVICE
SYSCALL_STUB ConnectSystemService, SYS_CONNECT_SYSTEM_SERVICE
; ---------------------------------------------------------------------------
; Mounted-volume manager control plane
; ---------------------------------------------------------------------------
SYSCALL_STUB QueryVolumes, SYS_QUERY_VOLUMES
SYSCALL_STUB OpenVolume, SYS_OPEN_VOLUME
SYSCALL_STUB WaitVolumeChange, SYS_WAIT_VOLUME_CHANGE
; ---------------------------------------------------------------------------
; Files and directories
; ---------------------------------------------------------------------------
SYSCALL_STUB OpenFileAt, SYS_OPEN_FILE_AT
SYSCALL_STUB OpenDirAt, SYS_OPEN_DIR_AT
SYSCALL_STUB StatAt, SYS_STAT_AT
SYSCALL_STUB DeleteAt, SYS_DELETE_AT
SYSCALL_STUB RenameAt, SYS_RENAME_AT
SYSCALL_STUB CreateDirAt, SYS_CREATE_DIR_AT
SYSCALL_STUB RemoveDirAt, SYS_REMOVE_DIR_AT
SYSCALL_STUB ReadFile, SYS_READ_FILE
SYSCALL_STUB WriteFile, SYS_WRITE_FILE
SYSCALL_STUB ReadFileAsync, SYS_READ_FILE_ASYNC
SYSCALL_STUB WriteFileAsync, SYS_WRITE_FILE_ASYNC
SYSCALL_STUB CancelIo, SYS_CANCEL_IO
SYSCALL_STUB SeekFile, SYS_SEEK_FILE
SYSCALL_STUB GetFilePos, SYS_GET_FILE_POS
SYSCALL_STUB GetFileSize, SYS_GET_FILE_SIZE
SYSCALL_STUB GetFileStat, SYS_GET_FILE_STAT
SYSCALL_STUB TruncateFile, SYS_TRUNCATE_FILE
SYSCALL_STUB FlushFile, SYS_FLUSH_FILE
SYSCALL_STUB LockFile, SYS_LOCK_FILE
SYSCALL_STUB UnlockFile, SYS_UNLOCK_FILE
SYSCALL_STUB QueryFileLock, SYS_QUERY_FILE_LOCK
SYSCALL_STUB SetFileStatus, SYS_SET_FILE_STATUS
SYSCALL_STUB CreatePipe, SYS_CREATE_PIPE
SYSCALL_STUB NotifyPipe, SYS_NOTIFY_PIPE
SYSCALL_STUB ReadDir, SYS_READ_DIR
; ---------------------------------------------------------------------------
; Console and graphics
; ---------------------------------------------------------------------------
SYSCALL_STUB WriteConsole, SYS_WRITE_CONSOLE
SYSCALL_STUB GetConsoleInfo, SYS_GET_CONSOLE_INFO
SYSCALL_STUB SetConsoleCursor, SYS_SET_CONSOLE_CURSOR
SYSCALL_STUB FillConsoleCharacter, SYS_FILL_CONSOLE_CHARACTER
SYSCALL_STUB FillConsoleAttribute, SYS_FILL_CONSOLE_ATTRIBUTE
SYSCALL_STUB PutScreenChar, SYS_PUT_SCREEN_CHAR
SYSCALL_STUB CreateSurface, SYS_CREATE_SURFACE
SYSCALL_STUB MapSurface, SYS_MAP_SURFACE
SYSCALL_STUB UnmapSurface, SYS_UNMAP_SURFACE
SYSCALL_STUB QuerySurface, SYS_QUERY_SURFACE
SYSCALL_STUB CommitSurface, SYS_COMMIT_SURFACE
SYSCALL_STUB ClearScreen, SYS_CLEAR_SCREEN
SYSCALL_STUB GetScreenSize, SYS_GET_SCREEN_SIZE
SYSCALL_STUB QueryDisplayInfo, SYS_QUERY_DISPLAY_INFO
SYSCALL_STUB QueryDisplayManagerInfo, SYS_QUERY_DISPLAY_MANAGER_INFO
SYSCALL_STUB PresentDisplayManagerSurface, SYS_PRESENT_DISPLAY_MANAGER_SURFACE
SYSCALL_STUB SetDisplayManagerCursor, SYS_SET_DISPLAY_MANAGER_CURSOR
SYSCALL_STUB WriteDisplayManagerConsole, SYS_WRITE_DISPLAY_MANAGER_CONSOLE
SYSCALL_STUB QueryDisplayManagerConsoleInfo, SYS_QUERY_DISPLAY_MANAGER_CONSOLE_INFO
SYSCALL_STUB SetDisplayManagerConsoleCursor, SYS_SET_DISPLAY_MANAGER_CONSOLE_CURSOR
SYSCALL_STUB FillDisplayManagerConsoleCharacter, SYS_FILL_DISPLAY_MANAGER_CONSOLE_CHARACTER
SYSCALL_STUB FillDisplayManagerConsoleAttribute, SYS_FILL_DISPLAY_MANAGER_CONSOLE_ATTRIBUTE
SYSCALL_STUB PutDisplayManagerConsoleCharacter, SYS_PUT_DISPLAY_MANAGER_CONSOLE_CHARACTER
SYSCALL_STUB ClearDisplayManagerConsole, SYS_CLEAR_DISPLAY_MANAGER_CONSOLE
SYSCALL_STUB OpenDisplayClock, SYS_OPEN_DISPLAY_CLOCK
; ---------------------------------------------------------------------------
; Native render audio
; ---------------------------------------------------------------------------
SYSCALL_STUB AudioEnumerateEndpoints, SYS_AUDIO_ENUMERATE_ENDPOINTS
SYSCALL_STUB AudioOpenStream, SYS_AUDIO_OPEN_STREAM
SYSCALL_STUB AudioWrite, SYS_AUDIO_WRITE
SYSCALL_STUB AudioArmWait, SYS_AUDIO_ARM_WAIT
SYSCALL_STUB AudioQueryStream, SYS_AUDIO_QUERY_STREAM
SYSCALL_STUB AudioStart, SYS_AUDIO_START
SYSCALL_STUB AudioPause, SYS_AUDIO_PAUSE
SYSCALL_STUB AudioResume, SYS_AUDIO_RESUME
SYSCALL_STUB AudioDrain, SYS_AUDIO_DRAIN
SYSCALL_STUB AudioStop, SYS_AUDIO_STOP
SYSCALL_STUB AudioReset, SYS_AUDIO_RESET
SYSCALL_STUB AudioSetVolume, SYS_AUDIO_SET_VOLUME
SYSCALL_STUB AudioSetMasterVolume, SYS_AUDIO_SET_MASTER_VOLUME
; ---------------------------------------------------------------------------
; Input
; ---------------------------------------------------------------------------
SYSCALL_STUB ReadInputManagerEvent, SYS_READ_INPUT_MANAGER_EVENT
SYSCALL_STUB PollKeyboard, SYS_POLL_KEYBOARD
SYSCALL_STUB IsKeyDown, SYS_IS_KEY_DOWN
SYSCALL_STUB ReadKeyboardChar, SYS_READ_KEYBOARD_CHAR
SYSCALL_STUB ReadKey, SYS_READ_KEY
SYSCALL_STUB GetKeyModifiers, SYS_GET_KEY_MODIFIERS
SYSCALL_STUB QueryGlobalInputState, SYS_QUERY_GLOBAL_INPUT_STATE
SYSCALL_STUB ReadInputEvent, SYS_READ_INPUT_EVENT
SYSCALL_STUB PeekInputEvent, SYS_PEEK_INPUT_EVENT
SYSCALL_STUB PeekMouse, SYS_PEEK_MOUSE
SYSCALL_STUB ReadMouse, SYS_READ_MOUSE
SYSCALL_STUB GetMousePos, SYS_GET_MOUSE_POS
; ---------------------------------------------------------------------------
; Time and debug
; ---------------------------------------------------------------------------
SYSCALL_STUB CreateTimer, SYS_CREATE_TIMER
SYSCALL_STUB SetTimer, SYS_SET_TIMER
SYSCALL_STUB CancelTimer, SYS_CANCEL_TIMER
SYSCALL_STUB GetTick, SYS_GET_TICK
SYSCALL_STUB GetTickFrequency, SYS_GET_TICK_FREQUENCY
SYSCALL_STUB PrintDebug, SYS_PRINT_DEBUG
SYSCALL_STUB QueryTrapFrame, SYS_QUERY_TRAP_FRAME
; ---------------------------------------------------------------------------
; Native sockets
; ---------------------------------------------------------------------------
SYSCALL_STUB CreateSocket, SYS_CREATE_SOCKET
SYSCALL_STUB SocketIoAsync, SYS_SOCKET_IO_ASYNC
SYSCALL_STUB BindSocket, SYS_BIND_SOCKET
SYSCALL_STUB ListenSocket, SYS_LISTEN_SOCKET
SYSCALL_STUB AcceptSocket, SYS_ACCEPT_SOCKET
SYSCALL_STUB ConnectSocket, SYS_CONNECT_SOCKET
SYSCALL_STUB SendSocket, SYS_SEND_SOCKET
SYSCALL_STUB RecvSocket, SYS_RECV_SOCKET
SYSCALL_STUB ShutdownSocket, SYS_SHUTDOWN_SOCKET
SYSCALL_STUB SendToSocket, SYS_SEND_TO_SOCKET
SYSCALL_STUB RecvFromSocket, SYS_RECV_FROM_SOCKET
SYSCALL_STUB ResolveHost, SYS_RESOLVE_HOST
SYSCALL_STUB SetSocketOption, SYS_SET_SOCKET_OPTION
SYSCALL_STUB GetSocketOption, SYS_GET_SOCKET_OPTION
SYSCALL_STUB Poll, SYS_POLL
SYSCALL_STUB GetMemoryStatus, SYS_GET_MEMORY_STATUS
SYSCALL_STUB QueryKernelStats, SYS_QUERY_KERNEL_STATS
SYSCALL_STUB GetSystemTime, SYS_GET_SYSTEM_TIME
SYSCALL_STUB CreateFileMapping, SYS_CREATE_FILE_MAPPING
SYSCALL_STUB MapFile, SYS_MAP_FILE
END