evocation/unix-like-syscalls.e
2026-09-24 17:47:58 +03:00

30 lines
983 B
Text

~ Raw system calls
~ ~~~~~~~~~~~~~~~~
~ See constants-*.e for the SYS_* words' definitions.
~ This does the Linux exit() system call, passing it an exit code taken
~ from the stack. It does not return.
~
~ (exit code -- *)
: sys-exit SYS_exit syscall-1
~ In the event we're still here, let's minimize confusion.
crash ;
~ This does the Linux write() system call, passing it an address from the
~ top of the stack and a length from the second position on the stack. It
~ uses a Unix file descriptor, which is a non-negative integer, to tell it
~ where to write to. For stdout, use fd 1.
~
~ (file descriptor, base address, length to write -- result code or length)
: sys-write SYS_write syscall-3 ;
~ (file descriptor, base address, length to read -- result code or length)
: sys-read SYS_read syscall-3 ;
~ (filename, flags, mode -- result code or file descriptor)
: sys-open SYS_open syscall-3 ;
~ (file descriptor -- result code)
: sys-close SYS_close syscall-1 ;