From 56846e2ddde98b6db7cbda456e905291a5cdb74b Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Wed, 11 Feb 2026 23:40:17 -0300 Subject: [PATCH] feat: fsync/fdatasync syscall stubs (no-op, POSIX compliance) --- include/syscall.h | 10 ++++++++++ src/kernel/syscall.c | 10 ++++++++++ user/ulibc/include/syscall.h | 2 ++ user/ulibc/include/unistd.h | 2 ++ user/ulibc/src/unistd.c | 8 ++++++++ 5 files changed, 32 insertions(+) diff --git a/include/syscall.h b/include/syscall.h index 170396d..3e3a36e 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -91,6 +91,16 @@ enum { SYSCALL_CLONE = 67, SYSCALL_GETTID = 68, + + SYSCALL_FSYNC = 69, + SYSCALL_FDATASYNC = 70, + SYSCALL_SIGPENDING = 71, + SYSCALL_PREAD = 72, + SYSCALL_PWRITE = 73, + SYSCALL_ACCESS = 74, + SYSCALL_UMASK = 75, + SYSCALL_SETUID = 76, + SYSCALL_SETGID = 77, }; #endif diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index 4e42df9..8f0b4ea 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -2200,6 +2200,16 @@ void syscall_handler(struct registers* regs) { return; } + if (syscall_no == SYSCALL_FSYNC || syscall_no == SYSCALL_FDATASYNC) { + int fd = (int)regs->ebx; + if (!current_process || fd < 0 || fd >= PROCESS_MAX_FILES || !current_process->files[fd]) { + regs->eax = (uint32_t)-EBADF; + } else { + regs->eax = 0; + } + return; + } + /* ---- Socket syscalls ---- */ socket_syscall_dispatch(regs, syscall_no); /* If socket dispatch handled it, eax is set and we return. diff --git a/user/ulibc/include/syscall.h b/user/ulibc/include/syscall.h index 3671aed..ec1e847 100644 --- a/user/ulibc/include/syscall.h +++ b/user/ulibc/include/syscall.h @@ -51,6 +51,8 @@ enum { SYS_SET_THREAD_AREA = 57, SYS_CLONE = 67, SYS_GETTID = 68, + SYS_FSYNC = 69, + SYS_FDATASYNC = 70, }; /* Raw syscall wrappers — up to 5 args via INT 0x80 */ diff --git a/user/ulibc/include/unistd.h b/user/ulibc/include/unistd.h index fe873cf..70a818f 100644 --- a/user/ulibc/include/unistd.h +++ b/user/ulibc/include/unistd.h @@ -33,6 +33,8 @@ int setsid(void); int setpgid(int pid, int pgid); int getpgrp(void); int gettid(void); +int fsync(int fd); +int fdatasync(int fd); void* brk(void* addr); void _exit(int status) __attribute__((noreturn)); diff --git a/user/ulibc/src/unistd.c b/user/ulibc/src/unistd.c index 2ae0979..06ce1b6 100644 --- a/user/ulibc/src/unistd.c +++ b/user/ulibc/src/unistd.c @@ -86,6 +86,14 @@ int gettid(void) { return _syscall0(SYS_GETTID); } +int fsync(int fd) { + return __syscall_ret(_syscall1(SYS_FSYNC, fd)); +} + +int fdatasync(int fd) { + return __syscall_ret(_syscall1(SYS_FDATASYNC, fd)); +} + void* brk(void* addr) { return (void*)_syscall1(SYS_BRK, (int)addr); } -- 2.43.0