From dd9351843b8ee35905706e085bb0a31f05fd2b32 Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 13 Jul 2023 13:33:17 +0300 Subject: [PATCH] [orbis-kernel] Dummy sys_stat implementation Ignore shm_open Correct Stat argument for syscalls --- orbis-kernel/include/orbis/sys/sysproto.hpp | 14 ++++----- orbis-kernel/src/sys/sys_descrip.cpp | 3 +- orbis-kernel/src/sys/sys_uipc_shm.cpp | 11 ++++++- orbis-kernel/src/sys/sys_vfs.cpp | 33 +++++++++++++++++---- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/orbis-kernel/include/orbis/sys/sysproto.hpp b/orbis-kernel/include/orbis/sys/sysproto.hpp index 804cb5c61..bba47387d 100644 --- a/orbis-kernel/include/orbis/sys/sysproto.hpp +++ b/orbis-kernel/include/orbis/sys/sysproto.hpp @@ -15,7 +15,7 @@ struct ModuleInfo; struct ModuleInfoEx; struct KEvent; struct timespec; - +struct Stat; struct stack_t; SysResult nosys(Thread *thread); @@ -173,9 +173,9 @@ SysResult sys_ntp_adjtime(Thread *thread, ptr tp); SysResult sys_setgid(Thread *thread, gid_t gid); SysResult sys_setegid(Thread *thread, gid_t egid); SysResult sys_seteuid(Thread *thread, uid_t euid); -SysResult sys_stat(Thread *thread, ptr path, ptr ub); -SysResult sys_fstat(Thread *thread, sint fd, ptr ub); -SysResult sys_lstat(Thread *thread, ptr path, ptr ub); +SysResult sys_stat(Thread *thread, ptr path, ptr ub); +SysResult sys_fstat(Thread *thread, sint fd, ptr ub); +SysResult sys_lstat(Thread *thread, ptr path, ptr ub); SysResult sys_pathconf(Thread *thread, ptr path, sint name); SysResult sys_fpathconf(Thread *thread, sint fd, sint name); SysResult sys_getrlimit(Thread *thread, uint which, ptr rlp); @@ -255,7 +255,7 @@ SysResult sys_pwritev(Thread *thread, sint fd, ptr iovp, SysResult sys_fhopen(Thread *thread, ptr u_fhp, sint flags); SysResult sys_fhstat(Thread *thread, ptr u_fhp, - ptr sb); + ptr sb); SysResult sys_modnext(Thread *thread, sint modid); SysResult sys_modstat(Thread *thread, sint modid, ptr stat); SysResult sys_modfnext(Thread *thread, sint modid); @@ -535,8 +535,8 @@ SysResult sys_fchownat(Thread *thread, sint fd, ptr path, uid_t uid, gid_t gid, sint flag); SysResult sys_fexecve(Thread *thread, sint fd, ptr> argv, ptr> envv); -SysResult sys_fstatat(Thread *thread, sint fd, ptr path, - ptr buf, sint flag); +SysResult sys_fstatat(Thread *thread, sint fd, ptr path, ptr buf, + sint flag); SysResult sys_futimesat(Thread *thread, sint fd, ptr path, ptr times); SysResult sys_linkat(Thread *thread, sint fd1, ptr path1, sint fd2, diff --git a/orbis-kernel/src/sys/sys_descrip.cpp b/orbis-kernel/src/sys/sys_descrip.cpp index c370b6eb7..a3957ac69 100644 --- a/orbis-kernel/src/sys/sys_descrip.cpp +++ b/orbis-kernel/src/sys/sys_descrip.cpp @@ -23,8 +23,7 @@ orbis::SysResult orbis::sys_close(Thread *thread, sint fd) { orbis::SysResult orbis::sys_closefrom(Thread *thread, sint lowfd) { return ErrorCode::NOSYS; } -orbis::SysResult orbis::sys_fstat(Thread *thread, sint fd, - ptr ub) { +orbis::SysResult orbis::sys_fstat(Thread *thread, sint fd, ptr ub) { return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_nfstat(Thread *thread, sint fd, diff --git a/orbis-kernel/src/sys/sys_uipc_shm.cpp b/orbis-kernel/src/sys/sys_uipc_shm.cpp index 51f38feea..c189eab44 100644 --- a/orbis-kernel/src/sys/sys_uipc_shm.cpp +++ b/orbis-kernel/src/sys/sys_uipc_shm.cpp @@ -1,8 +1,17 @@ +#include "orbis-config.hpp" #include "sys/sysproto.hpp" +#include "utils/Logs.hpp" orbis::SysResult orbis::sys_shm_open(Thread *thread, ptr path, sint flags, mode_t mode) { - return ErrorCode::NOSYS; + char _name[256]; + if (auto result = ureadString(_name, sizeof(_name), path); + result != ErrorCode{}) { + return result; + } + + ORBIS_LOG_TODO(__FUNCTION__, _name, flags, mode); + return {}; } orbis::SysResult orbis::sys_shm_unlink(Thread *thread, ptr path) { return ErrorCode::NOSYS; diff --git a/orbis-kernel/src/sys/sys_vfs.cpp b/orbis-kernel/src/sys/sys_vfs.cpp index f27b97bbd..c4bb748ec 100644 --- a/orbis-kernel/src/sys/sys_vfs.cpp +++ b/orbis-kernel/src/sys/sys_vfs.cpp @@ -1,3 +1,4 @@ +#include "stat.hpp" #include "sys/sysproto.hpp" #include "utils/Logs.hpp" @@ -103,16 +104,36 @@ orbis::SysResult orbis::sys_eaccess(Thread *thread, ptr path, sint flags) { return ErrorCode::NOSYS; } -orbis::SysResult orbis::sys_stat(Thread *thread, ptr path, - ptr ub) { - return ErrorCode::NOSYS; +orbis::SysResult orbis::sys_stat(Thread *thread, ptr path, ptr ub) { + ORBIS_LOG_TODO(__FUNCTION__, path, ub); + auto result = sys_open(thread, path, 0, 0); + if (result.isError()) { + return result; + } + + auto fd = thread->retval[0]; + result = sys_lseek(thread, fd, 0, SEEK_END); + if (result.isError()) { + sys_close(thread, fd); + return result; + } + + auto len = thread->retval[0]; + *ub = {}; + ub->size = len; + ub->blksize = 1; + ub->blocks = len; + ub->mode = 0777; + sys_close(thread, fd); + thread->retval[0] = 0; + return {}; } orbis::SysResult orbis::sys_fstatat(Thread *thread, sint fd, ptr path, - ptr buf, sint flag) { + ptr buf, sint flag) { return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_lstat(Thread *thread, ptr path, - ptr ub) { + ptr ub) { return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_nstat(Thread *thread, ptr path, @@ -257,7 +278,7 @@ orbis::sys_fhopen(Thread *thread, ptr u_fhp, sint flags) { } orbis::SysResult orbis::sys_fhstat(Thread *thread, ptr u_fhp, - ptr sb) { + ptr sb) { return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_fhstatfs(Thread *thread,