From 7baf078eafbaf68194b79ab96ca6754496b43258 Mon Sep 17 00:00:00 2001 From: HeatCrab Date: Tue, 3 Feb 2026 20:23:52 +0800 Subject: [PATCH] Fix POSIX syscall handling for consistency The heap allocation syscall had an implementation incompatible with the kernel's fixed-size heap design, changed to a proper stub to match other unsupported POSIX syscalls. Also added file descriptor validation in I/O syscalls to reject unsupported values beyond standard streams. --- kernel/syscall.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/kernel/syscall.c b/kernel/syscall.c index 8ad87e0..3313774 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -116,24 +116,12 @@ static int _getpid(void) return 1; } +/* linmo uses fixed heap via mo_heap_init, sbrk is not applicable */ static int _sbrk(int incr) { - extern uint32_t _end, _stack; - static char *brk = (char *) &_end; - char *prev = brk; - - if (unlikely(incr < 0)) { - errno = EINVAL; - return -1; - } - - if (unlikely(brk + incr >= (char *) &_stack)) { - errno = ENOMEM; - return -1; - } - - brk += incr; - return (int) prev; + (void) incr; + errno = ENOMEM; + return -1; } static int _usleep(int usec) @@ -180,7 +168,7 @@ static int _read(int file, char *ptr, int len) return -1; } - if (unlikely(file < 0)) { + if (unlikely(file < 0 || file > 2)) { errno = EBADF; return -1; } @@ -199,7 +187,7 @@ static int _write(int file, char *ptr, int len) return -1; } - if (unlikely(file < 0)) { + if (unlikely(file < 0 || file > 2)) { errno = EBADF; return -1; }