]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: flock() syscall (87) — advisory file locking no-op stub + ulibc wrapper
authorTulio A M Mendes <[email protected]>
Thu, 12 Feb 2026 04:05:00 +0000 (01:05 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:20:50 +0000 (23:20 -0300)
include/syscall.h
src/kernel/syscall.c
user/ulibc/include/syscall.h
user/ulibc/include/unistd.h
user/ulibc/src/unistd.c

index 9f16ebcd12e44a976c9bfbec7944b0694ab58378..33d63ba4d0a23f40c4b80e3c05099f147aff8c22 100644 (file)
@@ -110,6 +110,7 @@ enum {
     SYSCALL_TIMES     = 84,
     SYSCALL_FUTEX     = 85,
     SYSCALL_SIGALTSTACK = 86,
+    SYSCALL_FLOCK     = 87,
 };
 
 #endif
index c2940b70086a76d734cbd792729078f8d07e6de5..b876c4efec192a8105c51c54aab75c87ba56a438 100644 (file)
@@ -2272,6 +2272,16 @@ void syscall_handler(struct registers* regs) {
         return;
     }
 
+    if (syscall_no == SYSCALL_FLOCK) {
+        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; /* advisory lock — no-op stub */
+        }
+        return;
+    }
+
     if (syscall_no == SYSCALL_SIGALTSTACK ||
         syscall_no == SYSCALL_TIMES || syscall_no == SYSCALL_FUTEX) {
         posix_ext_syscall_dispatch(regs, syscall_no);
index 568e79fabfb9e7817492f1353df9721e6ef007b4..f322fddbe526d561e28be633933291f16a46442d 100644 (file)
@@ -69,6 +69,7 @@ enum {
     SYS_TIMES = 84,
     SYS_FUTEX = 85,
     SYS_SIGALTSTACK = 86,
+    SYS_FLOCK = 87,
 };
 
 /* Raw syscall wrappers — up to 5 args via INT 0x80 */
index e2bb132d8dc5816a6b3b4568e8c780334b9d9117..e9934174a6ed3bb6cf15c13732784ca466e70b77 100644 (file)
@@ -43,6 +43,11 @@ int     setgid(int gid);
 int     truncate(const char* path, int length);
 int     ftruncate(int fd, int length);
 unsigned int alarm(unsigned int seconds);
+#define LOCK_SH 1
+#define LOCK_EX 2
+#define LOCK_UN 8
+#define LOCK_NB 4
+int     flock(int fd, int operation);
 void*   brk(void* addr);
 
 void    _exit(int status) __attribute__((noreturn));
index 609de9f9736dd4c7306869a1052e99bd1edaede6..8d6294c20637a14befe7b79ac1598e53b639fc50 100644 (file)
@@ -126,6 +126,10 @@ unsigned int alarm(unsigned int seconds) {
     return (unsigned int)_syscall1(SYS_ALARM, (int)seconds);
 }
 
+int flock(int fd, int operation) {
+    return __syscall_ret(_syscall2(SYS_FLOCK, fd, operation));
+}
+
 void* brk(void* addr) {
     return (void*)_syscall1(SYS_BRK, (int)addr);
 }