]> 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 b8380e48c21b582ccdad89bb138a94f804aef963..5ed6cf6d90daaf46c5da986cd3dc04baaa85d69c 100644 (file)
@@ -119,6 +119,7 @@ enum {
     SYSCALL_TIMES     = 84,
     SYSCALL_FUTEX     = 85,
     SYSCALL_SIGALTSTACK = 86,
+    SYSCALL_FLOCK     = 87,
 };
 
 #endif
index e346592c53e1a283bae7ad14a84f0f0a8cea9055..bb27741ce3a623038eb23c89c26235675849b4c6 100644 (file)
@@ -2281,6 +2281,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 51ec5a77e8fc86515a85da483362af734017c554..9c0cfaf2181115f0a96642285676932febd4c673 100644 (file)
@@ -78,6 +78,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 6b480f8456695b4b65407eddc20fd41a27d85744..2d170c09d8e3e7e3b7e98c85b88fb99001c79668 100644 (file)
@@ -52,6 +52,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 7ffeb054af137b1c0b857e7836f0ed1063f0f376..c6a37787b1582ed32f41b81a2fef7147dcebc8cf 100644 (file)
@@ -135,6 +135,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);
 }