From 09a9518b9b73c0255fbc9193951c6dc7c1275fba Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 28 Aug 2025 16:55:52 +0200 Subject: [PATCH 01/14] change syscall number to correct ones --- so3/arch/arm32/include/asm/syscall_number.h | 106 ++++++++++--------- so3/arch/arm64/include/asm/syscall_number.h | 108 +++++++++++--------- 2 files changed, 119 insertions(+), 95 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 1da6a2f71..a3349efc2 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -24,61 +24,75 @@ */ #define SYSCALL_EXIT 1 -#define SYSCALL_EXECVE 2 -#define SYSCALL_WAITPID 3 -#define SYSCALL_READ 4 -#define SYSCALL_WRITE 5 -#define SYSCALL_FORK 7 -#define SYSCALL_PTRACE 8 -#define SYSCALL_READDIR 9 -#define SYSCALL_OPEN 14 -#define SYSCALL_CLOSE 15 -#define SYSCALL_THREAD_CREATE 16 -#define SYSCALL_THREAD_JOIN 17 -#define SYSCALL_THREAD_EXIT 18 -#define SYSCALL_PIPE 19 -#define SYSCALL_IOCTL 20 -#define SYSCALL_FCNTL 21 -#define SYSCALL_DUP 22 -#define SYSCALL_DUP2 23 - -#define SYSCALL_SOCKET 26 -#define SYSCALL_BIND 27 -#define SYSCALL_LISTEN 28 -#define SYSCALL_ACCEPT 29 -#define SYSCALL_CONNECT 30 -#define SYSCALL_RECV 31 -#define SYSCALL_SEND 32 -#define SYSCALL_SENDTO 33 - -#define SYSCALL_STAT 34 -#define SYSCALL_MMAP 35 -#define SYSCALL_GETPID 37 - -#define SYSCALL_GETTIMEOFDAY 38 -#define SYSCALL_SETTIMEOFDAY 39 -#define SYSCALL_CLOCK_GETTIME 40 +#define SYSCALL_FORK 2 +#define SYSCALL_READ 3 +#define SYSCALL_WRITE 4 +#define SYSCALL_OPEN 5 // Add mode +#define SYSCALL_CLOSE 6 -#define SYSCALL_THREAD_YIELD 43 +#define SYSCALL_EXECVE 11 -#define SYSCALL_SBRK 45 -#define SYSCALL_SIGACTION 46 -#define SYSCALL_KILL 47 -#define SYSCALL_SIGRETURN 48 +#define SYSCALL_LSEEK 19 +#define SYSCALL_GETPID 20 -#define SYSCALL_LSEEK 50 +#define SYSCALL_PTRACE 26 -#define SYSCALL_MUTEX_LOCK 60 -#define SYSCALL_MUTEX_UNLOCK 61 +#define SYSCALL_KILL 37 + +#define SYSCALL_DUP 41 -#define SYSCALL_NANOSLEEP 70 +#define SYSCALL_SBRK 45 // => brk +#define SYSCALL_PIPE 46 -#define SYSCALL_SYSINFO 99 +#define SYSCALL_IOCTL 54 +#define SYSCALL_FCNTL 55 // fcntl64? -#define SYSCALL_SETSOCKOPT 110 -#define SYSCALL_RECVFROM 111 +#define SYSCALL_DUP2 63 +#define SYSCALL_SIGACTION 67 + +#define SYSCALL_GETTIMEOFDAY 78 // Add _time32 +#define SYSCALL_SETTIMEOFDAY 79 // Implement? + +#define SYSCALL_STAT 106 + +#define SYSCALL_SYSINFO 116 // => struct sysinfo + +#define SYSCALL_SIGRETURN 119 #define SYSCALL_READV 145 #define SYSCALL_WRITEV 146 +#define SYSCALL_NANOSLEEP 162 + +#define SYSCALL_CLOCK_GETTIME 263 // 32 and 64 + +#define SYSCALL_SOCKET 281 +#define SYSCALL_BIND 282 +#define SYSCALL_CONNECT 283 +#define SYSCALL_LISTEN 284 +#define SYSCALL_ACCEPT 285 + +#define SYSCALL_SEND 289 +#define SYSCALL_SENDTO 290 + +#define SYSCALL_RECV 291 +#define SYSCALL_RECVFROM 292 + +#define SYSCALL_SETSOCKOPT 294 + +// Does not exist +#define SYSCALL_WAITPID 3 // => wait4? +#define SYSCALL_READDIR 9 // getdents + 64? +#define SYSCALL_MMAP 222 // => mmap2 + +// => pthread +#define SYSCALL_THREAD_CREATE 16 +#define SYSCALL_THREAD_JOIN 17 +#define SYSCALL_THREAD_EXIT 18 +#define SYSCALL_THREAD_YIELD 43 + +// => ??? +#define SYSCALL_MUTEX_LOCK 60 +#define SYSCALL_MUTEX_UNLOCK 61 + #endif /* ARCH_ARM32_SYSCALL_NUMBER_H */ diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 2cbbea82d..c2b8f9e86 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -22,63 +22,73 @@ /* * Syscall number definition */ +#define SYSCALL_DUP 23 -#define SYSCALL_EXIT 1 -#define SYSCALL_EXECVE 2 -#define SYSCALL_WAITPID 3 -#define SYSCALL_READ 4 -#define SYSCALL_WRITE 5 -#define SYSCALL_FORK 7 -#define SYSCALL_PTRACE 8 -#define SYSCALL_READDIR 9 -#define SYSCALL_OPEN 14 -#define SYSCALL_CLOSE 15 -#define SYSCALL_THREAD_CREATE 16 -#define SYSCALL_THREAD_JOIN 17 -#define SYSCALL_THREAD_EXIT 18 -#define SYSCALL_PIPE 19 -#define SYSCALL_IOCTL 20 -#define SYSCALL_FCNTL 21 -#define SYSCALL_DUP 22 -#define SYSCALL_DUP2 23 - -#define SYSCALL_SOCKET 26 -#define SYSCALL_BIND 27 -#define SYSCALL_LISTEN 28 -#define SYSCALL_ACCEPT 29 -#define SYSCALL_CONNECT 30 -#define SYSCALL_RECV 31 -#define SYSCALL_SEND 32 -#define SYSCALL_SENDTO 33 - -#define SYSCALL_STAT 34 -#define SYSCALL_MMAP 35 -#define SYSCALL_GETPID 37 - -#define SYSCALL_GETTIMEOFDAY 38 -#define SYSCALL_SETTIMEOFDAY 39 -#define SYSCALL_CLOCK_GETTIME 40 +#define SYSCALL_FCNTL 25 -#define SYSCALL_THREAD_YIELD 43 +#define SYSCALL_IOCTL 29 -#define SYSCALL_SBRK 45 -#define SYSCALL_SIGACTION 46 -#define SYSCALL_KILL 47 -#define SYSCALL_SIGRETURN 48 - -#define SYSCALL_LSEEK 50 - -#define SYSCALL_MUTEX_LOCK 60 -#define SYSCALL_MUTEX_UNLOCK 61 +#define SYSCALL_CLOSE 57 +#define SYSCALL_LSEEK 62 +#define SYSCALL_READ 63 +#define SYSCALL_WRITE 64 #define SYSCALL_READV 65 #define SYSCALL_WRITEV 66 -#define SYSCALL_NANOSLEEP 70 +#define SYSCALL_EXIT 93 + +#define SYSCALL_NANOSLEEP 101 + +#define SYSCALL_CLOCK_GETTIME 113 + +#define SYSCALL_PTRACE 117 + +#define SYSCALL_KILL 129 + +#define SYSCALL_GETTIMEOFDAY 169 // Add timezone +#define SYSCALL_SETTIMEOFDAY 170 // Implement? + +#define SYSCALL_GETPID 172 -#define SYSCALL_SYSINFO 99 +#define SYSCALL_SYSINFO 179 // => struct sysinfo -#define SYSCALL_SETSOCKOPT 110 -#define SYSCALL_RECVFROM 111 +#define SYSCALL_SOCKET 198 + +#define SYSCALL_BIND 200 +#define SYSCALL_LISTEN 201 +#define SYSCALL_ACCEPT 202 +#define SYSCALL_CONNECT 203 + +#define SYSCALL_SENDTO 206 +#define SYSCALL_RECVFROM 207 +#define SYSCALL_SETSOCKOPT 208 + +#define SYSCALL_SBRK 214 // => brk + +#define SYSCALL_EXECVE 221 +#define SYSCALL_MMAP 222 + +// Does not exist +#define SYSCALL_WAITPID 3 // => wait4? +#define SYSCALL_FORK 7 // => clone +#define SYSCALL_READDIR 9 // getdents64 +#define SYSCALL_OPEN 5 // => openat +#define SYSCALL_PIPE 19 // => pipe2 +#define SYSCALL_DUP2 23 // => dup3 +#define SYSCALL_SEND 32 // => sendto +#define SYSCALL_SIGACTION 46 // => rt_sigaction + +#define SYSCALL_STAT 34 // ???? +#define SYSCALL_SIGRETURN 48 // ????? + +#define SYSCALL_THREAD_CREATE 16 +#define SYSCALL_THREAD_JOIN 17 +#define SYSCALL_THREAD_EXIT 18 +#define SYSCALL_THREAD_YIELD 43 + +// => ??? +#define SYSCALL_MUTEX_LOCK 60 +#define SYSCALL_MUTEX_UNLOCK 61 #endif /* ARCH_ARM64_SYSCALL_NUMBER_H */ From cc2016feaadc7b623118557876f0484260cad81c Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 28 Aug 2025 17:29:24 +0200 Subject: [PATCH 02/14] rename sbrk to brk --- so3/arch/arm32/include/asm/syscall_number.h | 2 +- so3/arch/arm64/include/asm/syscall_number.h | 2 +- so3/include/process.h | 2 +- so3/kernel/process.c | 2 +- so3/kernel/syscalls.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index a3349efc2..6c0aa8779 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -41,7 +41,7 @@ #define SYSCALL_DUP 41 -#define SYSCALL_SBRK 45 // => brk +#define SYSCALL_BRK 45 #define SYSCALL_PIPE 46 #define SYSCALL_IOCTL 54 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index c2b8f9e86..aca168114 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -64,7 +64,7 @@ #define SYSCALL_RECVFROM 207 #define SYSCALL_SETSOCKOPT 208 -#define SYSCALL_SBRK 214 // => brk +#define SYSCALL_BRK 214 #define SYSCALL_EXECVE 221 #define SYSCALL_MMAP 222 diff --git a/so3/include/process.h b/so3/include/process.h index 83fceefe7..368d67b00 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -153,6 +153,6 @@ void dump_proc(void); extern int __exec(const char *file); extern int __write(int fd, char *buffer, int count); -SYSCALL_DECLARE(sbrk, int increment); +SYSCALL_DECLARE(brk, int increment); #endif /* PROCESS_H */ diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 21a21f628..52a9d7596 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -1088,7 +1088,7 @@ SYSCALL_DEFINE3(waitpid, int, pid, uint32_t *, wstatus, uint32_t, options) * @return This function will the position of the end of the heap / program *break before increment */ -SYSCALL_DEFINE1(sbrk, int, increment) +SYSCALL_DEFINE1(brk, int, increment) { pcb_t *pcb = current()->pcb; int ret_pointer; diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 68e15083f..c46b81a83 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -71,7 +71,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_MMAP] = __sys_mmap, [SYSCALL_NANOSLEEP] = __sys_nanosleep, #ifdef CONFIG_PROC_ENV - [SYSCALL_SBRK] = __sys_sbrk, + [SYSCALL_BRK] = __sys_brk, #endif [SYSCALL_MUTEX_LOCK] = __sys_mutex_lock, [SYSCALL_MUTEX_UNLOCK] = __sys_mutex_unlock, From 0a7427622b4e3ad972b842db1f31a02fe7fd265d Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 28 Aug 2025 17:42:32 +0200 Subject: [PATCH 03/14] add dup3 simple implementation --- so3/arch/arm32/include/asm/syscall_number.h | 2 ++ so3/arch/arm64/include/asm/syscall_number.h | 2 +- so3/fs/vfs.c | 14 ++++++++++++++ so3/include/vfs.h | 1 + so3/kernel/syscalls.c | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 6c0aa8779..ed56d1dfc 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -80,6 +80,8 @@ #define SYSCALL_SETSOCKOPT 294 +#define SYSCALL_DUP3 358 + // Does not exist #define SYSCALL_WAITPID 3 // => wait4? #define SYSCALL_READDIR 9 // getdents + 64? diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index aca168114..8b5a29a9c 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -23,6 +23,7 @@ * Syscall number definition */ #define SYSCALL_DUP 23 +#define SYSCALL_DUP3 24 #define SYSCALL_FCNTL 25 @@ -75,7 +76,6 @@ #define SYSCALL_READDIR 9 // getdents64 #define SYSCALL_OPEN 5 // => openat #define SYSCALL_PIPE 19 // => pipe2 -#define SYSCALL_DUP2 23 // => dup3 #define SYSCALL_SEND 32 // => sendto #define SYSCALL_SIGACTION 46 // => rt_sigaction diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 7c0ee97bb..d032d3e96 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -715,6 +715,20 @@ SYSCALL_DEFINE1(close, int, fd) return 0; } +SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) +{ + if (oldfd == newfd) { + set_errno(EINVAL); + return -1; + } + + if (flags != 0) { + LOG_WARNING("Flags not supported.\n"); + } + + return do_dup2(oldfd, newfd); +} + /** * @brief dup2 creates a synonym of oldfd on newfd * diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 89430c6c4..99d5a68ac 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -167,6 +167,7 @@ SYSCALL_DECLARE(readdir, int fd, char *buf, int len); SYSCALL_DECLARE(close, int fd); SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); +SYSCALL_DECLARE(dup3, int oldfd, int newfd, int flags); SYSCALL_DECLARE(stat, const char *path, struct stat *st); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index c46b81a83..cf82d60e5 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -66,7 +66,10 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_PIPE] = __sys_pipe, #endif [SYSCALL_DUP] = __sys_dup, +#ifdef SYSCALL_DUP2 [SYSCALL_DUP2] = __sys_dup2, +#endif + [SYSCALL_DUP3] = __sys_dup3, [SYSCALL_STAT] = __sys_stat, [SYSCALL_MMAP] = __sys_mmap, [SYSCALL_NANOSLEEP] = __sys_nanosleep, From 0759ba5d3cbf4b10862f1ac225b87b7f47a81307 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 2 Sep 2025 13:49:40 +0200 Subject: [PATCH 04/14] implement time32 version for clock_gettime and gettimeofday --- so3/arch/arm32/include/asm/syscall_number.h | 10 +++--- so3/arch/arm64/include/asm/syscall_number.h | 6 ++-- so3/include/device/timer.h | 10 ++++++ so3/include/timer.h | 4 ++- so3/include/types.h | 1 + so3/kernel/timer.c | 38 +++++++++++++++++++-- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index ed56d1dfc..20f2965aa 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -50,12 +50,12 @@ #define SYSCALL_DUP2 63 #define SYSCALL_SIGACTION 67 -#define SYSCALL_GETTIMEOFDAY 78 // Add _time32 -#define SYSCALL_SETTIMEOFDAY 79 // Implement? +#define SYSCALL_GETTIMEOFDAY_TIME32 78 +// #define SYSCALL_SETTIMEOFDAY 79 // Implement? #define SYSCALL_STAT 106 -#define SYSCALL_SYSINFO 116 // => struct sysinfo +// #define SYSCALL_SYSINFO 116 // => struct sysinfo #define SYSCALL_SIGRETURN 119 @@ -64,7 +64,7 @@ #define SYSCALL_NANOSLEEP 162 -#define SYSCALL_CLOCK_GETTIME 263 // 32 and 64 +#define SYSCALL_CLOCK_GETTIME32 263 #define SYSCALL_SOCKET 281 #define SYSCALL_BIND 282 @@ -82,6 +82,8 @@ #define SYSCALL_DUP3 358 +#define SYSCALL_CLOCK_GETTIME64 403 + // Does not exist #define SYSCALL_WAITPID 3 // => wait4? #define SYSCALL_READDIR 9 // getdents + 64? diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 8b5a29a9c..f8b0eb35e 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -47,12 +47,12 @@ #define SYSCALL_KILL 129 -#define SYSCALL_GETTIMEOFDAY 169 // Add timezone -#define SYSCALL_SETTIMEOFDAY 170 // Implement? +#define SYSCALL_GETTIMEOFDAY 169 +// #define SYSCALL_SETTIMEOFDAY 170 // Implement? #define SYSCALL_GETPID 172 -#define SYSCALL_SYSINFO 179 // => struct sysinfo +// #define SYSCALL_SYSINFO 179 // => struct sysinfo #define SYSCALL_SOCKET 198 diff --git a/so3/include/device/timer.h b/so3/include/device/timer.h index d159e6bb1..e8c213cb6 100644 --- a/so3/include/device/timer.h +++ b/so3/include/device/timer.h @@ -27,11 +27,21 @@ /* Time conversion units */ +struct timespec32 { + time32_t tv_sec; /* seconds */ + time32_t tv_nsec; /* nanoseconds */ +}; + struct timespec { time_t tv_sec; /* seconds */ time_t tv_nsec; /* nanoseconds */ }; +struct timeval32 { + time32_t tv_sec; /* seconds */ + time32_t tv_usec; /* microseconds */ +}; + struct timeval { time_t tv_sec; /* seconds */ time_t tv_usec; /* microseconds */ diff --git a/so3/include/timer.h b/so3/include/timer.h index bb125c666..8905046a0 100644 --- a/so3/include/timer.h +++ b/so3/include/timer.h @@ -128,7 +128,9 @@ void clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec) SYSCALL_DECLARE(nanosleep, const struct timespec *req, struct timespec *rem); -SYSCALL_DECLARE(gettimeofday, struct timespec *tv); +SYSCALL_DECLARE(gettimeofday_time32, struct timeval32 *tv, void *tz); +SYSCALL_DECLARE(gettimeofday, struct timeval *tv, void *tz); +SYSCALL_DECLARE(clock_gettime32, int clk_id, struct timespec32 *ts); SYSCALL_DECLARE(clock_gettime, int clk_id, struct timespec *ts); #ifdef CONFIG_AVZ diff --git a/so3/include/types.h b/so3/include/types.h index b128206fe..b12fad6fd 100644 --- a/so3/include/types.h +++ b/so3/include/types.h @@ -116,6 +116,7 @@ typedef __u32 __bitwise __wsum; typedef unsigned __bitwise__ gfp_t; +typedef u32 time32_t; typedef u64 time_t; #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) diff --git a/so3/kernel/timer.c b/so3/kernel/timer.c index 3c2173ca4..7ff452d1e 100644 --- a/so3/kernel/timer.c +++ b/so3/kernel/timer.c @@ -405,10 +405,28 @@ void timer_init(void) #endif } +SYSCALL_DEFINE2(gettimeofday_time32, struct timeval32 *, ts, void *, tz) +{ + struct timeval time64; + + long ret = do_gettimeofday(&time64, NULL); + + if (ret < 0) { + return ret; + } + + ts->tv_sec = (time32_t) time64.tv_sec; + ts->tv_usec = (time32_t) time64.tv_usec; + + return 0; +} + /* * This function gets the current time and put it in the parameter tv + * + * Timezone (tz) is ignored */ -SYSCALL_DEFINE1(gettimeofday, struct timespec *, ts) +SYSCALL_DEFINE2(gettimeofday, struct timeval *, ts, void *, tz) { u64 time; @@ -419,7 +437,23 @@ SYSCALL_DEFINE1(gettimeofday, struct timespec *, ts) time = NOW(); ts->tv_sec = time / (time_t) 1000000000; - ts->tv_nsec = time; + ts->tv_usec = time / (time_t) 1000; + + return 0; +} + +SYSCALL_DEFINE2(clock_gettime32, int, clk_id, struct timespec32 *, ts) +{ + struct timespec time64; + + long ret = do_clock_gettime(clk_id, &time64); + + if (ret < 0) { + return ret; + } + + ts->tv_sec = (time32_t) time64.tv_sec; + ts->tv_nsec = (time32_t) time64.tv_nsec; return 0; } From 41b182a80483fd7ed67d5a536fe392b3691fd38c Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 2 Sep 2025 15:44:03 +0200 Subject: [PATCH 05/14] wait4 and getdents --- so3/arch/arm32/include/asm/syscall_number.h | 6 ++++-- so3/arch/arm64/include/asm/syscall_number.h | 4 ++-- so3/fs/vfs.c | 2 +- so3/include/process.h | 2 +- so3/include/vfs.h | 2 +- so3/kernel/process.c | 6 ++++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 20f2965aa..bff2e042d 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -64,6 +64,10 @@ #define SYSCALL_NANOSLEEP 162 +#define SYSCALL_GETDENTS64 217 + +#define SYSCALL_WAIT4 260 + #define SYSCALL_CLOCK_GETTIME32 263 #define SYSCALL_SOCKET 281 @@ -85,8 +89,6 @@ #define SYSCALL_CLOCK_GETTIME64 403 // Does not exist -#define SYSCALL_WAITPID 3 // => wait4? -#define SYSCALL_READDIR 9 // getdents + 64? #define SYSCALL_MMAP 222 // => mmap2 // => pthread diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index f8b0eb35e..f706f59ed 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -31,6 +31,7 @@ #define SYSCALL_CLOSE 57 +#define SYSCALL_GETDENTS64 61 #define SYSCALL_LSEEK 62 #define SYSCALL_READ 63 #define SYSCALL_WRITE 64 @@ -42,6 +43,7 @@ #define SYSCALL_NANOSLEEP 101 #define SYSCALL_CLOCK_GETTIME 113 +#define SYSCALL_WAIT4 114 #define SYSCALL_PTRACE 117 @@ -71,9 +73,7 @@ #define SYSCALL_MMAP 222 // Does not exist -#define SYSCALL_WAITPID 3 // => wait4? #define SYSCALL_FORK 7 // => clone -#define SYSCALL_READDIR 9 // getdents64 #define SYSCALL_OPEN 5 // => openat #define SYSCALL_PIPE 19 // => pipe2 #define SYSCALL_SEND 32 // => sendto diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index d032d3e96..0345502bf 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -616,7 +616,7 @@ SYSCALL_DEFINE2(open, const char *, filename, int, flags) * @brief readdir read a directory entry which will be stored in a struct dirent entry * @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace. */ -SYSCALL_DEFINE3(readdir, int, fd, char *, buf, int, len) +SYSCALL_DEFINE3(getdents64, int, fd, char *, buf, size_t, len) { struct dirent *dirent; int gfd; diff --git a/so3/include/process.h b/so3/include/process.h index 368d67b00..62f2273f3 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -142,7 +142,7 @@ SYSCALL_DECLARE(getpid, void); SYSCALL_DECLARE(execve, const char *filename, char **argv, char **envp); SYSCALL_DECLARE(fork, void); SYSCALL_DECLARE(exit, int exit_status); -SYSCALL_DECLARE(waitpid, int pid, uint32_t *wstatus, uint32_t options); +SYSCALL_DECLARE(wait4, int pid, uint32_t *wstatus, uint32_t options, void *rusage); pcb_t *find_proc_by_pid(uint32_t pid); diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 99d5a68ac..af96bedbf 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -163,7 +163,7 @@ typedef enum { SYSCALL_DECLARE(open, const char *filename, int flags); SYSCALL_DECLARE(read, int fd, void *buffer, int count); SYSCALL_DECLARE(write, int fd, const void *buffer, int count); -SYSCALL_DECLARE(readdir, int fd, char *buf, int len); +SYSCALL_DECLARE(getdents64, int fd, char *buf, size_t count); SYSCALL_DECLARE(close, int fd); SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 52a9d7596..ed4bb838a 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -969,7 +969,7 @@ SYSCALL_DEFINE0(getpid) } /* - * Waitpid implementation - do_waitpid() does the following operations: + * Waitpid implementation via wait4 - do_wait4() does the following operations: * - Suspend the current process until the child process finished its execution * (exit()) If the pid argument is -1, waitpid() looks for a possible terminated * process and performs the operation. If no process is finished (in zombie @@ -977,8 +977,10 @@ SYSCALL_DEFINE0(getpid) * - Get the exit code from the child PCB * - Clean the PCB and page tables * - Return the pid if successful operation + * + * rusage is ignored */ -SYSCALL_DEFINE3(waitpid, int, pid, uint32_t *, wstatus, uint32_t, options) +SYSCALL_DEFINE4(wait4, int, pid, uint32_t *, wstatus, uint32_t, options, void *, rusage) { pcb_t *child; unsigned long flags; From 81c4c7cb9082a15d36a3da3888b62c772ad3c3bd Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 2 Sep 2025 16:56:04 +0200 Subject: [PATCH 06/14] add mmap2 and openat --- so3/arch/arm32/include/asm/syscall_number.h | 9 +++---- so3/arch/arm64/include/asm/syscall_number.h | 2 +- so3/fs/vfs.c | 26 ++++++++++++++++++++- so3/include/vfs.h | 10 ++++++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index bff2e042d..28be697bc 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -27,7 +27,7 @@ #define SYSCALL_FORK 2 #define SYSCALL_READ 3 #define SYSCALL_WRITE 4 -#define SYSCALL_OPEN 5 // Add mode +#define SYSCALL_OPEN 5 #define SYSCALL_CLOSE 6 #define SYSCALL_EXECVE 11 @@ -64,6 +64,8 @@ #define SYSCALL_NANOSLEEP 162 +#define SYSCALL_MMAP2 192 + #define SYSCALL_GETDENTS64 217 #define SYSCALL_WAIT4 260 @@ -84,13 +86,12 @@ #define SYSCALL_SETSOCKOPT 294 +#define SYSCALL_OPENAT 322 + #define SYSCALL_DUP3 358 #define SYSCALL_CLOCK_GETTIME64 403 -// Does not exist -#define SYSCALL_MMAP 222 // => mmap2 - // => pthread #define SYSCALL_THREAD_CREATE 16 #define SYSCALL_THREAD_JOIN 17 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index f706f59ed..36ba15f3c 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -29,6 +29,7 @@ #define SYSCALL_IOCTL 29 +#define SYSCALL_OPENAT 56 #define SYSCALL_CLOSE 57 #define SYSCALL_GETDENTS64 61 @@ -74,7 +75,6 @@ // Does not exist #define SYSCALL_FORK 7 // => clone -#define SYSCALL_OPEN 5 // => openat #define SYSCALL_PIPE 19 // => pipe2 #define SYSCALL_SEND 32 // => sendto #define SYSCALL_SIGACTION 46 // => rt_sigaction diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 0345502bf..023816c57 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -548,12 +548,16 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) /** * @brief This function opens a file. Not all file types are supported. */ -SYSCALL_DEFINE2(open, const char *, filename, int, flags) +SYSCALL_DEFINE3(open, const char *, filename, int, flags, unsigned short, mode) { int fd, gfd, ret = -1; uint32_t type; struct file_operations *fops; + if (mode != 0) { + LOG_WARNING("mode parameters isn't supported\n"); + } + mutex_lock(&vfs_lock); /* @@ -612,6 +616,18 @@ SYSCALL_DEFINE2(open, const char *, filename, int, flags) return ret; } +/** + * dirfd is currently ignored. + */ +SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned short, mode) +{ + if (dirfd != AT_FDCWD) { + LOG_WARNING("dirfd parameters isn't supported\n"); + } + + return do_open(filename, flags, mode); +} + /* * @brief readdir read a directory entry which will be stored in a struct dirent entry * @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace. @@ -837,6 +853,14 @@ SYSCALL_DEFINE6(mmap, addr_t, start, size_t, length, int, prot, int, flags, int, return do_mmap(fd, start, page_count, offset); } +/** + * Works like mmap, but with the given offset been in page count. + */ +SYSCALL_DEFINE6(mmap2, addr_t, start, size_t, length, int, prot, int, flags, int, fd, off_t, pgoffset) +{ + return sys_do_mmap(start, length, prot, flags, fd, pgoffset * PAGE_SIZE); +} + SYSCALL_DEFINE3(ioctl, int, fd, unsigned long, cmd, unsigned long, args) { int rc, gfd; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index af96bedbf..ab6641dd4 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -1,7 +1,7 @@ /* * Copyright (C) 2014-2019 Daniel Rossier * Copyright (C) 2017 Xavier Ruppen - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -94,6 +94,10 @@ /* mmap flags options */ #define MAP_ANONYMOUS 0x10 /* don't use a file */ +/* Special value for dirfd used to indicate openat + should use the current working directory. */ +#define AT_FDCWD (-100) + /* Return error values */ #define MAP_FAILED ((void *) -1) /* mmap fail */ @@ -160,7 +164,8 @@ typedef enum { /* Syscall accessible from userspace */ -SYSCALL_DECLARE(open, const char *filename, int flags); +SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, unsigned short mode) +SYSCALL_DECLARE(open, const char *filename, int flags, unsigned short mode); SYSCALL_DECLARE(read, int fd, void *buffer, int count); SYSCALL_DECLARE(write, int fd, const void *buffer, int count); SYSCALL_DECLARE(getdents64, int fd, char *buf, size_t count); @@ -170,6 +175,7 @@ SYSCALL_DECLARE(dup2, int oldfd, int newfd); SYSCALL_DECLARE(dup3, int oldfd, int newfd, int flags); SYSCALL_DECLARE(stat, const char *path, struct stat *st); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); +SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(fcntl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); From fff4b8ffde92d4fa9b7cb82373c59cfad00dac70 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 25 Sep 2025 09:18:19 +0200 Subject: [PATCH 07/14] remove support for sysinfo --- so3/arch/arm32/include/asm/syscall_number.h | 2 -- so3/arch/arm64/include/asm/syscall_number.h | 3 --- so3/include/syscall.h | 8 ------ so3/kernel/syscalls.c | 30 --------------------- usr/lib/libc/crt0.S | 1 - usr/lib/libc/include/syscall.h | 8 ------ 6 files changed, 52 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 28be697bc..88428e2ad 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -55,8 +55,6 @@ #define SYSCALL_STAT 106 -// #define SYSCALL_SYSINFO 116 // => struct sysinfo - #define SYSCALL_SIGRETURN 119 #define SYSCALL_READV 145 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 36ba15f3c..029eb665b 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -51,12 +51,9 @@ #define SYSCALL_KILL 129 #define SYSCALL_GETTIMEOFDAY 169 -// #define SYSCALL_SETTIMEOFDAY 170 // Implement? #define SYSCALL_GETPID 172 -// #define SYSCALL_SYSINFO 179 // => struct sysinfo - #define SYSCALL_SOCKET 198 #define SYSCALL_BIND 200 diff --git a/so3/include/syscall.h b/so3/include/syscall.h index 1c1031576..711b84145 100644 --- a/so3/include/syscall.h +++ b/so3/include/syscall.h @@ -21,12 +21,6 @@ #ifndef ASM_ARM_SYSCALL_H #define ASM_ARM_SYSCALL_H -#define SYSINFO_DUMP_HEAP 0 -#define SYSINFO_DUMP_SCHED 1 -#define SYSINFO_TEST_MALLOC 2 -#define SYSINFO_PRINTK 3 -#define SYSINFO_DUMP_PROC 4 - #include #ifndef __ASSEMBLY__ @@ -120,8 +114,6 @@ typedef long (*syscall_fn_t)(syscall_args_t *); long syscall_handle(syscall_args_t *); -SYSCALL_DECLARE(sysinfo, unsigned long info_number, char *text); - #endif /* __ASSEMBLY__ */ #endif /* ASM_ARM_SYSCALL_H */ diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index cf82d60e5..a2be6e803 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -95,38 +95,8 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_SETSOCKOPT] = __sys_setsockopt, [SYSCALL_RECVFROM] = __sys_recvfrom, #endif - [SYSCALL_SYSINFO] = __sys_sysinfo, }; -SYSCALL_DEFINE2(sysinfo, unsigned long, info_number, char *, text) -{ - switch (info_number) { - case SYSINFO_DUMP_HEAP: - dump_heap("Heap info asked from user.\n"); - break; - - case SYSINFO_DUMP_SCHED: - dump_sched(); - break; - -#ifdef CONFIG_MMU - case SYSINFO_DUMP_PROC: - dump_proc(); - break; -#endif - -#ifdef CONFIG_APP_TEST_MALLOC - case SYSINFO_TEST_MALLOC: - test_malloc(a->args[1]); - break; -#endif - case SYSINFO_PRINTK: - printk("%s", (char *) text); - break; - } - return 0; -} - /* * Process syscalls according to the syscall number passed in r7 on ARM and x8 on ARM64. * According to SO3 ABI, the syscall arguments are passed in r0-r5 on ARM and x0-x5 on ARM64. diff --git a/usr/lib/libc/crt0.S b/usr/lib/libc/crt0.S index 22ba5aeda..f8f1ea080 100755 --- a/usr/lib/libc/crt0.S +++ b/usr/lib/libc/crt0.S @@ -164,7 +164,6 @@ SYSCALLSTUB sys_settimeofday, syscallSetTimeOfDay 2 SYSCALLSTUB sys_clock_gettime, syscallClockGetTime 2 SYSCALLSTUB sys_sbrk, syscallSbrk 1 -SYSCALLSTUB sys_info, syscallSysinfo 2 SYSCALLSTUB sys_lseek, syscallLseek 3 diff --git a/usr/lib/libc/include/syscall.h b/usr/lib/libc/include/syscall.h index 2426d2bd4..65299ad58 100644 --- a/usr/lib/libc/include/syscall.h +++ b/usr/lib/libc/include/syscall.h @@ -88,17 +88,9 @@ #define syscallNanosleep 70 -#define syscallSysinfo 99 - #define syscallSetsockopt 110 #define syscallRecvfrom 111 - -#define SYSINFO_DUMP_HEAP 0 -#define SYSINFO_DUMP_SCHED 1 -#define SYSINFO_TEST_MALLOC 2 -#define SYSINFO_PRINTK 3 - #ifndef __ASSEMBLY__ #include From d420d5bca9477cf0d343d32fb969687efde6d368 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 30 Sep 2025 13:13:12 +0200 Subject: [PATCH 08/14] add pipe2 --- so3/arch/arm32/include/asm/syscall_number.h | 1 + so3/arch/arm64/include/asm/syscall_number.h | 3 ++- so3/fs/vfs.c | 10 +++++++--- so3/include/pipe.h | 1 + so3/ipc/pipe.c | 13 +++++++++++++ so3/kernel/syscalls.c | 9 +++++++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 88428e2ad..1a3915b1c 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -87,6 +87,7 @@ #define SYSCALL_OPENAT 322 #define SYSCALL_DUP3 358 +#define SYSCALL_PIPE2 359 #define SYSCALL_CLOCK_GETTIME64 403 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 029eb665b..1c994cf8c 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -32,6 +32,8 @@ #define SYSCALL_OPENAT 56 #define SYSCALL_CLOSE 57 +#define SYSCALL_PIPE2 59 + #define SYSCALL_GETDENTS64 61 #define SYSCALL_LSEEK 62 #define SYSCALL_READ 63 @@ -72,7 +74,6 @@ // Does not exist #define SYSCALL_FORK 7 // => clone -#define SYSCALL_PIPE 19 // => pipe2 #define SYSCALL_SEND 32 // => sendto #define SYSCALL_SIGACTION 46 // => rt_sigaction diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 023816c57..771aaef38 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -617,12 +617,13 @@ SYSCALL_DEFINE3(open, const char *, filename, int, flags, unsigned short, mode) } /** - * dirfd is currently ignored. + * Simple openat implementation ignoring dirfd for aarch64. */ SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned short, mode) { if (dirfd != AT_FDCWD) { LOG_WARNING("dirfd parameters isn't supported\n"); + return -ENOSYS; } return do_open(filename, flags, mode); @@ -731,15 +732,18 @@ SYSCALL_DEFINE1(close, int, fd) return 0; } +/** + * Simple dup3 implementation ignoring flags for aarch64. + */ SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) { if (oldfd == newfd) { - set_errno(EINVAL); - return -1; + return -EINVAL; } if (flags != 0) { LOG_WARNING("Flags not supported.\n"); + return -ENOSYS; } return do_dup2(oldfd, newfd); diff --git a/so3/include/pipe.h b/so3/include/pipe.h index 961f0b4c9..2f8f24101 100644 --- a/so3/include/pipe.h +++ b/so3/include/pipe.h @@ -54,5 +54,6 @@ struct pipe_desc { typedef struct pipe_desc pipe_desc_t; SYSCALL_DECLARE(pipe, int *pipefd); +SYSCALL_DECLARE(pipe2, int *pipefd, int flags); #endif /* PIPE_H */ diff --git a/so3/ipc/pipe.c b/so3/ipc/pipe.c index e649bdff3..d40f62bb5 100644 --- a/so3/ipc/pipe.c +++ b/so3/ipc/pipe.c @@ -308,3 +308,16 @@ SYSCALL_DEFINE1(pipe, int *, pipefd) return 0; } + +/** + * Simple pipe2 implementation ignoring flags for aarch64. + */ +SYSCALL_DEFINE2(pipe2, int *, pipefd, int, flags) +{ + if (flags != 0) { + LOG_WARNING("Flags not supported.\n"); + return -ENOSYS; + } + + return do_pipe(pipefd); +} diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index a2be6e803..462f83a08 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -45,12 +45,18 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_EXIT] = __sys_exit, [SYSCALL_EXECVE] = __sys_execve, [SYSCALL_FORK] = __sys_fork, +#ifdef SYSCALL_WAITPID [SYSCALL_WAITPID] = __sys_waitpid, +#endif + [SYSCALL_WAIT4] = __sys_wait4, [SYSCALL_PTRACE] = __sys_ptrace, #endif [SYSCALL_READ] = __sys_read, [SYSCALL_WRITE] = __sys_write, +#ifdef SYSCALL_OPEN [SYSCALL_OPEN] = __sys_open, +#endif + [SYSCALL_OPENAT] = __sys_openat, [SYSCALL_CLOSE] = __sys_close, [SYSCALL_THREAD_CREATE] = __sys_thread_create, [SYSCALL_THREAD_JOIN] = __sys_thread_join, @@ -63,7 +69,10 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_READV] = __sys_readv, [SYSCALL_WRITEV] = __sys_writev, #ifdef CONFIG_IPC_PIPE +#ifdef SYSCALL_PIPE [SYSCALL_PIPE] = __sys_pipe, +#endif + [SYSCALL_PIPE2] = __sys_pipe2, #endif [SYSCALL_DUP] = __sys_dup, #ifdef SYSCALL_DUP2 From e0bcb8aff81183fe0be2e7eba6d6e6375ea7439c Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 30 Sep 2025 16:14:15 +0200 Subject: [PATCH 09/14] add rt_sig, fstatat and correct syscall table --- so3/arch/arm32/include/asm/syscall_number.h | 5 ++ so3/arch/arm64/exception.S | 2 +- so3/arch/arm64/include/asm/syscall_number.h | 11 +++-- so3/fs/elf.c | 2 +- so3/fs/fat/fat.c | 3 +- so3/fs/vfs.c | 39 +++++++++++++++ so3/include/signal.h | 2 + so3/include/stat.h | 54 ++++++++++++++++----- so3/include/vfs.h | 1 + so3/ipc/signal.c | 20 +++++++- so3/kernel/syscalls.c | 30 +++++++++++- 11 files changed, 147 insertions(+), 22 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 1a3915b1c..11330a050 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -62,6 +62,9 @@ #define SYSCALL_NANOSLEEP 162 +#define SYSCALL_RT_SIGRETURN 173 +#define SYSCALL_RT_SIGACTION 174 + #define SYSCALL_MMAP2 192 #define SYSCALL_GETDENTS64 217 @@ -86,6 +89,8 @@ #define SYSCALL_OPENAT 322 +#define SYSCALL_FSTATAT 327 + #define SYSCALL_DUP3 358 #define SYSCALL_PIPE2 359 diff --git a/so3/arch/arm64/exception.S b/so3/arch/arm64/exception.S index bde52f61b..cf58242bc 100644 --- a/so3/arch/arm64/exception.S +++ b/so3/arch/arm64/exception.S @@ -557,7 +557,7 @@ el01_sync_handler: // Check if sigreturn has been called. In this case, we // clean the stack frame which has been used to manage the user handler. - cmp x8, #SYSCALL_SIGRETURN + cmp x8, #SYSCALL_RT_SIGRETURN bne __ret_from_fork // Reset the stack frame by removing the one issued from sigreturn diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 1c994cf8c..2c318f7ba 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -41,6 +41,8 @@ #define SYSCALL_READV 65 #define SYSCALL_WRITEV 66 +#define SYSCALL_FSTATAT 79 + #define SYSCALL_EXIT 93 #define SYSCALL_NANOSLEEP 101 @@ -52,6 +54,10 @@ #define SYSCALL_KILL 129 +#define SYSCALL_RT_SIGACTION 134 + +#define SYSCALL_RT_SIGRETURN 139 + #define SYSCALL_GETTIMEOFDAY 169 #define SYSCALL_GETPID 172 @@ -74,11 +80,6 @@ // Does not exist #define SYSCALL_FORK 7 // => clone -#define SYSCALL_SEND 32 // => sendto -#define SYSCALL_SIGACTION 46 // => rt_sigaction - -#define SYSCALL_STAT 34 // ???? -#define SYSCALL_SIGRETURN 48 // ????? #define SYSCALL_THREAD_CREATE 16 #define SYSCALL_THREAD_JOIN 17 diff --git a/so3/fs/elf.c b/so3/fs/elf.c index 0489e7de5..a06d77fa1 100644 --- a/so3/fs/elf.c +++ b/so3/fs/elf.c @@ -35,7 +35,7 @@ uint8_t *elf_load_buffer(const char *filename) struct stat st; /* open and read file */ - fd = sys_do_open(filename, O_RDONLY); + fd = sys_do_open(filename, O_RDONLY, 0); if (fd < 0) return NULL; diff --git a/so3/fs/fat/fat.c b/so3/fs/fat/fat.c index 4a41b514f..551454488 100644 --- a/so3/fs/fat/fat.c +++ b/so3/fs/fat/fat.c @@ -415,8 +415,7 @@ int fat_stat(const char *path, struct stat *st) } time_fat_fat2so3(finfo.fdate, finfo.ftime, &tm); - st->st_mtim = tm.tv_sec; - strcpy(st->st_name, path); + st->st_mtime = tm.tv_sec; st->st_size = finfo.fsize; return 0; diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 771aaef38..cac94cd2c 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -818,6 +818,8 @@ SYSCALL_DEFINE2(stat, const char *, path, struct stat *, st) { int ret; + memset(st, 0, sizeof(*st)); + mutex_lock(&vfs_lock); /* FIXME Find the correct mount point with the path */ @@ -838,6 +840,43 @@ SYSCALL_DEFINE2(stat, const char *, path, struct stat *, st) return ret; } +SYSCALL_DEFINE3(fstatat, const char *, path, struct stat64 *, st, int, flags) +{ + struct stat stat32; + int ret; + if (flags != 0) { + LOG_WARNING("Flags not supported\n"); + return -ENOSYS; + } + + ret = do_stat(path, &stat32); + if (ret < 0) { + return ret; + } + + memset(st, 0, sizeof(*st)); + + // Copy with extension from 32 bits to 64 bits + st->st_dev = stat32.st_dev; + st->st_ino = stat32.st_ino; + st->st_mode = stat32.st_mode; + st->st_nlink = stat32.st_nlink; + st->st_uid = stat32.st_uid; + st->st_gid = stat32.st_gid; + st->st_rdev = stat32.st_rdev; + st->st_size = stat32.st_size; + st->st_blksize = stat32.st_blksize; + st->st_blocks = stat32.st_blocks; + st->st_atime = stat32.st_atime; + st->st_atime_nsec = stat32.st_atime_nsec; + st->st_mtime = stat32.st_mtime; + st->st_mtime_nsec = stat32.st_mtime_nsec; + st->st_ctime = stat32.st_ctime; + st->st_ctime_nsec = stat32.st_ctime_nsec; + + return 0; +} + /** * An mmap() implementation in VFS. */ diff --git a/so3/include/signal.h b/so3/include/signal.h index b4f8156a8..0969ad23e 100644 --- a/so3/include/signal.h +++ b/so3/include/signal.h @@ -95,7 +95,9 @@ typedef struct __sigaction { } __sigaction_t; SYSCALL_DECLARE(sigaction, int signum, const sigaction_t *action, sigaction_t *old_action); +SYSCALL_DECLARE(rt_sigaction, int signum, const sigaction_t *action, sigaction_t *old_action, size_t sigsize); SYSCALL_DECLARE(kill, int pid, int sig); SYSCALL_DECLARE(sigreturn, void); +SYSCALL_DECLARE(rt_sigreturn, void); #endif /* SIGNAL_H */ diff --git a/so3/include/stat.h b/so3/include/stat.h index 6571c90a1..03cd9694c 100644 --- a/so3/include/stat.h +++ b/so3/include/stat.h @@ -20,18 +20,50 @@ #ifndef STAT_H #define STAT_H -#include - -#define FILENAME_SIZE 256 - -typedef uint32_t mode_t; - struct stat { - char st_name[FILENAME_SIZE]; /* Filename */ - unsigned long st_size; /* Size of file */ - time_t st_mtim; /* Time of last modification in sec*/ - unsigned char st_flags; /* Regular file flag (not supported on fat) */ - mode_t st_mode; /* Protection not used (not supported on fat) */ + unsigned long st_dev; /* Device. */ + unsigned long st_ino; /* File serial number. */ + unsigned int st_mode; /* File mode. */ + unsigned int st_nlink; /* Link count. */ + unsigned int st_uid; /* User ID of the file's owner. */ + unsigned int st_gid; /* Group ID of the file's group. */ + unsigned long st_rdev; /* Device number, if device. */ + unsigned long __pad1; + long st_size; /* Size of file, in bytes. */ + int st_blksize; /* Optimal block size for I/O. */ + int __pad2; + long st_blocks; /* Number 512-byte blocks allocated. */ + long st_atime; /* Time of last access. */ + unsigned long st_atime_nsec; + long st_mtime; /* Time of last modification. */ + unsigned long st_mtime_nsec; + long st_ctime; /* Time of last status change. */ + unsigned long st_ctime_nsec; + unsigned int __unused4; + unsigned int __unused5; +}; + +struct stat64 { + unsigned long long st_dev; /* Device. */ + unsigned long long st_ino; /* File serial number. */ + unsigned int st_mode; /* File mode. */ + unsigned int st_nlink; /* Link count. */ + unsigned int st_uid; /* User ID of the file's owner. */ + unsigned int st_gid; /* Group ID of the file's group. */ + unsigned long long st_rdev; /* Device number, if device. */ + unsigned long long __pad1; + long long st_size; /* Size of file, in bytes. */ + int st_blksize; /* Optimal block size for I/O. */ + int __pad2; + long long st_blocks; /* Number 512-byte blocks allocated. */ + int st_atime; /* Time of last access. */ + unsigned int st_atime_nsec; + int st_mtime; /* Time of last modification. */ + unsigned int st_mtime_nsec; + int st_ctime; /* Time of last status change. */ + unsigned int st_ctime_nsec; + unsigned int __unused4; + unsigned int __unused5; }; #endif /* STAT_H */ diff --git a/so3/include/vfs.h b/so3/include/vfs.h index ab6641dd4..c460745a4 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -174,6 +174,7 @@ SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); SYSCALL_DECLARE(dup3, int oldfd, int newfd, int flags); SYSCALL_DECLARE(stat, const char *path, struct stat *st); +SYSCALL_DECLARE(fstatat, const char *path, struct stat64 *st, int flags); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); diff --git a/so3/ipc/signal.c b/so3/ipc/signal.c index c610b2ad9..4fa2347df 100644 --- a/so3/ipc/signal.c +++ b/so3/ipc/signal.c @@ -44,6 +44,14 @@ SYSCALL_DEFINE0(sigreturn) return 0; } +/** + * rt_sigreturn isn't different from sigreturn for SO3 use case. + */ +SYSCALL_DEFINE0(rt_sigreturn) +{ + return do_sigreturn(); +} + /** * Checks if signals were set and executes their handlers if so. */ @@ -107,7 +115,7 @@ SYSCALL_DEFINE3(sigaction, int, signum, const sigaction_t *, action, sigaction_t { if (signum < 0 || signum >= _NSIG) { LOG_ERROR("signum not valid!\n"); - return -1; + return -EINVAL; } if (old_action != NULL) @@ -124,6 +132,16 @@ SYSCALL_DEFINE3(sigaction, int, signum, const sigaction_t *, action, sigaction_t return 0; } +SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigaction_t *, old_actionm, size_t, sigsize) +{ + if (sigsize != sizeof(sigset_t)) { + LOG_WARNING("Invalid sigset size\n"); + return -EINVAL; + } + + return do_sigaction(signum, action, old_actionm); +} + SYSCALL_DEFINE2(kill, int, pid, int, sig) { pcb_t *proc; diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 462f83a08..50fe271b2 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -40,8 +40,18 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { #ifdef CONFIG_MMU [SYSCALL_GETPID] = __sys_getpid, +#ifdef SYSCALL_GETTIMEOFDAY [SYSCALL_GETTIMEOFDAY] = __sys_gettimeofday, +#endif +#ifdef SYSCALL_GETTIMEOFDAY_TIME32 + [SYSCALL_GETTIMEOFDAY_TIME32] = __sys_gettimeofday_time32, +#endif +#ifdef SYSCALL_CLOCK_GETTIME [SYSCALL_CLOCK_GETTIME] = __sys_clock_gettime, +#endif +#ifdef SYSCALL_CLOCK_GETTIME32 + [SYSCALL_CLOCK_GETTIME32] = __sys_clock_gettime32, +#endif [SYSCALL_EXIT] = __sys_exit, [SYSCALL_EXECVE] = __sys_execve, [SYSCALL_FORK] = __sys_fork, @@ -62,7 +72,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_THREAD_JOIN] = __sys_thread_join, [SYSCALL_THREAD_EXIT] = __sys_thread_exit, [SYSCALL_THREAD_YIELD] = __sys_thread_yield, - [SYSCALL_READDIR] = __sys_readdir, + [SYSCALL_GETDENTS64] = __sys_getdents64, [SYSCALL_IOCTL] = __sys_ioctl, [SYSCALL_FCNTL] = __sys_fcntl, [SYSCALL_LSEEK] = __sys_lseek, @@ -79,8 +89,16 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_DUP2] = __sys_dup2, #endif [SYSCALL_DUP3] = __sys_dup3, +#ifdef SYSCALL_STAT [SYSCALL_STAT] = __sys_stat, +#endif + [SYSCALL_FSTATAT] = __sys_fstatat, +#ifdef SYSCALL_MMAP [SYSCALL_MMAP] = __sys_mmap, +#endif +#ifdef SYSCALL_MMAP2 + [SYSCALL_MMAP2] = __sys_mmap2, +#endif [SYSCALL_NANOSLEEP] = __sys_nanosleep, #ifdef CONFIG_PROC_ENV [SYSCALL_BRK] = __sys_brk, @@ -88,9 +106,15 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_MUTEX_LOCK] = __sys_mutex_lock, [SYSCALL_MUTEX_UNLOCK] = __sys_mutex_unlock, #ifdef CONFIG_IPC_SIGNAL +#ifdef SYSCALL_SIGACTION [SYSCALL_SIGACTION] = __sys_sigaction, +#endif + [SYSCALL_RT_SIGACTION] = __sys_rt_sigaction, [SYSCALL_KILL] = __sys_kill, +#ifdef SYSCALL_SIGRETURN [SYSCALL_SIGRETURN] = __sys_sigreturn, +#endif + [SYSCALL_RT_SIGRETURN] = __sys_rt_sigreturn, #endif #ifdef CONFIG_NET [SYSCALL_SOCKET] = __sys_socket, @@ -98,8 +122,12 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_LISTEN] = __sys_listen, [SYSCALL_ACCEPT] = __sys_accept, [SYSCALL_CONNECT] = __sys_connect, +#ifdef SYSCALL_RECV [SYSCALL_RECV] = __sys_recv, +#endif +#ifdef SYSCALL_SEND [SYSCALL_SEND] = __sys_send, +#endif [SYSCALL_SENDTO] = __sys_sendto, [SYSCALL_SETSOCKOPT] = __sys_setsockopt, [SYSCALL_RECVFROM] = __sys_recvfrom, From 089075023bda3ded645c50f5e5396eab881eb502 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Fri, 10 Oct 2025 15:04:31 +0200 Subject: [PATCH 10/14] correction after rebase --- so3/fs/vfs.c | 6 +++--- so3/ipc/pipe.c | 4 ++-- so3/ipc/signal.c | 4 ++-- so3/kernel/process.c | 2 +- so3/kernel/thread.c | 4 ++-- so3/kernel/timer.c | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index cac94cd2c..13fd99662 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -626,7 +626,7 @@ SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned return -ENOSYS; } - return do_open(filename, flags, mode); + return sys_do_open(filename, flags, mode); } /* @@ -746,7 +746,7 @@ SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) return -ENOSYS; } - return do_dup2(oldfd, newfd); + return sys_do_dup2(oldfd, newfd); } /** @@ -849,7 +849,7 @@ SYSCALL_DEFINE3(fstatat, const char *, path, struct stat64 *, st, int, flags) return -ENOSYS; } - ret = do_stat(path, &stat32); + ret = sys_do_stat(path, &stat32); if (ret < 0) { return ret; } diff --git a/so3/ipc/pipe.c b/so3/ipc/pipe.c index d40f62bb5..8efe9c7ca 100644 --- a/so3/ipc/pipe.c +++ b/so3/ipc/pipe.c @@ -19,8 +19,8 @@ #include #include -#include #include +#include #include #include #include @@ -319,5 +319,5 @@ SYSCALL_DEFINE2(pipe2, int *, pipefd, int, flags) return -ENOSYS; } - return do_pipe(pipefd); + return sys_do_pipe(pipefd); } diff --git a/so3/ipc/signal.c b/so3/ipc/signal.c index 4fa2347df..20371e85c 100644 --- a/so3/ipc/signal.c +++ b/so3/ipc/signal.c @@ -49,7 +49,7 @@ SYSCALL_DEFINE0(sigreturn) */ SYSCALL_DEFINE0(rt_sigreturn) { - return do_sigreturn(); + return sys_do_sigreturn(); } /** @@ -139,7 +139,7 @@ SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigactio return -EINVAL; } - return do_sigaction(signum, action, old_actionm); + return sys_do_sigaction(signum, action, old_actionm); } SYSCALL_DEFINE2(kill, int, pid, int, sig) diff --git a/so3/kernel/process.c b/so3/kernel/process.c index ed4bb838a..ba91a16e6 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -969,7 +969,7 @@ SYSCALL_DEFINE0(getpid) } /* - * Waitpid implementation via wait4 - do_wait4() does the following operations: + * Waitpid implementation via wait4 - sys_do_wait4() does the following operations: * - Suspend the current process until the child process finished its execution * (exit()) If the pid argument is -1, waitpid() looks for a possible terminated * process and performs the operation. If no process is finished (in zombie diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 363ec1520..51062add5 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -255,9 +255,9 @@ void thread_exit(int *exit_status) * According to the thread which is calling thread_exit(), the behaviour may differ. * Typically, if it is the main thread of the process, we have to wait until all * running threads (belonging to the process) are completed, and we pursue with - * do_exit(). + * sys_do_exit(). * - * - If pcb->state == PROC_STATE_ZOMBIE, it means we are called from do_exit() + * - If pcb->state == PROC_STATE_ZOMBIE, it means we are called from sys_do_exit() */ pcb = current()->pcb; diff --git a/so3/kernel/timer.c b/so3/kernel/timer.c index 7ff452d1e..075b39c70 100644 --- a/so3/kernel/timer.c +++ b/so3/kernel/timer.c @@ -409,7 +409,7 @@ SYSCALL_DEFINE2(gettimeofday_time32, struct timeval32 *, ts, void *, tz) { struct timeval time64; - long ret = do_gettimeofday(&time64, NULL); + long ret = sys_do_gettimeofday(&time64, NULL); if (ret < 0) { return ret; @@ -446,7 +446,7 @@ SYSCALL_DEFINE2(clock_gettime32, int, clk_id, struct timespec32 *, ts) { struct timespec time64; - long ret = do_clock_gettime(clk_id, &time64); + long ret = sys_do_clock_gettime(clk_id, &time64); if (ret < 0) { return ret; From b91c3661f8b1f58fa139fb1b5695c6c2816df8bc Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Fri, 10 Oct 2025 16:04:25 +0200 Subject: [PATCH 11/14] remove unwanted comment in syscall_number --- so3/arch/arm32/include/asm/syscall_number.h | 5 +---- so3/arch/arm64/include/asm/syscall_number.h | 5 +---- so3/fs/vfs.c | 10 ---------- so3/include/vfs.h | 1 - 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 11330a050..733c4ef9e 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -45,13 +45,11 @@ #define SYSCALL_PIPE 46 #define SYSCALL_IOCTL 54 -#define SYSCALL_FCNTL 55 // fcntl64? #define SYSCALL_DUP2 63 #define SYSCALL_SIGACTION 67 #define SYSCALL_GETTIMEOFDAY_TIME32 78 -// #define SYSCALL_SETTIMEOFDAY 79 // Implement? #define SYSCALL_STAT 106 @@ -96,13 +94,12 @@ #define SYSCALL_CLOCK_GETTIME64 403 -// => pthread +/* Following syscalls stills need to be align */ #define SYSCALL_THREAD_CREATE 16 #define SYSCALL_THREAD_JOIN 17 #define SYSCALL_THREAD_EXIT 18 #define SYSCALL_THREAD_YIELD 43 -// => ??? #define SYSCALL_MUTEX_LOCK 60 #define SYSCALL_MUTEX_UNLOCK 61 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 2c318f7ba..302e27afe 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -25,8 +25,6 @@ #define SYSCALL_DUP 23 #define SYSCALL_DUP3 24 -#define SYSCALL_FCNTL 25 - #define SYSCALL_IOCTL 29 #define SYSCALL_OPENAT 56 @@ -78,7 +76,7 @@ #define SYSCALL_EXECVE 221 #define SYSCALL_MMAP 222 -// Does not exist +/* Following syscalls stills need to be align */ #define SYSCALL_FORK 7 // => clone #define SYSCALL_THREAD_CREATE 16 @@ -86,7 +84,6 @@ #define SYSCALL_THREAD_EXIT 18 #define SYSCALL_THREAD_YIELD 43 -// => ??? #define SYSCALL_MUTEX_LOCK 60 #define SYSCALL_MUTEX_UNLOCK 61 diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 13fd99662..c84b6c806 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -953,16 +953,6 @@ SYSCALL_DEFINE3(lseek, int, fd, off_t, off, int, whence) return rc; } -/* - * Implementation of the fcntl syscall - */ -SYSCALL_DEFINE3(fcntl, int, fd, unsigned long, cmd, unsigned long, args) -{ - /* Not yet implemented */ - - return 0; -} - /* * Implementation of the writev syscall */ diff --git a/so3/include/vfs.h b/so3/include/vfs.h index c460745a4..1dbaf4381 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -178,7 +178,6 @@ SYSCALL_DECLARE(fstatat, const char *path, struct stat64 *st, int flags); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); -SYSCALL_DECLARE(fcntl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); SYSCALL_DECLARE(writev, unsigned long fd, const struct iovec *vec, unsigned long vlen); SYSCALL_DECLARE(readv, unsigned long fd, const struct iovec *vec, unsigned long vlen); From c9ca020479a788b5313f478f3bb5142b0d9a2700 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Fri, 10 Oct 2025 19:53:10 +0200 Subject: [PATCH 12/14] correct syscall arguments and numbers --- so3/arch/arm32/include/asm/syscall_number.h | 13 +- so3/arch/arm64/include/asm/syscall_number.h | 7 +- so3/fs/elf.c | 2 +- so3/fs/vfs.c | 148 +++++++++++++------- so3/include/dirent.h | 2 +- so3/include/net.h | 19 ++- so3/include/process.h | 2 +- so3/include/ptrace.h | 2 +- so3/include/signal.h | 1 - so3/include/stat.h | 44 +++--- so3/include/types.h | 4 +- so3/include/vfs.h | 17 ++- so3/ipc/signal.c | 17 +-- so3/kernel/process.c | 2 +- so3/kernel/ptrace.c | 2 +- so3/kernel/syscalls.c | 5 +- so3/net/net.c | 44 +++--- 17 files changed, 192 insertions(+), 139 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 733c4ef9e..9f6552805 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -40,18 +40,17 @@ #define SYSCALL_KILL 37 #define SYSCALL_DUP 41 +#define SYSCALL_PIPE 42 #define SYSCALL_BRK 45 -#define SYSCALL_PIPE 46 #define SYSCALL_IOCTL 54 #define SYSCALL_DUP2 63 -#define SYSCALL_SIGACTION 67 #define SYSCALL_GETTIMEOFDAY_TIME32 78 -#define SYSCALL_STAT 106 +#define SYSCALL_WAIT4 114 #define SYSCALL_SIGRETURN 119 @@ -65,9 +64,9 @@ #define SYSCALL_MMAP2 192 -#define SYSCALL_GETDENTS64 217 +#define SYSCALL_STAT64 195 -#define SYSCALL_WAIT4 260 +#define SYSCALL_GETDENTS64 217 #define SYSCALL_CLOCK_GETTIME32 263 @@ -87,14 +86,14 @@ #define SYSCALL_OPENAT 322 -#define SYSCALL_FSTATAT 327 +#define SYSCALL_FSTATAT64 327 #define SYSCALL_DUP3 358 #define SYSCALL_PIPE2 359 #define SYSCALL_CLOCK_GETTIME64 403 -/* Following syscalls stills need to be align */ +/* Following syscalls still need to be aligned */ #define SYSCALL_THREAD_CREATE 16 #define SYSCALL_THREAD_JOIN 17 #define SYSCALL_THREAD_EXIT 18 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 302e27afe..be298b5f0 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -39,14 +39,13 @@ #define SYSCALL_READV 65 #define SYSCALL_WRITEV 66 -#define SYSCALL_FSTATAT 79 +#define SYSCALL_NEWFSTATAT 79 #define SYSCALL_EXIT 93 #define SYSCALL_NANOSLEEP 101 #define SYSCALL_CLOCK_GETTIME 113 -#define SYSCALL_WAIT4 114 #define SYSCALL_PTRACE 117 @@ -76,7 +75,9 @@ #define SYSCALL_EXECVE 221 #define SYSCALL_MMAP 222 -/* Following syscalls stills need to be align */ +#define SYSCALL_WAIT4 260 + +/* Following syscalls still need to be aligned */ #define SYSCALL_FORK 7 // => clone #define SYSCALL_THREAD_CREATE 16 diff --git a/so3/fs/elf.c b/so3/fs/elf.c index a06d77fa1..c05309a6b 100644 --- a/so3/fs/elf.c +++ b/so3/fs/elf.c @@ -40,7 +40,7 @@ uint8_t *elf_load_buffer(const char *filename) if (fd < 0) return NULL; - if (sys_do_stat(filename, &st)) + if (sys_do_newfstatat(AT_FDCWD, filename, &st, 0)) return NULL; if (!st.st_size) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index c84b6c806..c1edd8ee1 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -33,6 +33,9 @@ #include #include +#include +#include + /* The VFS abstract subsystem manages a table of open file descriptors where indexes are known as gfd (global file descriptor). * Every process has its own file descriptor table. A local file descriptor (belonging to a process) must be linked to a global file descriptor * according to the fd type. @@ -381,7 +384,7 @@ int vfs_clone_fd(int *fd_src, int *fd_dst) /**************************** Syscall implementation ****************************/ /* Low Level read */ -static int do_read(int fd, void *buffer, int count) +static int do_read(int fd, void *buffer, size_t count) { int gfd; int ret; @@ -423,7 +426,7 @@ static int do_read(int fd, void *buffer, int count) } /* Low Level write */ -static int do_write(int fd, const void *buffer, int count) +static int do_write(int fd, const void *buffer, size_t count) { int gfd; int ret; @@ -532,7 +535,56 @@ static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t off return virt_addr; } -SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) +static long do_stat(const char *path, struct stat *st) +{ + int ret; + + memset(st, 0, sizeof(*st)); + + mutex_lock(&vfs_lock); + + /* FIXME Find the correct mount point with the path */ + if (!registered_fs_ops[FS_FAT]) { + mutex_unlock(&vfs_lock); + return -ENOENT; + } + + if (!registered_fs_ops[FS_FAT]->stat) { + mutex_unlock(&vfs_lock); + return -ENOENT; + } + + ret = registered_fs_ops[FS_FAT]->stat(path, st); + + mutex_unlock(&vfs_lock); + + return ret; +} + +static struct stat64 stat_to_stat64(struct stat *st) +{ + return (struct stat64) { + .st_dev = st->st_dev, + .__st_ino = st->st_ino, + .st_mode = st->st_mode, + .st_nlink = st->st_nlink, + .st_uid = st->st_uid, + .st_gid = st->st_gid, + .st_rdev = st->st_rdev, + .st_size = st->st_size, + .st_blksize = st->st_blksize, + .st_blocks = st->st_blocks, + .st_atime = st->st_atime, + .st_atime_nsec = st->st_atime_nsec, + .st_mtime = st->st_mtime, + .st_mtime_nsec = st->st_mtime_nsec, + .st_ctime = st->st_ctime, + .st_ctime_nsec = st->st_ctime_nsec, + .st_ino = st->st_ino, + }; +} + +SYSCALL_DEFINE3(read, int, fd, void *, buffer, size_t, count) { return do_read(fd, buffer, count); } @@ -540,7 +592,7 @@ SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) /** * @brief This function writes a REGULAR FILE/FOLDER. It only support regular file, dirs and pipes */ -SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) +SYSCALL_DEFINE3(write, int, fd, const void *, buffer, size_t, count) { return do_write(fd, buffer, count); } @@ -548,7 +600,7 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) /** * @brief This function opens a file. Not all file types are supported. */ -SYSCALL_DEFINE3(open, const char *, filename, int, flags, unsigned short, mode) +SYSCALL_DEFINE3(open, const char *, filename, int, flags, umode_t, mode) { int fd, gfd, ret = -1; uint32_t type; @@ -619,7 +671,7 @@ SYSCALL_DEFINE3(open, const char *, filename, int, flags, unsigned short, mode) /** * Simple openat implementation ignoring dirfd for aarch64. */ -SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned short, mode) +SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, umode_t, mode) { if (dirfd != AT_FDCWD) { LOG_WARNING("dirfd parameters isn't supported\n"); @@ -630,14 +682,20 @@ SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned } /* - * @brief readdir read a directory entry which will be stored in a struct dirent entry + * @brief gedetens64 read a directory entry which will be stored in a struct dirent entry * @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace. */ -SYSCALL_DEFINE3(getdents64, int, fd, char *, buf, size_t, len) +SYSCALL_DEFINE3(getdents64, int, fd, struct dirent *, buf, size_t, count) { struct dirent *dirent; int gfd; + /* Dirent d_name should be a flexible array, which is not the case here. + So ensure that the given dirent can actually our full dirent. */ + if (count < sizeof(struct dirent)) { + return -EINVAL; + } + mutex_lock(&vfs_lock); gfd = vfs_get_gfd(fd); @@ -814,67 +872,57 @@ SYSCALL_DEFINE1(dup, int, oldfd) #endif } -SYSCALL_DEFINE2(stat, const char *, path, struct stat *, st) +SYSCALL_DEFINE2(stat64, const char *, path, struct stat64 *, st) { - int ret; + struct stat stat; + long ret = 0; - memset(st, 0, sizeof(*st)); + ret = do_stat(path, &stat); - mutex_lock(&vfs_lock); - - /* FIXME Find the correct mount point with the path */ - if (!registered_fs_ops[FS_FAT]) { - mutex_unlock(&vfs_lock); - return -ENOENT; + if (ret >= 0) { + *st = stat_to_stat64(&stat); } - if (!registered_fs_ops[FS_FAT]->stat) { - mutex_unlock(&vfs_lock); - return -ENOENT; - } - - ret = registered_fs_ops[FS_FAT]->stat(path, st); - - mutex_unlock(&vfs_lock); - return ret; } -SYSCALL_DEFINE3(fstatat, const char *, path, struct stat64 *, st, int, flags) +SYSCALL_DEFINE4(fstatat64, int, fd, const char *, path, struct stat64 *, st, int, flags) { - struct stat stat32; + struct stat stat; int ret; + + if (fd != AT_FDCWD) { + LOG_WARNING("fd parameters isn't supported\n"); + return -ENOSYS; + } + if (flags != 0) { LOG_WARNING("Flags not supported\n"); return -ENOSYS; } - ret = sys_do_stat(path, &stat32); - if (ret < 0) { - return ret; + ret = do_stat(path, &stat); + + if (ret >= 0) { + *st = stat_to_stat64(&stat); } - memset(st, 0, sizeof(*st)); + return ret; +} + +SYSCALL_DEFINE4(newfstatat, int, fd, const char *, path, struct stat *, st, int, flags) +{ + if (fd != AT_FDCWD) { + LOG_WARNING("fd parameters isn't supported\n"); + return -ENOSYS; + } - // Copy with extension from 32 bits to 64 bits - st->st_dev = stat32.st_dev; - st->st_ino = stat32.st_ino; - st->st_mode = stat32.st_mode; - st->st_nlink = stat32.st_nlink; - st->st_uid = stat32.st_uid; - st->st_gid = stat32.st_gid; - st->st_rdev = stat32.st_rdev; - st->st_size = stat32.st_size; - st->st_blksize = stat32.st_blksize; - st->st_blocks = stat32.st_blocks; - st->st_atime = stat32.st_atime; - st->st_atime_nsec = stat32.st_atime_nsec; - st->st_mtime = stat32.st_mtime; - st->st_mtime_nsec = stat32.st_mtime_nsec; - st->st_ctime = stat32.st_ctime; - st->st_ctime_nsec = stat32.st_ctime_nsec; + if (flags != 0) { + LOG_WARNING("Flags not supported\n"); + return -ENOSYS; + } - return 0; + return do_stat(path, st); } /** diff --git a/so3/include/dirent.h b/so3/include/dirent.h index c480e80b5..6c63cee25 100644 --- a/so3/include/dirent.h +++ b/so3/include/dirent.h @@ -22,7 +22,7 @@ #define DIRENT_H_ typedef uint64_t ino_t; -typedef uint32_t off_t; +typedef int64_t off_t; struct dirent { ino_t d_ino; diff --git a/so3/include/net.h b/so3/include/net.h index 52a97f27c..b527ddf8a 100644 --- a/so3/include/net.h +++ b/so3/include/net.h @@ -66,17 +66,26 @@ #define SIOCSIFHWBROADCAST 0x8937 #define SIOCGIFCOUNT 0x8938 +/* network address struct used by the userspace */ +struct usr_sockaddr_in { + u16 sin_family; + in_port_t sin_port; + struct in_addr sin_addr; + uint8_t sin_zero[8]; +}; + void net_init(void); SYSCALL_DECLARE(socket, int domain, int type, int protocol); -SYSCALL_DECLARE(connect, int sockfd, const struct sockaddr *name, socklen_t namelen); -SYSCALL_DECLARE(bind, int sockfd, const struct sockaddr *addr, socklen_t addrlen); +SYSCALL_DECLARE(connect, int sockfd, const struct usr_sockaddr_in *name, socklen_t namelen); +SYSCALL_DECLARE(bind, int sockfd, const struct usr_sockaddr_in *addr, socklen_t addrlen); SYSCALL_DECLARE(listen, int sockfd, int backlog); -SYSCALL_DECLARE(accept, int sockfd, struct sockaddr *addr, socklen_t *addrlen); +SYSCALL_DECLARE(accept, int sockfd, struct usr_sockaddr_in *addr, socklen_t *addrlen); SYSCALL_DECLARE(recv, int sockfd, void *mem, size_t len, int flags); -SYSCALL_DECLARE(recvfrom, int sockfd, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); +SYSCALL_DECLARE(recvfrom, int sockfd, void *mem, size_t len, int flags, struct usr_sockaddr_in *from, socklen_t *fromlen); SYSCALL_DECLARE(send, int sockfd, const void *dataptr, size_t size, int flags); -SYSCALL_DECLARE(sendto, int sockfd, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen); +SYSCALL_DECLARE(sendto, int sockfd, const void *dataptr, size_t size, int flags, const struct usr_sockaddr_in *to, + socklen_t tolen); SYSCALL_DECLARE(setsockopt, int sockfd, int level, int optname, const void *optval, socklen_t optlen); #endif /* NET_H */ diff --git a/so3/include/process.h b/so3/include/process.h index 62f2273f3..5b444deab 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -153,6 +153,6 @@ void dump_proc(void); extern int __exec(const char *file); extern int __write(int fd, char *buffer, int count); -SYSCALL_DECLARE(brk, int increment); +SYSCALL_DECLARE(brk, long increment); #endif /* PROCESS_H */ diff --git a/so3/include/ptrace.h b/so3/include/ptrace.h index e2b828721..b77dfa09d 100644 --- a/so3/include/ptrace.h +++ b/so3/include/ptrace.h @@ -208,7 +208,7 @@ struct ptrace_peeksiginfo_args { int32_t nr; }; -SYSCALL_DECLARE(ptrace, enum __ptrace_request request, uint32_t pid, void *addr, void *data); +SYSCALL_DECLARE(ptrace, enum __ptrace_request request, int pid, void *addr, void *data); struct pcb; struct user; diff --git a/so3/include/signal.h b/so3/include/signal.h index 0969ad23e..1feb49783 100644 --- a/so3/include/signal.h +++ b/so3/include/signal.h @@ -94,7 +94,6 @@ typedef struct __sigaction { sigaction_t *sa; } __sigaction_t; -SYSCALL_DECLARE(sigaction, int signum, const sigaction_t *action, sigaction_t *old_action); SYSCALL_DECLARE(rt_sigaction, int signum, const sigaction_t *action, sigaction_t *old_action, size_t sigsize); SYSCALL_DECLARE(kill, int pid, int sig); SYSCALL_DECLARE(sigreturn, void); diff --git a/so3/include/stat.h b/so3/include/stat.h index 03cd9694c..6aea97153 100644 --- a/so3/include/stat.h +++ b/so3/include/stat.h @@ -20,6 +20,9 @@ #ifndef STAT_H #define STAT_H +#include + +/* Stat structure copied from Linux include/uapi/asm-generic/stat.h */ struct stat { unsigned long st_dev; /* Device. */ unsigned long st_ino; /* File serial number. */ @@ -43,27 +46,28 @@ struct stat { unsigned int __unused5; }; +/* This is for ARM32 compatibility on ARM64 as 64bits version of stat will be called. + Adapted from arch/arm64/include/asm/stat.h */ struct stat64 { - unsigned long long st_dev; /* Device. */ - unsigned long long st_ino; /* File serial number. */ - unsigned int st_mode; /* File mode. */ - unsigned int st_nlink; /* Link count. */ - unsigned int st_uid; /* User ID of the file's owner. */ - unsigned int st_gid; /* Group ID of the file's group. */ - unsigned long long st_rdev; /* Device number, if device. */ - unsigned long long __pad1; - long long st_size; /* Size of file, in bytes. */ - int st_blksize; /* Optimal block size for I/O. */ - int __pad2; - long long st_blocks; /* Number 512-byte blocks allocated. */ - int st_atime; /* Time of last access. */ - unsigned int st_atime_nsec; - int st_mtime; /* Time of last modification. */ - unsigned int st_mtime_nsec; - int st_ctime; /* Time of last status change. */ - unsigned int st_ctime_nsec; - unsigned int __unused4; - unsigned int __unused5; + u64 st_dev; /* Device. */ + unsigned char __pad0[4]; + u32 __st_ino; /* File serial number. */ + u32 st_mode; /* File mode. */ + u32 st_nlink; /* Link count. */ + u32 st_uid; /* User ID of the file's owner. */ + u32 st_gid; /* Group ID of the file's group. */ + u64 st_rdev; /* Device number, if device. */ + unsigned char __pad3[4]; + s64 st_size; /* Size of file, in bytes. */ + u32 st_blksize; /* Optimal block size for I/O. */ + u64 st_blocks; /* Number 512-byte blocks allocated. */ + u32 st_atime; /* Time of last access. */ + u32 st_atime_nsec; + u32 st_mtime; /* Time of last modification. */ + u32 st_mtime_nsec; + u32 st_ctime; /* Time of last status change. */ + u32 st_ctime_nsec; + u64 st_ino; }; #endif /* STAT_H */ diff --git a/so3/include/types.h b/so3/include/types.h index b12fad6fd..75efc09fc 100644 --- a/so3/include/types.h +++ b/so3/include/types.h @@ -116,8 +116,8 @@ typedef __u32 __bitwise __wsum; typedef unsigned __bitwise__ gfp_t; -typedef u32 time32_t; -typedef u64 time_t; +typedef long time32_t; +typedef s64 time_t; #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 1dbaf4381..7496a4054 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -108,8 +108,6 @@ #include #include -#include - struct iovec { void *iov_base; size_t iov_len; @@ -164,17 +162,18 @@ typedef enum { /* Syscall accessible from userspace */ -SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, unsigned short mode) -SYSCALL_DECLARE(open, const char *filename, int flags, unsigned short mode); -SYSCALL_DECLARE(read, int fd, void *buffer, int count); -SYSCALL_DECLARE(write, int fd, const void *buffer, int count); -SYSCALL_DECLARE(getdents64, int fd, char *buf, size_t count); +SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, umode_t mode) +SYSCALL_DECLARE(open, const char *filename, int flags, umode_t mode); +SYSCALL_DECLARE(read, int fd, void *buffer, size_t count); +SYSCALL_DECLARE(write, int fd, const void *buffer, size_t count); +SYSCALL_DECLARE(getdents64, int fd, struct dirent *buf, size_t count); SYSCALL_DECLARE(close, int fd); SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); SYSCALL_DECLARE(dup3, int oldfd, int newfd, int flags); -SYSCALL_DECLARE(stat, const char *path, struct stat *st); -SYSCALL_DECLARE(fstatat, const char *path, struct stat64 *st, int flags); +SYSCALL_DECLARE(stat64, const char *path, struct stat64 *st); +SYSCALL_DECLARE(fstatat64, int fd, const char *filename, struct stat64 *statbuf, int flag); +SYSCALL_DECLARE(newfstatat, int fd, const char *filename, struct stat *statbuf, int flag); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); diff --git a/so3/ipc/signal.c b/so3/ipc/signal.c index 20371e85c..24de966a5 100644 --- a/so3/ipc/signal.c +++ b/so3/ipc/signal.c @@ -111,8 +111,13 @@ void __mem(int a, char *adr, int log) { } #endif /* 0 */ -SYSCALL_DEFINE3(sigaction, int, signum, const sigaction_t *, action, sigaction_t *, old_action) +SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigaction_t *, old_action, size_t, sigsize) { + if (sigsize != sizeof(sigset_t)) { + LOG_WARNING("Invalid sigset size\n"); + return -EINVAL; + } + if (signum < 0 || signum >= _NSIG) { LOG_ERROR("signum not valid!\n"); return -EINVAL; @@ -132,16 +137,6 @@ SYSCALL_DEFINE3(sigaction, int, signum, const sigaction_t *, action, sigaction_t return 0; } -SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigaction_t *, old_actionm, size_t, sigsize) -{ - if (sigsize != sizeof(sigset_t)) { - LOG_WARNING("Invalid sigset size\n"); - return -EINVAL; - } - - return sys_do_sigaction(signum, action, old_actionm); -} - SYSCALL_DEFINE2(kill, int, pid, int, sig) { pcb_t *proc; diff --git a/so3/kernel/process.c b/so3/kernel/process.c index ba91a16e6..13ec54092 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -1090,7 +1090,7 @@ SYSCALL_DEFINE4(wait4, int, pid, uint32_t *, wstatus, uint32_t, options, void *, * @return This function will the position of the end of the heap / program *break before increment */ -SYSCALL_DEFINE1(brk, int, increment) +SYSCALL_DEFINE1(brk, long, increment) { pcb_t *pcb = current()->pcb; int ret_pointer; diff --git a/so3/kernel/ptrace.c b/so3/kernel/ptrace.c index 8750f6667..3a30ef729 100644 --- a/so3/kernel/ptrace.c +++ b/so3/kernel/ptrace.c @@ -64,7 +64,7 @@ void __check_ptrace_syscall(void) /* * Implementation of ptrace syscall */ -SYSCALL_DEFINE4(ptrace, enum __ptrace_request, request, uint32_t, pid, void *, addr, void *, data) +SYSCALL_DEFINE4(ptrace, enum __ptrace_request, request, int, pid, void *, addr, void *, data) { pcb_t *pcb; diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 50fe271b2..2d3f2acdf 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -35,9 +35,10 @@ extern uint32_t __get_syscall_stack_arg(uint32_t nr); extern void test_malloc(int test_no); +#warning Not updated, a rework is needed to avoid having a big array because of #ifdef ... static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [0 ... NR_SYSCALLS - 1] = NULL, - + /* #ifdef CONFIG_MMU [SYSCALL_GETPID] = __sys_getpid, #ifdef SYSCALL_GETTIMEOFDAY @@ -74,7 +75,6 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_THREAD_YIELD] = __sys_thread_yield, [SYSCALL_GETDENTS64] = __sys_getdents64, [SYSCALL_IOCTL] = __sys_ioctl, - [SYSCALL_FCNTL] = __sys_fcntl, [SYSCALL_LSEEK] = __sys_lseek, [SYSCALL_READV] = __sys_readv, [SYSCALL_WRITEV] = __sys_writev, @@ -132,6 +132,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_SETSOCKOPT] = __sys_setsockopt, [SYSCALL_RECVFROM] = __sys_recvfrom, #endif +*/ }; /* diff --git a/so3/net/net.c b/so3/net/net.c index d638f0797..21effb26c 100644 --- a/so3/net/net.c +++ b/so3/net/net.c @@ -134,29 +134,21 @@ struct ifreq2 { } ifr_ifru; }; -/* network address struct used by the userspace */ -struct sockaddr_in_usr { - u16 sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - uint8_t sin_zero[8]; -}; - /** * Adapt a userspace sockaddr to a lwip one. * Iwip sockaddr have a sa_len field as first byte * @param usr * @param lwip */ -struct sockaddr *user_to_lwip_sockadd(struct sockaddr_in_usr *usr, struct sockaddr_in *lwip) +struct sockaddr *user_to_lwip_sockadd(const struct usr_sockaddr_in *usr, struct sockaddr_in *lwip) { if (usr == NULL) { return NULL; } - memset(lwip, 0, sizeof(struct sockaddr)); + memset(lwip, 0, sizeof(struct sockaddr_in)); - lwip->sin_len = sizeof(struct sockaddr); + lwip->sin_len = sizeof(struct sockaddr_in); lwip->sin_family = usr->sin_family; lwip->sin_port = usr->sin_port; lwip->sin_addr = usr->sin_addr; @@ -424,7 +416,7 @@ SYSCALL_DEFINE3(socket, int, domain, int, type, int, protocol) return fd; } -SYSCALL_DEFINE3(connect, int, sockfd, const struct sockaddr *, addr, socklen_t, namelen) +SYSCALL_DEFINE3(connect, int, sockfd, const struct usr_sockaddr_in *, addr, socklen_t, namelen) { int ret; struct sockaddr_in addr_lwip; @@ -436,13 +428,13 @@ SYSCALL_DEFINE3(connect, int, sockfd, const struct sockaddr *, addr, socklen_t, return -EBADF; } - addr_ptr = user_to_lwip_sockadd((struct sockaddr_in_usr *) addr, &addr_lwip); + addr_ptr = user_to_lwip_sockadd(addr, &addr_lwip); ret = lwip_connect(lwip_fd, addr_ptr, namelen); return lwip_return(ret); } -SYSCALL_DEFINE3(bind, int, sockfd, const struct sockaddr *, addr, socklen_t, addrlen) +SYSCALL_DEFINE3(bind, int, sockfd, const struct usr_sockaddr_in *, addr, socklen_t, addrlen) { int ret; struct sockaddr_in addr_lwip; @@ -454,7 +446,7 @@ SYSCALL_DEFINE3(bind, int, sockfd, const struct sockaddr *, addr, socklen_t, add return -EBADF; } - addr_ptr = user_to_lwip_sockadd((struct sockaddr_in_usr *) addr, &addr_lwip); + addr_ptr = user_to_lwip_sockadd(addr, &addr_lwip); ret = lwip_bind(lwip_fd, addr_ptr, addrlen); return lwip_return(ret); @@ -473,7 +465,7 @@ SYSCALL_DEFINE2(listen, int, sockfd, int, backlog) return lwip_return(ret); } -SYSCALL_DEFINE3(accept, int, sockfd, struct sockaddr *, addr, socklen_t *, addrlen) +SYSCALL_DEFINE3(accept, int, sockfd, struct usr_sockaddr_in *, addr, socklen_t *, addrlen) { int fd, gfd, lwip_fd, lwip_bind_fd; struct file_operations *fops; @@ -485,7 +477,7 @@ SYSCALL_DEFINE3(accept, int, sockfd, struct sockaddr *, addr, socklen_t *, addrl return -EBADF; } - addr_ptr = user_to_lwip_sockadd((struct sockaddr_in_usr *) addr, &addr_lwip); + addr_ptr = user_to_lwip_sockadd(addr, &addr_lwip); fops = register_sock(); @@ -532,16 +524,21 @@ SYSCALL_DEFINE4(recv, int, sockfd, void *, mem, size_t, len, int, flags) return lwip_return(ret); } -SYSCALL_DEFINE6(recvfrom, int, sockfd, void *, mem, size_t, len, int, flags, struct sockaddr *, from, socklen_t *, fromlen) +SYSCALL_DEFINE6(recvfrom, int, sockfd, void *, mem, size_t, len, int, flags, struct usr_sockaddr_in *, from, socklen_t *, + fromlen) { int ret; + struct sockaddr_in from_lwip; + struct sockaddr *from_ptr; int lwip_fd = get_lwip_fd(sockfd); if (lwip_fd < 0) { return -EBADF; } - ret = lwip_recvfrom(lwip_fd, mem, len, flags, from, fromlen); + from_ptr = user_to_lwip_sockadd(from, &from_lwip); + + ret = lwip_recvfrom(lwip_fd, mem, len, flags, from_ptr, fromlen); return lwip_return(ret); } @@ -558,20 +555,21 @@ SYSCALL_DEFINE4(send, int, sockfd, const void *, dataptr, size_t, size, int, fla return lwip_return(ret); } -SYSCALL_DEFINE6(sendto, int, sockfd, const void *, dataptr, size_t, size, int, flags, const struct sockaddr *, to, socklen_t, - tolen) +SYSCALL_DEFINE6(sendto, int, sockfd, const void *, dataptr, size_t, size, int, flags, const struct usr_sockaddr_in *, to, + socklen_t, tolen) { int ret; struct sockaddr_in to_lwip; + struct sockaddr *to_ptr; int lwip_fd = get_lwip_fd(sockfd); if (lwip_fd < 0) { return -EBADF; } - user_to_lwip_sockadd((struct sockaddr_in_usr *) to, &to_lwip); + to_ptr = user_to_lwip_sockadd(to, &to_lwip); - ret = lwip_sendto(lwip_fd, dataptr, size, flags, (struct sockaddr *) &to_lwip, tolen); + ret = lwip_sendto(lwip_fd, dataptr, size, flags, to_ptr, tolen); return lwip_return(ret); } From a50e08ce5ef5d1a07f581f22ade88d9de270f5e2 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Mon, 13 Oct 2025 11:45:41 +0200 Subject: [PATCH 13/14] cleanups --- so3/fs/vfs.c | 46 +++++++++++++++++++++++++++----- so3/include/device/timer.h | 22 +++++++++------- so3/include/stat.h | 48 +++++++++++++++++----------------- so3/include/vfs.h | 9 ++++--- so3/kernel/syscalls.c | 46 +++----------------------------- usr/lib/libc/crt0.S | 1 + usr/lib/libc/include/syscall.h | 8 ++++++ 7 files changed, 95 insertions(+), 85 deletions(-) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index c1edd8ee1..485eb4f12 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -535,6 +535,9 @@ static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t off return virt_addr; } +/** + * @brief Low level stat implementation. + */ static long do_stat(const char *path, struct stat *st) { int ret; @@ -561,6 +564,9 @@ static long do_stat(const char *path, struct stat *st) return ret; } +/** + * @brief Function to convert stat to stat64 for ARM32 compatibility. + */ static struct stat64 stat_to_stat64(struct stat *st) { return (struct stat64) { @@ -600,7 +606,7 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, size_t, count) /** * @brief This function opens a file. Not all file types are supported. */ -SYSCALL_DEFINE3(open, const char *, filename, int, flags, umode_t, mode) +SYSCALL_DEFINE3(open, const char *, filename, int, flags, mode_t, mode) { int fd, gfd, ret = -1; uint32_t type; @@ -669,9 +675,9 @@ SYSCALL_DEFINE3(open, const char *, filename, int, flags, umode_t, mode) } /** - * Simple openat implementation ignoring dirfd for aarch64. + * @brief Simple openat implementation ignoring dirfd for aarch64. */ -SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, umode_t, mode) +SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, mode_t, mode) { if (dirfd != AT_FDCWD) { LOG_WARNING("dirfd parameters isn't supported\n"); @@ -682,7 +688,8 @@ SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, umode_t, } /* - * @brief gedetens64 read a directory entry which will be stored in a struct dirent entry + * @brief gedetens64 read a directory entry which will be stored in a struct dirent entry. + * This is used for readdir on userspace. * @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace. */ SYSCALL_DEFINE3(getdents64, int, fd, struct dirent *, buf, size_t, count) @@ -791,7 +798,7 @@ SYSCALL_DEFINE1(close, int, fd) } /** - * Simple dup3 implementation ignoring flags for aarch64. + * @brief Simple dup3 implementation ignoring flags for aarch64. */ SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) { @@ -809,7 +816,6 @@ SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) /** * @brief dup2 creates a synonym of oldfd on newfd - * */ SYSCALL_DEFINE2(dup2, int, oldfd, int, newfd) { @@ -872,6 +878,9 @@ SYSCALL_DEFINE1(dup, int, oldfd) #endif } +/** + * @brief On ARM32, stat64 syscall is called instead of stat. + */ SYSCALL_DEFINE2(stat64, const char *, path, struct stat64 *, st) { struct stat stat; @@ -886,6 +895,9 @@ SYSCALL_DEFINE2(stat64, const char *, path, struct stat64 *, st) return ret; } +/** + * @brief On ARM32, fstatat64 syscall is called instead of fstatat and stat in some condition. + */ SYSCALL_DEFINE4(fstatat64, int, fd, const char *, path, struct stat64 *, st, int, flags) { struct stat stat; @@ -910,6 +922,9 @@ SYSCALL_DEFINE4(fstatat64, int, fd, const char *, path, struct stat64 *, st, int return ret; } +/** + * @brief On aarch64, newfstatat syscall is called for stat. + */ SYSCALL_DEFINE4(newfstatat, int, fd, const char *, path, struct stat *, st, int, flags) { if (fd != AT_FDCWD) { @@ -1001,6 +1016,25 @@ SYSCALL_DEFINE3(lseek, int, fd, off_t, off, int, whence) return rc; } +/** + * @brief Implementation of llseek syscall for ARM32 which use it instead of lseek. + */ +SYSCALL_DEFINE5(llseek, int, fd, unsigned long, offset_high, unsigned long, offset_low, off_t *, result, unsigned, whence) +{ + off_t offset = ((off_t) offset_high << 32) | offset_low; + off_t ret; + + ret = sys_do_lseek(fd, offset, whence); + + if (ret >= 0) { + /* New offset is returned in the 64 bits of result. */ + *result = ret; + ret = 0; + } + + return ret; +} + /* * Implementation of the writev syscall */ diff --git a/so3/include/device/timer.h b/so3/include/device/timer.h index e8c213cb6..cdca9f822 100644 --- a/so3/include/device/timer.h +++ b/so3/include/device/timer.h @@ -27,26 +27,28 @@ /* Time conversion units */ -struct timespec32 { - time32_t tv_sec; /* seconds */ - time32_t tv_nsec; /* nanoseconds */ -}; - struct timespec { time_t tv_sec; /* seconds */ time_t tv_nsec; /* nanoseconds */ }; -struct timeval32 { - time32_t tv_sec; /* seconds */ - time32_t tv_usec; /* microseconds */ -}; - struct timeval { time_t tv_sec; /* seconds */ time_t tv_usec; /* microseconds */ }; +/* Time conversion units - ARM32 compatibility. */ + +struct timespec32 { + time32_t tv_sec; /* seconds */ + time32_t tv_nsec; /* nanoseconds */ +}; + +struct timeval32 { + time32_t tv_sec; /* seconds */ + time32_t tv_usec; /* microseconds */ +}; + /* All timing information below must be express in nanoseconds. The underlying hardware is responsible * to perform the necessary alignment on 64 bits. */ diff --git a/so3/include/stat.h b/so3/include/stat.h index 6aea97153..835b7d896 100644 --- a/so3/include/stat.h +++ b/so3/include/stat.h @@ -24,48 +24,48 @@ /* Stat structure copied from Linux include/uapi/asm-generic/stat.h */ struct stat { - unsigned long st_dev; /* Device. */ - unsigned long st_ino; /* File serial number. */ - unsigned int st_mode; /* File mode. */ - unsigned int st_nlink; /* Link count. */ - unsigned int st_uid; /* User ID of the file's owner. */ + unsigned long st_dev; /* Device. */ + unsigned long st_ino; /* File serial number. */ + unsigned int st_mode; /* File mode. */ + unsigned int st_nlink; /* Link count. */ + unsigned int st_uid; /* User ID of the file's owner. */ unsigned int st_gid; /* Group ID of the file's group. */ - unsigned long st_rdev; /* Device number, if device. */ + unsigned long st_rdev; /* Device number, if device. */ unsigned long __pad1; - long st_size; /* Size of file, in bytes. */ - int st_blksize; /* Optimal block size for I/O. */ + long st_size; /* Size of file, in bytes. */ + int st_blksize; /* Optimal block size for I/O. */ int __pad2; long st_blocks; /* Number 512-byte blocks allocated. */ - long st_atime; /* Time of last access. */ + long st_atime; /* Time of last access. */ unsigned long st_atime_nsec; - long st_mtime; /* Time of last modification. */ + long st_mtime; /* Time of last modification. */ unsigned long st_mtime_nsec; - long st_ctime; /* Time of last status change. */ + long st_ctime; /* Time of last status change. */ unsigned long st_ctime_nsec; unsigned int __unused4; unsigned int __unused5; }; -/* This is for ARM32 compatibility on ARM64 as 64bits version of stat will be called. - Adapted from arch/arm64/include/asm/stat.h */ +/* This is for ARM32 compatibility as 64bits version of stat will be called. + Adapted from arch/arm64/include/asm/stat.h on Linux */ struct stat64 { - u64 st_dev; /* Device. */ + u64 st_dev; /* Device. */ unsigned char __pad0[4]; - u32 __st_ino; /* File serial number. */ - u32 st_mode; /* File mode. */ - u32 st_nlink; /* Link count. */ - u32 st_uid; /* User ID of the file's owner. */ + u32 __st_ino; /* File serial number. */ + u32 st_mode; /* File mode. */ + u32 st_nlink; /* Link count. */ + u32 st_uid; /* User ID of the file's owner. */ u32 st_gid; /* Group ID of the file's group. */ - u64 st_rdev; /* Device number, if device. */ + u64 st_rdev; /* Device number, if device. */ unsigned char __pad3[4]; - s64 st_size; /* Size of file, in bytes. */ - u32 st_blksize; /* Optimal block size for I/O. */ + s64 st_size; /* Size of file, in bytes. */ + u32 st_blksize; /* Optimal block size for I/O. */ u64 st_blocks; /* Number 512-byte blocks allocated. */ - u32 st_atime; /* Time of last access. */ + u32 st_atime; /* Time of last access. */ u32 st_atime_nsec; - u32 st_mtime; /* Time of last modification. */ + u32 st_mtime; /* Time of last modification. */ u32 st_mtime_nsec; - u32 st_ctime; /* Time of last status change. */ + u32 st_ctime; /* Time of last status change. */ u32 st_ctime_nsec; u64 st_ino; }; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 7496a4054..e67bde3d6 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -1,7 +1,7 @@ /* * Copyright (C) 2014-2019 Daniel Rossier * Copyright (C) 2017 Xavier Ruppen - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -108,6 +108,8 @@ #include #include +typedef uint32_t mode_t; + struct iovec { void *iov_base; size_t iov_len; @@ -162,8 +164,8 @@ typedef enum { /* Syscall accessible from userspace */ -SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, umode_t mode) -SYSCALL_DECLARE(open, const char *filename, int flags, umode_t mode); +SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, mode_t mode) +SYSCALL_DECLARE(open, const char *filename, int flags, mode_t mode); SYSCALL_DECLARE(read, int fd, void *buffer, size_t count); SYSCALL_DECLARE(write, int fd, const void *buffer, size_t count); SYSCALL_DECLARE(getdents64, int fd, struct dirent *buf, size_t count); @@ -178,6 +180,7 @@ SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); +SYSCALL_DECLARE(llseek, int fd, unsigned long offset_high, unsigned long offset_low, off_t *result, unsigned whence); SYSCALL_DECLARE(writev, unsigned long fd, const struct iovec *vec, unsigned long vlen); SYSCALL_DECLARE(readv, unsigned long fd, const struct iovec *vec, unsigned long vlen); diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 2d3f2acdf..d87c60098 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -41,80 +41,45 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { /* #ifdef CONFIG_MMU [SYSCALL_GETPID] = __sys_getpid, -#ifdef SYSCALL_GETTIMEOFDAY [SYSCALL_GETTIMEOFDAY] = __sys_gettimeofday, -#endif -#ifdef SYSCALL_GETTIMEOFDAY_TIME32 - [SYSCALL_GETTIMEOFDAY_TIME32] = __sys_gettimeofday_time32, -#endif -#ifdef SYSCALL_CLOCK_GETTIME [SYSCALL_CLOCK_GETTIME] = __sys_clock_gettime, -#endif -#ifdef SYSCALL_CLOCK_GETTIME32 - [SYSCALL_CLOCK_GETTIME32] = __sys_clock_gettime32, -#endif [SYSCALL_EXIT] = __sys_exit, [SYSCALL_EXECVE] = __sys_execve, [SYSCALL_FORK] = __sys_fork, -#ifdef SYSCALL_WAITPID [SYSCALL_WAITPID] = __sys_waitpid, -#endif - [SYSCALL_WAIT4] = __sys_wait4, [SYSCALL_PTRACE] = __sys_ptrace, #endif [SYSCALL_READ] = __sys_read, [SYSCALL_WRITE] = __sys_write, -#ifdef SYSCALL_OPEN [SYSCALL_OPEN] = __sys_open, -#endif - [SYSCALL_OPENAT] = __sys_openat, [SYSCALL_CLOSE] = __sys_close, [SYSCALL_THREAD_CREATE] = __sys_thread_create, [SYSCALL_THREAD_JOIN] = __sys_thread_join, [SYSCALL_THREAD_EXIT] = __sys_thread_exit, [SYSCALL_THREAD_YIELD] = __sys_thread_yield, - [SYSCALL_GETDENTS64] = __sys_getdents64, + [SYSCALL_READDIR] = __sys_readdir, [SYSCALL_IOCTL] = __sys_ioctl, + [SYSCALL_FCNTL] = __sys_fcntl, [SYSCALL_LSEEK] = __sys_lseek, [SYSCALL_READV] = __sys_readv, [SYSCALL_WRITEV] = __sys_writev, #ifdef CONFIG_IPC_PIPE -#ifdef SYSCALL_PIPE [SYSCALL_PIPE] = __sys_pipe, -#endif - [SYSCALL_PIPE2] = __sys_pipe2, #endif [SYSCALL_DUP] = __sys_dup, -#ifdef SYSCALL_DUP2 [SYSCALL_DUP2] = __sys_dup2, -#endif - [SYSCALL_DUP3] = __sys_dup3, -#ifdef SYSCALL_STAT [SYSCALL_STAT] = __sys_stat, -#endif - [SYSCALL_FSTATAT] = __sys_fstatat, -#ifdef SYSCALL_MMAP [SYSCALL_MMAP] = __sys_mmap, -#endif -#ifdef SYSCALL_MMAP2 - [SYSCALL_MMAP2] = __sys_mmap2, -#endif [SYSCALL_NANOSLEEP] = __sys_nanosleep, #ifdef CONFIG_PROC_ENV - [SYSCALL_BRK] = __sys_brk, + [SYSCALL_SBRK] = __sys_sbrk, #endif [SYSCALL_MUTEX_LOCK] = __sys_mutex_lock, [SYSCALL_MUTEX_UNLOCK] = __sys_mutex_unlock, #ifdef CONFIG_IPC_SIGNAL -#ifdef SYSCALL_SIGACTION [SYSCALL_SIGACTION] = __sys_sigaction, -#endif - [SYSCALL_RT_SIGACTION] = __sys_rt_sigaction, [SYSCALL_KILL] = __sys_kill, -#ifdef SYSCALL_SIGRETURN [SYSCALL_SIGRETURN] = __sys_sigreturn, -#endif - [SYSCALL_RT_SIGRETURN] = __sys_rt_sigreturn, #endif #ifdef CONFIG_NET [SYSCALL_SOCKET] = __sys_socket, @@ -122,16 +87,13 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_LISTEN] = __sys_listen, [SYSCALL_ACCEPT] = __sys_accept, [SYSCALL_CONNECT] = __sys_connect, -#ifdef SYSCALL_RECV [SYSCALL_RECV] = __sys_recv, -#endif -#ifdef SYSCALL_SEND [SYSCALL_SEND] = __sys_send, -#endif [SYSCALL_SENDTO] = __sys_sendto, [SYSCALL_SETSOCKOPT] = __sys_setsockopt, [SYSCALL_RECVFROM] = __sys_recvfrom, #endif + [SYSCALL_SYSINFO] = __sys_sysinfo, */ }; diff --git a/usr/lib/libc/crt0.S b/usr/lib/libc/crt0.S index f8f1ea080..22ba5aeda 100755 --- a/usr/lib/libc/crt0.S +++ b/usr/lib/libc/crt0.S @@ -164,6 +164,7 @@ SYSCALLSTUB sys_settimeofday, syscallSetTimeOfDay 2 SYSCALLSTUB sys_clock_gettime, syscallClockGetTime 2 SYSCALLSTUB sys_sbrk, syscallSbrk 1 +SYSCALLSTUB sys_info, syscallSysinfo 2 SYSCALLSTUB sys_lseek, syscallLseek 3 diff --git a/usr/lib/libc/include/syscall.h b/usr/lib/libc/include/syscall.h index 65299ad58..2426d2bd4 100644 --- a/usr/lib/libc/include/syscall.h +++ b/usr/lib/libc/include/syscall.h @@ -88,9 +88,17 @@ #define syscallNanosleep 70 +#define syscallSysinfo 99 + #define syscallSetsockopt 110 #define syscallRecvfrom 111 + +#define SYSINFO_DUMP_HEAP 0 +#define SYSINFO_DUMP_SCHED 1 +#define SYSINFO_TEST_MALLOC 2 +#define SYSINFO_PRINTK 3 + #ifndef __ASSEMBLY__ #include From 9d8fd89a7cf64e7c505b0969b82a40b73d0e37e0 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Mon, 13 Oct 2025 19:05:38 +0200 Subject: [PATCH 14/14] rename llseek to _llseek --- so3/fs/vfs.c | 2 +- so3/include/vfs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 485eb4f12..5f7f76dff 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -1019,7 +1019,7 @@ SYSCALL_DEFINE3(lseek, int, fd, off_t, off, int, whence) /** * @brief Implementation of llseek syscall for ARM32 which use it instead of lseek. */ -SYSCALL_DEFINE5(llseek, int, fd, unsigned long, offset_high, unsigned long, offset_low, off_t *, result, unsigned, whence) +SYSCALL_DEFINE5(_llseek, int, fd, unsigned long, offset_high, unsigned long, offset_low, off_t *, result, unsigned, whence) { off_t offset = ((off_t) offset_high << 32) | offset_low; off_t ret; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index e67bde3d6..5c72e7208 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -180,7 +180,7 @@ SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); -SYSCALL_DECLARE(llseek, int fd, unsigned long offset_high, unsigned long offset_low, off_t *result, unsigned whence); +SYSCALL_DECLARE(_llseek, int fd, unsigned long offset_high, unsigned long offset_low, off_t *result, unsigned whence); SYSCALL_DECLARE(writev, unsigned long fd, const struct iovec *vec, unsigned long vlen); SYSCALL_DECLARE(readv, unsigned long fd, const struct iovec *vec, unsigned long vlen);