]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-timerfd: Add syscall interface 1179/head
authorAndrei Tatar <andrei@unikraft.io>
Fri, 24 Nov 2023 15:46:14 +0000 (16:46 +0100)
committerAndrei Tatar <andrei@unikraft.io>
Wed, 29 Nov 2023 00:38:30 +0000 (01:38 +0100)
This change implements the syscall interface to posix-timerfd, adding
the following syscalls to Unikraft:
- timerfd_create
- timerfd_settime
- timerfd_gettime

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
lib/posix-timerfd/Makefile.uk
lib/posix-timerfd/timerfd.c

index ea68dc070e580724ff872c6df115be6c262f1d4d..e5f010ce4a01a04dd22448ee42888e8ae5671fcc 100644 (file)
@@ -4,3 +4,7 @@ CINCLUDES-$(CONFIG_LIBPOSIX_TIMERFD) += -I$(LIBPOSIX_TIMERFD_BASE)/include
 CXXINCLUDES-$(CONFIG_LIBPOSIX_TIMERFD) += -I$(LIBPOSIX_TIMERFD_BASE)/include
 
 LIBPOSIX_TIMERFD_SRCS-y += $(LIBPOSIX_TIMERFD_BASE)/timerfd.c
+
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_TIMERFD) += timerfd_create-2
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_TIMERFD) += timerfd_settime-4
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_TIMERFD) += timerfd_gettime-2
index ec690a0cbf49abf645d45d48078b3bad511c3d77..fc895b40ed5afa2ab7afd5abdc77eb455730b898 100644 (file)
@@ -17,6 +17,7 @@
 #include <uk/mutex.h>
 #include <uk/sched.h>
 #include <uk/timeutil.h>
+#include <uk/syscall.h>
 
 
 static const char TIMERFD_VOLID[] = "timerfd_vol";
@@ -330,3 +331,45 @@ int uk_sys_timerfd_gettime(const struct uk_file *f,
        curr_value->it_value = uk_time_spec_from_nsec(st.next);
        return 0;
 }
+
+/* Syscalls */
+
+UK_SYSCALL_R_DEFINE(int, timerfd_create, int, id, int, flags)
+{
+       return uk_sys_timerfd_create(id, flags);
+}
+
+UK_SYSCALL_R_DEFINE(int, timerfd_settime, int, fd, int, flags,
+                   const struct itimerspec *, new_value,
+                   struct itimerspec *, old_value)
+{
+       int r;
+       struct uk_ofile *of;
+
+       if (unlikely(!new_value))
+               return -EFAULT;
+
+       of = uk_fdtab_get(fd);
+       if (unlikely(!of))
+               return -EBADF;
+       r = uk_sys_timerfd_settime(of->file, flags, new_value, old_value);
+       uk_fdtab_ret(of);
+       return r;
+}
+
+UK_SYSCALL_R_DEFINE(int, timerfd_gettime, int, fd,
+                   struct itimerspec *, curr_value)
+{
+       int r;
+       struct uk_ofile *of;
+
+       if (unlikely(!curr_value))
+               return -EFAULT;
+
+       of = uk_fdtab_get(fd);
+       if (unlikely(!of))
+               return -EBADF;
+       r = uk_sys_timerfd_gettime(of->file, curr_value);
+       uk_fdtab_ret(of);
+       return r;
+}