commit 84939a022b9e03adb81a7e61d8d805a54f085659
parent 2678aca0d2ebde08c0e1228c626603da87f0a64c
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Sun, 21 Dec 2025 00:44:03 +0000
Fix x86_64
Diffstat:
9 files changed, 43 insertions(+), 99 deletions(-)
diff --git a/aarch64.s b/aarch64.s
@@ -25,78 +25,5 @@ syscall 63 read
syscall 64 write
syscall 56 openat
syscall 57 close
+syscall 93 exit
syscall 222 mmap
-
-/*
-syscall 4 stat
-syscall 5 fstat
-syscall 6 lstat
-syscall 7 poll
-syscall 8 lseek
-syscall 222 mmap
-syscall 10 mprotect
-syscall 11 munmap
-syscall 12 brk
-syscall 13 rt_sigaction
-syscall 14 rt_sigprocmask
-syscall 15 rt_sigreturn
-syscall 16 ioctl
-syscall 17 pread64
-syscall 18 pwrite64
-syscall 19 readv
-syscall 20 writev
-syscall 21 access
-syscall 22 pipe
-syscall 23 select
-syscall 24 yield
-syscall 25 mremap
-syscall 26 msync
-syscall 27 mincore
-syscall 28 madvise
-syscall 29 shmget
-syscall 30 shmat
-syscall 31 shmctl
-syscall 32 dup
-syscall 33 dup2
-syscall 34 pause
-syscall 35 nanosleep
-syscall 36 getitimer
-syscall 37 alarm
-syscall 38 setitimer
-syscall 39 getpid
-syscall 40 sendfile
-syscall 41 socket
-syscall 42 connect
-syscall 43 accept
-syscall 44 sendto
-syscall 45 recvfrom
-syscall 46 sendmsg
-syscall 47 recvmsg
-syscall 48 shutdown
-syscall 49 bind
-syscall 50 listen
-syscall 51 getsockname
-syscall 52 getpeername
-syscall 53 socketpair
-syscall 54 setsockopt
-syscall 55 getsockopt
-syscall 56 clone
-syscall 57 fork
-syscall 58 vfork
-syscall 59 execve
-*/
-
-.section .text.exit
-exit: # mov x0, r0
- mov w8, #93
- svc #0
-
-/*
-syscall 61 wait4
-syscall 62 kill
-syscall 63 uname
-syscall 64 semget
-syscall 65 semop
-
-syscall 77 ftruncate
-*/
diff --git a/cat.c b/cat.c
@@ -1,4 +1,4 @@
-#include "syscall.h"
+#include "linux.h"
static void cat(int fd)
{
@@ -20,7 +20,7 @@ int main(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i)
{
- int fd = openat(-100, argv[i], 0, /*O_RDONLY*/0);
+ int fd = openat(AT_FDCWD, argv[i], 0, /*O_RDONLY*/0);
if (fd < 0)
return 1;
cat(fd);
diff --git a/echo.c b/echo.c
@@ -1,4 +1,4 @@
-#include "syscall.h"
+#include "linux.h"
static struct
{
diff --git a/linux.h b/linux.h
@@ -0,0 +1,33 @@
+#pragma once
+
+typedef unsigned long long size_t;
+typedef signed long long ssize_t;
+typedef unsigned long long uintptr_t;
+typedef signed long long intptr_t;
+
+enum {
+ AT_FDCWD = -100,
+
+ O_RDONLY = 0,
+ O_WRONLY = 1,
+ O_RDWR = 2,
+
+ PROT_READ = 0x1,
+ PROT_WRITE = 0x2,
+ PROT_EXEC = 0x4,
+ MAP_FIXED = 0x10,
+ MAP_ANONYMOUS = 0x20,
+ MAP_SHARED = 0x1,
+ MAP_PRIVATE = 0x2,
+};
+
+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/paste.c b/paste.c
@@ -1,5 +1,4 @@
-#include "syscall.h"
-#include <linux/mman.h>
+#include "linux.h"
struct input
{
@@ -28,7 +27,7 @@ int main(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i)
{
- int fd = openat(-100, argv[i], 0, 0);
+ int fd = openat(AT_FDCWD, argv[i], 0, 0);
if (fd < 0)
return 1;
struct input* m = mmap(mappable + n_inputs++, sizeof(struct input), PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
diff --git a/syscall.h b/syscall.h
@@ -1,14 +0,0 @@
-#include <stddef.h>
-
-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);
-
-extern void* brk(void* new_brk);
-
-__attribute__((noreturn))
-extern void exit(int error_code);
-
-extern int ftruncate(int fd, unsigned long length);
diff --git a/tac.c b/tac.c
@@ -1,6 +1,4 @@
-#define _SYS_MMAN_H
-#include "syscall.h"
-#include <bits/mman-linux.h>
+#include "linux.h"
extern char mappable[];
@@ -39,7 +37,7 @@ int main()
while (len == cap)
{
void* m = mmap(buf + cap, cap ?: 0x1000, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- if ((long long)m < 0)
+ if ((intptr_t)m < 0)
return 1;
cap += cap ?: 0x1000;
diff --git a/test.c b/test.c
@@ -1,4 +1,4 @@
-#include "syscall.h"
+#include "linux.h"
char const rodata[] = "rodata\n";
char data[] = "data\n";
diff --git a/x86_64.s b/x86_64.s
@@ -112,3 +112,4 @@ syscall3 64 semget
syscall3 65 semop
syscall3 77 ftruncate
+syscall6 257 openat