syscalls: implement clock_getres

This commit is contained in:
Matheus
2026-04-23 12:10:26 -03:00
parent 8b41077128
commit a15b034aa8
4 changed files with 103 additions and 8 deletions
+3 -1
View File
@@ -102,6 +102,7 @@ extern syscall_yield
extern syscall_fstatvfs
extern syscall_fstatvfsat
extern syscall_getsockopt
extern syscall_clock_getres
syscalltab:
dq syscall_print
dq syscall_mmap
@@ -206,7 +207,8 @@ dq syscall_yield
dq syscall_fstatvfs
dq syscall_fstatvfsat
dq syscall_getsockopt
syscallcount equ 103
dq syscall_clock_getres
syscallcount equ 104
section .text
global arch_syscall_entry
; on entry:
+3 -1
View File
@@ -9,7 +9,7 @@
void arch_interrupt_disable();
void arch_interrupt_enable();
#define SYSCALL_COUNT 103
#define SYSCALL_COUNT 104
#define LOGSTR(x) arch_e9_puts(x)
static char *name[] = {
@@ -116,6 +116,7 @@ static char *name[] = {
"fstatvfs",
"fstatvfsat",
"getsockopt",
"clock_getres",
};
static char *args[] = {
@@ -222,6 +223,7 @@ static char *args[] = {
"fd %d ustat %p", // fstatvfs
"dirfd %d path %s ustat %p flags %d", // fstatvfsat
"fd %d level %d optname %d optval %p optlen %p", // getsockopt
"clockid %d timespec %p", // clock_getres
};
#endif
+34
View File
@@ -0,0 +1,34 @@
#include <kernel/syscalls.h>
#include <time.h>
#include <kernel/usercopy.h>
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#define CLOCK_BOOTTIME 7
syscallret_t syscall_clock_getres(context_t *, int clockid, timespec_t *res) {
syscallret_t ret;
switch (clockid) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
case CLOCK_BOOTTIME:
if (res) {
timespec_t ts = {
.s = 0,
.ns = 1
};
ret.errno = usercopy_touser(res, &ts, sizeof(timespec_t));
} else {
ret.errno = 0;
}
break;
default:
ret.errno = EINVAL;
break;
}
ret.ret = ret.errno ? -1 : 0;
return ret;
}
+63 -6
View File
@@ -224,7 +224,7 @@ index 07dbe11..3ece6ec 100644
constexpr bool logLdPath = false;
constexpr bool logSymbolVersions = false;
diff --git mlibc-clean/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
index 939925e..5c3ca08 100644
index 939925e..7841cfe 100644
--- mlibc-clean/sysdeps/astral/generic/generic.cpp
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
@@ -1,4 +1,5 @@
@@ -250,51 +250,93 @@ index 939925e..5c3ca08 100644
namespace mlibc {
int sys_setgroups(size_t size, const gid_t *list) {
@@ -31,13 +42,170 @@ namespace mlibc {
@@ -31,13 +42,212 @@ namespace mlibc {
return 0;
}
+ int sys_setxattr(const char *path, const char *name,
+ const void *val, size_t size, int flags) {
+ (void)path;
+ (void)name;
+ (void)val;
+ (void)size;
+ (void)flags;
+ return ENOTSUP;
+ }
+ int sys_lsetxattr(const char *path, const char *name,
+ const void *val, size_t size, int flags) {
+ (void)path;
+ (void)name;
+ (void)val;
+ (void)size;
+ (void)flags;
+ return ENOTSUP;
+ }
+
+ int sys_fsetxattr(int fd, const char *name, const void *val,
+ size_t size, int flags) {
+ (void)fd;
+ (void)name;
+ (void)val;
+ (void)size;
+ (void)flags;
+ return ENOTSUP;
+ }
+
+ int sys_getxattr(const char *path, const char *name,
+ void *val, size_t size, ssize_t *nread) {
+ (void)path;
+ (void)name;
+ (void)val;
+ (void)size;
+ (void)nread;
+ return ENOTSUP;
+ }
+
+ int sys_lgetxattr(const char *path, const char *name,
+ void *val, size_t size, ssize_t *nread) {
+ (void)path;
+ (void)name;
+ (void)val;
+ (void)size;
+ (void)nread;
+ return ENOTSUP;
+ }
+
+ int sys_fgetxattr(int fd, const char *name, void *val,
+ size_t size, ssize_t *nread) {
+ (void)fd;
+ (void)name;
+ (void)val;
+ (void)size;
+ (void)nread;
+ return ENOTSUP;
+ }
+
+ int sys_listxattr(const char *path, char *list, size_t size,
+ ssize_t *nread) {
+ (void)path;
+ (void)list;
+ (void)size;
+ (void)nread;
+ return ENOTSUP;
+ }
+
+ int sys_llistxattr(const char *path, char *list, size_t size,
+ ssize_t *nread) {
+ (void)path;
+ (void)list;
+ (void)size;
+ (void)nread;
+ return ENOTSUP;
+ }
+
+ int sys_flistxattr(int fd, char *list, size_t size,
+ ssize_t *nread) {
+ (void)fd;
+ (void)list;
+ (void)size;
+ (void)nread;
+ return ENOTSUP;
+ }
+
@@ -424,7 +466,7 @@ index 939925e..5c3ca08 100644
}
int sys_inet_configured(bool *ipv4, bool *ipv6) {
@@ -47,6 +215,71 @@ namespace mlibc {
@@ -47,6 +257,71 @@ namespace mlibc {
return 0;
}
@@ -496,7 +538,7 @@ index 939925e..5c3ca08 100644
int sys_readv(int fd, const struct iovec *iovs, int iovc, ssize_t *bytes_read) {
long r;
int error = syscall(SYSCALL_READV, &r, fd, (uint64_t)iovs, iovc);
@@ -489,6 +722,7 @@ namespace mlibc {
@@ -489,6 +764,7 @@ namespace mlibc {
int sys_setsockopt(int fd, int layer, int number, const void *buffer, socklen_t size) {
long ret;
@@ -504,6 +546,20 @@ index 939925e..5c3ca08 100644
return syscall(SYSCALL_SETSOCKOPT, &ret, fd, layer, number, (uint64_t)buffer, size);
}
@@ -932,4 +1208,13 @@ namespace mlibc {
*nanos = ts.tv_nsec;
return err;
}
+
+ int sys_clock_getres(int clock, time_t *secs, long *nanos) {
+ struct timespec ts;
+ long ret;
+ int err = syscall(SYSCALL_CLOCK_GETRES, &ret, clock, (uint64_t)&ts);
+ *secs = ts.tv_sec;
+ *nanos = ts.tv_nsec;
+ return err;
+ }
} // namespace mlibc
diff --git mlibc-clean/sysdeps/astral/include/astral/archctl.h mlibc-workdir/sysdeps/astral/include/astral/archctl.h
index 7e4f2a1..ecc2677 100644
--- mlibc-clean/sysdeps/astral/include/astral/archctl.h
@@ -527,10 +583,10 @@ index 7e4f2a1..ecc2677 100644
#ifdef __cplusplus
extern "C" {
diff --git mlibc-clean/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
index a6c4067..7568e64 100644
index a6c4067..f1e0b65 100644
--- mlibc-clean/sysdeps/astral/include/astral/syscall.h
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
@@ -103,6 +103,10 @@
@@ -103,6 +103,11 @@
#define SYSCALL_SYSINFO 96
#define SYSCALL_WRITEV 97
#define SYSCALL_READV 98
@@ -538,6 +594,7 @@ index a6c4067..7568e64 100644
+#define SYSCALL_FSTATVFS 100
+#define SYSCALL_FSTATVFSAT 101
+#define SYSCALL_GETSOCKOPT 102
+#define SYSCALL_CLOCK_GETRES 103
#ifndef __MLIBC_ABI_ONLY