kernel: stat syscall family

This commit is contained in:
Matheus
2023-05-13 23:14:26 -03:00
parent c6f9f295ee
commit cabd9d7e4b
4 changed files with 164 additions and 5 deletions
+21 -4
View File
@@ -133,10 +133,10 @@ index 0000000..e5b087a
+
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
new file mode 100644
index 0000000..81ba749
index 0000000..dc6bd0e
--- /dev/null
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
@@ -0,0 +1,163 @@
@@ -0,0 +1,178 @@
+#include <bits/ensure.h>
+#include <mlibc/debug.hpp>
+#include <mlibc/all-sysdeps.hpp>
@@ -200,6 +200,21 @@ index 0000000..81ba749
+ return 0;
+ }
+
+ int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags, struct stat *statbuf) {
+ long ret;
+ switch (fsfdt) {
+ case fsfd_target::path:
+ return syscall(SYSCALL_FSTATAT, &ret, AT_FDCWD, (uint64_t)path, (uint64_t)statbuf, 0);
+ case fsfd_target::fd:
+ return syscall(SYSCALL_FSTAT, &ret, fd, (uint64_t)statbuf);
+ case fsfd_target::fd_path:
+ return syscall(SYSCALL_FSTATAT, &ret, fd, (uint64_t)path, (uint64_t)statbuf, flags);
+ default:
+ mlibc::infoLogger() << "mlibc: stat: Unknown fsfd_target: " << (int)fsfdt << frg::endlog;
+ return ENOSYS;
+ }
+ }
+
+ pid_t sys_getpid() {
+ long ret;
+ syscall(SYSCALL_GETPID, &ret);
@@ -319,10 +334,10 @@ index 0000000..990eca0
+#endif
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
new file mode 100644
index 0000000..fe5ea34
index 0000000..fde482a
--- /dev/null
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
@@ -0,0 +1,32 @@
@@ -0,0 +1,34 @@
+#ifndef _SYSCALL_H_INCLUDE
+#define _SYSCALL_H_INCLUDE
+
@@ -335,6 +350,8 @@ index 0000000..fe5ea34
+#define SYSCALL_ARCHCTL 6
+#define SYSCALL_WRITE 7
+#define SYSCALL_GETPID 8
+#define SYSCALL_FSTAT 9
+#define SYSCALL_FSTATAT 10
+
+#include <stddef.h>
+#include <stdint.h>