From d91f5e82634dbb57346d78c2588be34059199e04 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Mon, 22 Apr 2024 11:58:14 +0100 Subject: [PATCH] Fix `syscall` calls Use named constants instead of just integers --- tests/simple_fopen.c | 5 +++-- tests/simple_syscall_getpid.c | 3 ++- tests/simple_syscall_write.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/simple_fopen.c b/tests/simple_fopen.c index c123458..6409763 100644 --- a/tests/simple_fopen.c +++ b/tests/simple_fopen.c @@ -2,6 +2,7 @@ #include #include #include +#include #include void @@ -18,12 +19,12 @@ by_fopen() void by_syscall() { - int fd = syscall(5, "tmp", O_CREAT); // open + int fd = syscall(SYS_open, "tmp", O_CREAT); // open if (fd == -1) { err(1, "Error in open: "); } - syscall(6, fd); // close + syscall(SYS_close, fd); // close } void diff --git a/tests/simple_syscall_getpid.c b/tests/simple_syscall_getpid.c index 4956dfa..3bae87e 100644 --- a/tests/simple_syscall_getpid.c +++ b/tests/simple_syscall_getpid.c @@ -1,10 +1,11 @@ #include +#include #include int main(void) { - long int sc_pid = syscall(20); + long int sc_pid = syscall(SYS_getpid); pid_t pid = getpid(); assert(pid == sc_pid); return 0; diff --git a/tests/simple_syscall_write.c b/tests/simple_syscall_write.c index 119cd45..44d35f2 100644 --- a/tests/simple_syscall_write.c +++ b/tests/simple_syscall_write.c @@ -1,12 +1,13 @@ #include #include +#include #include int main(void) { char *buf = "Hello World!\n"; - long int sc_write = syscall(4, STDOUT_FILENO, buf, strlen(buf)); + long int sc_write = syscall(SYS_write, STDOUT_FILENO, buf, strlen(buf)); if (sc_write == -1) { err(1, "Error calling `syscall`:");