commit 528829c7f8919c34edae11b46a8582c775fa5882
parent 84939a022b9e03adb81a7e61d8d805a54f085659
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Sun, 21 Dec 2025 01:02:18 +0000
Tidy up x86_64 syscalls
Diffstat:
| M | linux.h | | | 7 | ++----- |
| M | x86_64.s | | | 103 | +++++++++++++++---------------------------------------------------------------- |
2 files changed, 21 insertions(+), 89 deletions(-)
diff --git a/linux.h b/linux.h
@@ -21,13 +21,10 @@ enum {
MAP_PRIVATE = 0x2,
};
+__attribute__((noreturn))
+extern void exit(int error_code);
extern int read(int fd, char* data, size_t count);
extern int write(int fd, char const* data, size_t count);
extern int openat(int fd, char const* name, int flags, int mode);
extern int close(int fd);
extern void* mmap(void* addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long off);
-
-__attribute__((noreturn))
-extern void exit(int error_code);
-
-extern int ftruncate(int fd, unsigned long length);
diff --git a/x86_64.s b/x86_64.s
@@ -12,104 +12,39 @@ start: # start is the entry point known to the linker
mov rdi, rax
jmp exit
-.macro syscall3, num, name
+.macro _syscall, num, impl, name
.global \name
.section .text.\name
\name:
+ mov rax, \num
+ jmp \impl
+.endm
+
+syscall3:
push r11
push rcx
- mov rax, \num
syscall
pop rcx
pop r11
ret
-.endm
-.macro syscall6, num, name
-.global \name
-.section .text.\name
-\name:
+syscall6:
push r11
- mov rax, \num
mov r10, rcx
syscall
pop r11
ret
-.endm
-.text
-.global exit
-
-syscall3 0 read
-syscall3 1 write
-syscall3 2 open
-syscall3 3 close
-syscall3 4 stat
-syscall3 5 fstat
-syscall3 6 lstat
-syscall3 7 poll
-syscall3 8 lseek
-syscall6 9 mmap
-syscall3 10 mprotect
-syscall3 11 munmap
-syscall3 12 brk
-syscall6 13 rt_sigaction
-syscall6 14 rt_sigprocmask
-syscall3 15 rt_sigreturn
-syscall3 16 ioctl
-syscall6 17 pread64
-syscall6 18 pwrite64
-syscall3 19 readv
-syscall3 20 writev
-syscall3 21 access
-syscall3 22 pipe
-syscall6 23 select
-syscall3 24 yield
-syscall6 25 mremap
-syscall3 26 msync
-syscall3 27 mincore
-syscall3 28 madvise
-syscall3 29 shmget
-syscall3 30 shmat
-syscall3 31 shmctl
-syscall3 32 dup
-syscall3 33 dup2
-syscall3 34 pause
-syscall3 35 nanosleep
-syscall3 36 getitimer
-syscall3 37 alarm
-syscall3 38 setitimer
-syscall3 39 getpid
-syscall6 40 sendfile
-syscall3 41 socket
-syscall3 42 connect
-syscall3 43 accept
-syscall6 44 sendto
-syscall6 45 recvfrom
-syscall3 46 sendmsg
-syscall3 47 recvmsg
-syscall3 48 shutdown
-syscall3 49 bind
-syscall3 50 listen
-syscall3 51 getsockname
-syscall3 52 getpeername
-syscall3 53 socketpair
-syscall6 54 setsockopt
-syscall6 55 getsockopt
-syscall3 56 clone
-syscall3 57 fork
-syscall3 58 vfork
-syscall3 59 execve
-
-.section .text.exit
-exit: mov rax, 60
- syscall
-
-syscall6 61 wait4
-syscall3 62 kill
-syscall3 63 uname
-syscall3 64 semget
-syscall3 65 semop
+.macro syscall6, num, name
+.global \name
+.section .text.\name
+\name:
+ mov rax, \num
+.endm
-syscall3 77 ftruncate
-syscall6 257 openat
+_syscall 0 syscall3 read
+_syscall 1 syscall3 write
+_syscall 3 syscall3 close
+_syscall 9 syscall6 mmap
+_syscall 60 syscall3 exit
+_syscall 257 syscall6 openat