From f63ff6eb2977ce0f9d4fca9ae699ded47151f911 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sun, 4 Oct 2026 21:12:03 +0300 Subject: [PATCH 1/2] Added generated syscall identifiers. --- packages/Makefile | 5 + packages/README.md | 9 + packages/syscall.header | 4 + packages/syscall.lisp | 379 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 397 insertions(+) create mode 100644 packages/Makefile create mode 100644 packages/syscall.header create mode 100644 packages/syscall.lisp diff --git a/packages/Makefile b/packages/Makefile new file mode 100644 index 0000000..c49e455 --- /dev/null +++ b/packages/Makefile @@ -0,0 +1,5 @@ +nop: + @echo "Run make syscall to update syscall.lisp" + +syscall: + { cat syscall.header; awk '/^#define __NR_/ { name=$$2; sub(/^__NR_/, "", name); print "(defconst SYS_" name " " $$3 ")" }' /usr/include/x86_64-linux-gnu/asm/unistd_64.h; } > syscall.lisp diff --git a/packages/README.md b/packages/README.md index a1add86..a5de8b6 100644 --- a/packages/README.md +++ b/packages/README.md @@ -69,6 +69,15 @@ Property list code, included as part of `stdlib.lisp`, so there is no need to ad ``` +### syscall + +A package containing the definition of linux kernel syscall-numbers, as read from `/usr/include/x86_64-linux-gnu/asm/unistd_64.h`. + +```lisp +(require syscall) +``` + + ### tree A package containing simple AVL-tree routines, used by [our lisp interpreter](../INCEPTION.md). diff --git a/packages/syscall.header b/packages/syscall.header new file mode 100644 index 0000000..d80732d --- /dev/null +++ b/packages/syscall.header @@ -0,0 +1,4 @@ +;;; syscall-constants +;; +;; These constants define known syscalls, and are auto-generated. +;; diff --git a/packages/syscall.lisp b/packages/syscall.lisp new file mode 100644 index 0000000..ff798c7 --- /dev/null +++ b/packages/syscall.lisp @@ -0,0 +1,379 @@ +;;; syscall-constants +;; +;; These constants define known syscalls, and are auto-generated. +;; +(defconst SYS_read 0) +(defconst SYS_write 1) +(defconst SYS_open 2) +(defconst SYS_close 3) +(defconst SYS_stat 4) +(defconst SYS_fstat 5) +(defconst SYS_lstat 6) +(defconst SYS_poll 7) +(defconst SYS_lseek 8) +(defconst SYS_mmap 9) +(defconst SYS_mprotect 10) +(defconst SYS_munmap 11) +(defconst SYS_brk 12) +(defconst SYS_rt_sigaction 13) +(defconst SYS_rt_sigprocmask 14) +(defconst SYS_rt_sigreturn 15) +(defconst SYS_ioctl 16) +(defconst SYS_pread64 17) +(defconst SYS_pwrite64 18) +(defconst SYS_readv 19) +(defconst SYS_writev 20) +(defconst SYS_access 21) +(defconst SYS_pipe 22) +(defconst SYS_select 23) +(defconst SYS_sched_yield 24) +(defconst SYS_mremap 25) +(defconst SYS_msync 26) +(defconst SYS_mincore 27) +(defconst SYS_madvise 28) +(defconst SYS_shmget 29) +(defconst SYS_shmat 30) +(defconst SYS_shmctl 31) +(defconst SYS_dup 32) +(defconst SYS_dup2 33) +(defconst SYS_pause 34) +(defconst SYS_nanosleep 35) +(defconst SYS_getitimer 36) +(defconst SYS_alarm 37) +(defconst SYS_setitimer 38) +(defconst SYS_getpid 39) +(defconst SYS_sendfile 40) +(defconst SYS_socket 41) +(defconst SYS_connect 42) +(defconst SYS_accept 43) +(defconst SYS_sendto 44) +(defconst SYS_recvfrom 45) +(defconst SYS_sendmsg 46) +(defconst SYS_recvmsg 47) +(defconst SYS_shutdown 48) +(defconst SYS_bind 49) +(defconst SYS_listen 50) +(defconst SYS_getsockname 51) +(defconst SYS_getpeername 52) +(defconst SYS_socketpair 53) +(defconst SYS_setsockopt 54) +(defconst SYS_getsockopt 55) +(defconst SYS_clone 56) +(defconst SYS_fork 57) +(defconst SYS_vfork 58) +(defconst SYS_execve 59) +(defconst SYS_exit 60) +(defconst SYS_wait4 61) +(defconst SYS_kill 62) +(defconst SYS_uname 63) +(defconst SYS_semget 64) +(defconst SYS_semop 65) +(defconst SYS_semctl 66) +(defconst SYS_shmdt 67) +(defconst SYS_msgget 68) +(defconst SYS_msgsnd 69) +(defconst SYS_msgrcv 70) +(defconst SYS_msgctl 71) +(defconst SYS_fcntl 72) +(defconst SYS_flock 73) +(defconst SYS_fsync 74) +(defconst SYS_fdatasync 75) +(defconst SYS_truncate 76) +(defconst SYS_ftruncate 77) +(defconst SYS_getdents 78) +(defconst SYS_getcwd 79) +(defconst SYS_chdir 80) +(defconst SYS_fchdir 81) +(defconst SYS_rename 82) +(defconst SYS_mkdir 83) +(defconst SYS_rmdir 84) +(defconst SYS_creat 85) +(defconst SYS_link 86) +(defconst SYS_unlink 87) +(defconst SYS_symlink 88) +(defconst SYS_readlink 89) +(defconst SYS_chmod 90) +(defconst SYS_fchmod 91) +(defconst SYS_chown 92) +(defconst SYS_fchown 93) +(defconst SYS_lchown 94) +(defconst SYS_umask 95) +(defconst SYS_gettimeofday 96) +(defconst SYS_getrlimit 97) +(defconst SYS_getrusage 98) +(defconst SYS_sysinfo 99) +(defconst SYS_times 100) +(defconst SYS_ptrace 101) +(defconst SYS_getuid 102) +(defconst SYS_syslog 103) +(defconst SYS_getgid 104) +(defconst SYS_setuid 105) +(defconst SYS_setgid 106) +(defconst SYS_geteuid 107) +(defconst SYS_getegid 108) +(defconst SYS_setpgid 109) +(defconst SYS_getppid 110) +(defconst SYS_getpgrp 111) +(defconst SYS_setsid 112) +(defconst SYS_setreuid 113) +(defconst SYS_setregid 114) +(defconst SYS_getgroups 115) +(defconst SYS_setgroups 116) +(defconst SYS_setresuid 117) +(defconst SYS_getresuid 118) +(defconst SYS_setresgid 119) +(defconst SYS_getresgid 120) +(defconst SYS_getpgid 121) +(defconst SYS_setfsuid 122) +(defconst SYS_setfsgid 123) +(defconst SYS_getsid 124) +(defconst SYS_capget 125) +(defconst SYS_capset 126) +(defconst SYS_rt_sigpending 127) +(defconst SYS_rt_sigtimedwait 128) +(defconst SYS_rt_sigqueueinfo 129) +(defconst SYS_rt_sigsuspend 130) +(defconst SYS_sigaltstack 131) +(defconst SYS_utime 132) +(defconst SYS_mknod 133) +(defconst SYS_uselib 134) +(defconst SYS_personality 135) +(defconst SYS_ustat 136) +(defconst SYS_statfs 137) +(defconst SYS_fstatfs 138) +(defconst SYS_sysfs 139) +(defconst SYS_getpriority 140) +(defconst SYS_setpriority 141) +(defconst SYS_sched_setparam 142) +(defconst SYS_sched_getparam 143) +(defconst SYS_sched_setscheduler 144) +(defconst SYS_sched_getscheduler 145) +(defconst SYS_sched_get_priority_max 146) +(defconst SYS_sched_get_priority_min 147) +(defconst SYS_sched_rr_get_interval 148) +(defconst SYS_mlock 149) +(defconst SYS_munlock 150) +(defconst SYS_mlockall 151) +(defconst SYS_munlockall 152) +(defconst SYS_vhangup 153) +(defconst SYS_modify_ldt 154) +(defconst SYS_pivot_root 155) +(defconst SYS__sysctl 156) +(defconst SYS_prctl 157) +(defconst SYS_arch_prctl 158) +(defconst SYS_adjtimex 159) +(defconst SYS_setrlimit 160) +(defconst SYS_chroot 161) +(defconst SYS_sync 162) +(defconst SYS_acct 163) +(defconst SYS_settimeofday 164) +(defconst SYS_mount 165) +(defconst SYS_umount2 166) +(defconst SYS_swapon 167) +(defconst SYS_swapoff 168) +(defconst SYS_reboot 169) +(defconst SYS_sethostname 170) +(defconst SYS_setdomainname 171) +(defconst SYS_iopl 172) +(defconst SYS_ioperm 173) +(defconst SYS_create_module 174) +(defconst SYS_init_module 175) +(defconst SYS_delete_module 176) +(defconst SYS_get_kernel_syms 177) +(defconst SYS_query_module 178) +(defconst SYS_quotactl 179) +(defconst SYS_nfsservctl 180) +(defconst SYS_getpmsg 181) +(defconst SYS_putpmsg 182) +(defconst SYS_afs_syscall 183) +(defconst SYS_tuxcall 184) +(defconst SYS_security 185) +(defconst SYS_gettid 186) +(defconst SYS_readahead 187) +(defconst SYS_setxattr 188) +(defconst SYS_lsetxattr 189) +(defconst SYS_fsetxattr 190) +(defconst SYS_getxattr 191) +(defconst SYS_lgetxattr 192) +(defconst SYS_fgetxattr 193) +(defconst SYS_listxattr 194) +(defconst SYS_llistxattr 195) +(defconst SYS_flistxattr 196) +(defconst SYS_removexattr 197) +(defconst SYS_lremovexattr 198) +(defconst SYS_fremovexattr 199) +(defconst SYS_tkill 200) +(defconst SYS_time 201) +(defconst SYS_futex 202) +(defconst SYS_sched_setaffinity 203) +(defconst SYS_sched_getaffinity 204) +(defconst SYS_set_thread_area 205) +(defconst SYS_io_setup 206) +(defconst SYS_io_destroy 207) +(defconst SYS_io_getevents 208) +(defconst SYS_io_submit 209) +(defconst SYS_io_cancel 210) +(defconst SYS_get_thread_area 211) +(defconst SYS_lookup_dcookie 212) +(defconst SYS_epoll_create 213) +(defconst SYS_epoll_ctl_old 214) +(defconst SYS_epoll_wait_old 215) +(defconst SYS_remap_file_pages 216) +(defconst SYS_getdents64 217) +(defconst SYS_set_tid_address 218) +(defconst SYS_restart_syscall 219) +(defconst SYS_semtimedop 220) +(defconst SYS_fadvise64 221) +(defconst SYS_timer_create 222) +(defconst SYS_timer_settime 223) +(defconst SYS_timer_gettime 224) +(defconst SYS_timer_getoverrun 225) +(defconst SYS_timer_delete 226) +(defconst SYS_clock_settime 227) +(defconst SYS_clock_gettime 228) +(defconst SYS_clock_getres 229) +(defconst SYS_clock_nanosleep 230) +(defconst SYS_exit_group 231) +(defconst SYS_epoll_wait 232) +(defconst SYS_epoll_ctl 233) +(defconst SYS_tgkill 234) +(defconst SYS_utimes 235) +(defconst SYS_vserver 236) +(defconst SYS_mbind 237) +(defconst SYS_set_mempolicy 238) +(defconst SYS_get_mempolicy 239) +(defconst SYS_mq_open 240) +(defconst SYS_mq_unlink 241) +(defconst SYS_mq_timedsend 242) +(defconst SYS_mq_timedreceive 243) +(defconst SYS_mq_notify 244) +(defconst SYS_mq_getsetattr 245) +(defconst SYS_kexec_load 246) +(defconst SYS_waitid 247) +(defconst SYS_add_key 248) +(defconst SYS_request_key 249) +(defconst SYS_keyctl 250) +(defconst SYS_ioprio_set 251) +(defconst SYS_ioprio_get 252) +(defconst SYS_inotify_init 253) +(defconst SYS_inotify_add_watch 254) +(defconst SYS_inotify_rm_watch 255) +(defconst SYS_migrate_pages 256) +(defconst SYS_openat 257) +(defconst SYS_mkdirat 258) +(defconst SYS_mknodat 259) +(defconst SYS_fchownat 260) +(defconst SYS_futimesat 261) +(defconst SYS_newfstatat 262) +(defconst SYS_unlinkat 263) +(defconst SYS_renameat 264) +(defconst SYS_linkat 265) +(defconst SYS_symlinkat 266) +(defconst SYS_readlinkat 267) +(defconst SYS_fchmodat 268) +(defconst SYS_faccessat 269) +(defconst SYS_pselect6 270) +(defconst SYS_ppoll 271) +(defconst SYS_unshare 272) +(defconst SYS_set_robust_list 273) +(defconst SYS_get_robust_list 274) +(defconst SYS_splice 275) +(defconst SYS_tee 276) +(defconst SYS_sync_file_range 277) +(defconst SYS_vmsplice 278) +(defconst SYS_move_pages 279) +(defconst SYS_utimensat 280) +(defconst SYS_epoll_pwait 281) +(defconst SYS_signalfd 282) +(defconst SYS_timerfd_create 283) +(defconst SYS_eventfd 284) +(defconst SYS_fallocate 285) +(defconst SYS_timerfd_settime 286) +(defconst SYS_timerfd_gettime 287) +(defconst SYS_accept4 288) +(defconst SYS_signalfd4 289) +(defconst SYS_eventfd2 290) +(defconst SYS_epoll_create1 291) +(defconst SYS_dup3 292) +(defconst SYS_pipe2 293) +(defconst SYS_inotify_init1 294) +(defconst SYS_preadv 295) +(defconst SYS_pwritev 296) +(defconst SYS_rt_tgsigqueueinfo 297) +(defconst SYS_perf_event_open 298) +(defconst SYS_recvmmsg 299) +(defconst SYS_fanotify_init 300) +(defconst SYS_fanotify_mark 301) +(defconst SYS_prlimit64 302) +(defconst SYS_name_to_handle_at 303) +(defconst SYS_open_by_handle_at 304) +(defconst SYS_clock_adjtime 305) +(defconst SYS_syncfs 306) +(defconst SYS_sendmmsg 307) +(defconst SYS_setns 308) +(defconst SYS_getcpu 309) +(defconst SYS_process_vm_readv 310) +(defconst SYS_process_vm_writev 311) +(defconst SYS_kcmp 312) +(defconst SYS_finit_module 313) +(defconst SYS_sched_setattr 314) +(defconst SYS_sched_getattr 315) +(defconst SYS_renameat2 316) +(defconst SYS_seccomp 317) +(defconst SYS_getrandom 318) +(defconst SYS_memfd_create 319) +(defconst SYS_kexec_file_load 320) +(defconst SYS_bpf 321) +(defconst SYS_execveat 322) +(defconst SYS_userfaultfd 323) +(defconst SYS_membarrier 324) +(defconst SYS_mlock2 325) +(defconst SYS_copy_file_range 326) +(defconst SYS_preadv2 327) +(defconst SYS_pwritev2 328) +(defconst SYS_pkey_mprotect 329) +(defconst SYS_pkey_alloc 330) +(defconst SYS_pkey_free 331) +(defconst SYS_statx 332) +(defconst SYS_io_pgetevents 333) +(defconst SYS_rseq 334) +(defconst SYS_uretprobe 335) +(defconst SYS_pidfd_send_signal 424) +(defconst SYS_io_uring_setup 425) +(defconst SYS_io_uring_enter 426) +(defconst SYS_io_uring_register 427) +(defconst SYS_open_tree 428) +(defconst SYS_move_mount 429) +(defconst SYS_fsopen 430) +(defconst SYS_fsconfig 431) +(defconst SYS_fsmount 432) +(defconst SYS_fspick 433) +(defconst SYS_pidfd_open 434) +(defconst SYS_clone3 435) +(defconst SYS_close_range 436) +(defconst SYS_openat2 437) +(defconst SYS_pidfd_getfd 438) +(defconst SYS_faccessat2 439) +(defconst SYS_process_madvise 440) +(defconst SYS_epoll_pwait2 441) +(defconst SYS_mount_setattr 442) +(defconst SYS_quotactl_fd 443) +(defconst SYS_landlock_create_ruleset 444) +(defconst SYS_landlock_add_rule 445) +(defconst SYS_landlock_restrict_self 446) +(defconst SYS_memfd_secret 447) +(defconst SYS_process_mrelease 448) +(defconst SYS_futex_waitv 449) +(defconst SYS_set_mempolicy_home_node 450) +(defconst SYS_cachestat 451) +(defconst SYS_fchmodat2 452) +(defconst SYS_map_shadow_stack 453) +(defconst SYS_futex_wake 454) +(defconst SYS_futex_wait 455) +(defconst SYS_futex_requeue 456) +(defconst SYS_statmount 457) +(defconst SYS_listmount 458) +(defconst SYS_lsm_get_self_attr 459) +(defconst SYS_lsm_set_self_attr 460) +(defconst SYS_lsm_list_modules 461) +(defconst SYS_mseal 462) From 87b29e92436da205e46b1dbce918a7abdda8481f Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sun, 4 Oct 2026 21:15:27 +0300 Subject: [PATCH 2/2] Avoid hardcoding syscall IDs, and import the library that defines them --- stdlib.slisp | 46 ++-------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/stdlib.slisp b/stdlib.slisp index 6d65768..fe0a3ce 100644 --- a/stdlib.slisp +++ b/stdlib.slisp @@ -322,7 +322,8 @@ The first argument is the number of the function to call, after that the argumen "Is the given item nil?" (nil? x)) - +;; Ensure we have our syscall IDs defined +(require syscall) ;;; 2. Printing @@ -383,8 +384,6 @@ do the right thing for each entry in the given list." (if (= 1 (car res)) t)))) -(defconst SYS_getdents64 217) - (defconst O_RDONLY 0) (defconst O_DIRECTORY 65536) @@ -456,8 +455,6 @@ The implementation here is either horrid, or awesome. You decide." "Does the named path exist?" (cons? (stat path))) -(defconst SYS_close 3) - (defun fclose (handle) "Close the given handle. @@ -472,8 +469,6 @@ As a special case closing a NIL file-handle is valid" nil))) (t (do (println "Calling fclose with an invalid handle-type") (exit 1))))) -(defconst SYS_open 2) - (defun fopen (str mode) "Open a file with the given mode. @@ -490,9 +485,7 @@ Mode is \"r\" for read, \"w\" for write, and \"a\" for append." handle nil))) -(defconst SYS_lseek 8) (defconst SEEK_END 2) - (defconst SEEK_START 0) (defun fread (handle) @@ -514,8 +507,6 @@ It is assumed the filehandle came from fopen, but nil is also accepted." nil mem)))))))) -(defconst SYS_write 1) - (defun fwrite (handle data len) "Write the given data, of length LEN, to the specified file-handle. @@ -534,8 +525,6 @@ It is assumed the filehandle came from fopen, but nil is also accepted." (if (= 0 (car res)) t)))) -(defconst SYS_mkdir 83) - (defun mkdir (path) "Make the given directory. @@ -568,8 +557,6 @@ Note that this does not create parents, use (mkdirs) for that." (join (list (car res) "/" binary))))) -(defconst SYS_rmdir 84) - (defun rmdir (path) (if (< (syscall SYS_rmdir path) 0) nil @@ -599,8 +586,6 @@ Note that this does not create parents, use (mkdirs) for that." (defun u64! (buf pos val) (sys_u64! buf pos val)) -(defconst SYS_stat 4) - (defun stat (path) "Return details of the given filesystem entry. @@ -628,8 +613,6 @@ This returns a list of the form (TYPE SIZE MODE)." ) (list type size mode))))))) ; return the list -(defconst SYS_unlink 87) - (defun unlink (path) "Delete the given file from the filesystem. @@ -1219,8 +1202,6 @@ Incrementing by the given step each time." ;; These are functions which are designed to interface with the ;; system environment more than just with File I/O -(defconst SYS_read 0) - ;; undocumented (defun lst2array (lst) "Convert a lisp list to a C-style array of strings" @@ -1233,8 +1214,6 @@ Incrementing by the given step each time." (u64! m (* i 8) 0) m)) -(defconst SYS_chdir 80) - (defun cd (path) "Change to the given working directory" (if (< (syscall SYS_chdir path) 0) @@ -1263,32 +1242,24 @@ Uses (environment) to get all environmental variables, and filters." (getenv-loop name (cdr xs)))) nil)) -(defconst SYS_getgid 104) - (defun getgid () "Return the group ID of the current user." (let ((res (syscall SYS_getgid))) (if (< res 0) nil res ))) -(defconst SYS_getpid 39) - (defun getpid () "Return the process ID of the current process." (let ((res (syscall SYS_getpid))) (if (< res 0) nil res ))) -(defconst SYS_getuid 102) - (defun getuid () "Return the ID of the current user." (let ((res (syscall SYS_getuid))) (if (< res 0) nil res ))) -(defconst SYS_uname 63) - (defun hostname () "Return the system hostname, via the uname syscall." (let ((len 1024) @@ -1303,8 +1274,6 @@ Uses (environment) to get all environmental variables, and filters." (set! i (+ i 1))) hst)))) -(defconst SYS_clock_gettime 228) - (defun now () "Return the number of milliseconds since the Unix EPOCH." (let ((buffer (alloc 16))) @@ -1323,8 +1292,6 @@ Uses (environment) to get all environmental variables, and filters." ((int? c) (syscall 1 1 (string (chr (& 255 c))) 1)) (t (do (println "putc called with bogus arg") (exit 1))))) -(defconst SYS_getcwd 79) - (defun pwd () "Return the current working directory" (let ((len 1024) @@ -1332,9 +1299,6 @@ Uses (environment) to get all environmental variables, and filters." (if (>= (syscall SYS_getcwd buf len) 0) buf nil))) - -(defconst SYS_getrandom 318) - (defun random (n) "Return a random number between zero and N-1, (both zero and N-1 are valid return values.) @@ -1370,12 +1334,6 @@ The newline which terminates input is not included." (set! text (strcat text (string (chr ch))))))) text)) -(defconst SYS_fork 57) -(defconst SYS_execve 59) -(defconst SYS_dup2 33) -(defconst SYS_wait4 61) -(defconst SYS_exit 60) - ;; shell to use for running system commands. (defvar sys_run_shell "/bin/sh")