syscalls: clockget

This commit is contained in:
Matheus
2023-07-05 22:13:29 -03:00
parent 3019ae0a55
commit e05e74e1a5
4 changed files with 61 additions and 10 deletions
+3 -1
View File
@@ -27,6 +27,7 @@ extern syscall_faccessat
extern syscall_unlinkat extern syscall_unlinkat
extern syscall_ioctl extern syscall_ioctl
extern syscall_mkdirat extern syscall_mkdirat
extern syscall_clockget
syscalltab: syscalltab:
dq syscall_print dq syscall_print
dq syscall_mmap dq syscall_mmap
@@ -56,7 +57,8 @@ dq syscall_faccessat
dq syscall_unlinkat dq syscall_unlinkat
dq syscall_ioctl dq syscall_ioctl
dq syscall_mkdirat dq syscall_mkdirat
syscallcount equ 28 dq syscall_clockget
syscallcount equ 29
section .text section .text
global arch_syscall_entry global arch_syscall_entry
; on entry: ; on entry:
+5 -3
View File
@@ -4,7 +4,7 @@
#ifdef SYSCALL_LOGGING #ifdef SYSCALL_LOGGING
#define SYSCALL_COUNT 28 #define SYSCALL_COUNT 29
#define LOGSTR(x) arch_e9_puts(x) #define LOGSTR(x) arch_e9_puts(x)
static char *name[] = { static char *name[] = {
@@ -35,7 +35,8 @@ static char *name[] = {
"faccessat", "faccessat",
"unlinkat", "unlinkat",
"ioctl", "ioctl",
"mkdirat" "mkdirat",
"clockget"
}; };
static char *args[] = { static char *args[] = {
@@ -66,7 +67,8 @@ static char *args[] = {
"dirfd %d pathname %s mode %d flags %d", // faccessat "dirfd %d pathname %s mode %d flags %d", // faccessat
"dirfd %d pathname %d flags %d", // unlinkat "dirfd %d pathname %d flags %d", // unlinkat
"fd %d request %lu argument %d", // ioctl "fd %d request %lu argument %d", // ioctl
"dirfd %d path %s mode %o" // mkdirat "dirfd %d path %s mode %o", // mkdirat
"clockid %d timespec %p" // clockget
}; };
#endif #endif
+40
View File
@@ -0,0 +1,40 @@
#include <kernel/syscalls.h>
#include <kernel/abi.h>
#include <time.h>
#include <kernel/timekeeper.h>
#include <kernel/vmm.h>
#define CLOCK_REALTIME 0
#define CLOCK_BOOTTIME 7
syscallret_t syscall_clockget(context_t *, int clockid, timespec_t *tp){
syscallret_t ret = {
.ret = -1
};
if ((void *)tp > USERSPACE_END) {
ret.errno = EFAULT;
return ret;
}
switch (clockid) {
case CLOCK_REALTIME:
// TODO safe memcpy
*tp = timekeeper_time();
ret.errno = 0;
break;
case CLOCK_BOOTTIME:
// TODO safe memcpy
*tp = timekeeper_timefromboot();
ret.errno = 0;
break;
default:
ret.errno = EINVAL;
break;
}
ret.ret = ret.errno ? -1 : 0;
return ret;
}
+13 -6
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 diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
new file mode 100644 new file mode 100644
index 0000000..28f6942 index 0000000..97b963a
--- /dev/null --- /dev/null
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
@@ -0,0 +1,295 @@ @@ -0,0 +1,301 @@
+#include <bits/ensure.h> +#include <bits/ensure.h>
+#include <mlibc/debug.hpp> +#include <mlibc/debug.hpp>
+#include <mlibc/all-sysdeps.hpp> +#include <mlibc/all-sysdeps.hpp>
@@ -347,10 +347,12 @@ index 0000000..28f6942
+ } + }
+ +
+ int sys_futex_wait(int *pointer, int expected, const struct timespec *time) { + int sys_futex_wait(int *pointer, int expected, const struct timespec *time) {
+ mlibc::infoLogger() << "mlibc: futex wait is a stub" << frg::endlog;
+ // TODO UNSTUB + // TODO UNSTUB
+ return ENOSYS; + return ENOSYS;
+ } + }
+ int sys_futex_wake(int *pointer) { + int sys_futex_wake(int *pointer) {
+ mlibc::infoLogger() << "mlibc: futex wake is a stub" << frg::endlog;
+ // TODO UNSTUB + // TODO UNSTUB
+ return ENOSYS; + return ENOSYS;
+ } + }
@@ -426,8 +428,12 @@ index 0000000..28f6942
+ } + }
+ +
+ int sys_clock_get(int clock, time_t *secs, long *nanos) { + int sys_clock_get(int clock, time_t *secs, long *nanos) {
+ // TODO UNSTUB + struct timespec ts;
+ return ENOSYS; + long ret;
+ int err = syscall(SYSCALL_CLOCKGET, &ret, clock, (uint64_t)&ts);
+ *secs = ts.tv_sec;
+ *nanos = ts.tv_nsec;
+ return err;
+ } + }
+ +
+} // namespace mlibc +} // namespace mlibc
@@ -451,10 +457,10 @@ index 0000000..990eca0
+#endif +#endif
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
new file mode 100644 new file mode 100644
index 0000000..a569d38 index 0000000..96da753
--- /dev/null --- /dev/null
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
@@ -0,0 +1,51 @@ @@ -0,0 +1,52 @@
+#ifndef _SYSCALL_H_INCLUDE +#ifndef _SYSCALL_H_INCLUDE
+#define _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE
+ +
@@ -486,6 +492,7 @@ index 0000000..a569d38
+#define SYSCALL_UNLINKAT 25 +#define SYSCALL_UNLINKAT 25
+#define SYSCALL_IOCTL 26 +#define SYSCALL_IOCTL 26
+#define SYSCALL_MKDIRAT 27 +#define SYSCALL_MKDIRAT 27
+#define SYSCALL_CLOCKGET 28
+ +
+#include <stddef.h> +#include <stddef.h>
+#include <stdint.h> +#include <stdint.h>