From c327e2f2bfbdf9a82b0aadeb66ba9f9a5fee04b2 Mon Sep 17 00:00:00 2001 From: Kailun Qin Date: Mon, 10 Jun 2024 22:44:06 -0400 Subject: [PATCH] fixup! [LibOS] Add support for timerfd system calls Signed-off-by: Kailun Qin --- libos/src/sys/libos_timerfd.c | 20 ++++++++++---------- libos/test/regression/timerfd.c | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libos/src/sys/libos_timerfd.c b/libos/src/sys/libos_timerfd.c index a0fc53104f..f6fefebc64 100644 --- a/libos/src/sys/libos_timerfd.c +++ b/libos/src/sys/libos_timerfd.c @@ -162,17 +162,17 @@ long libos_syscall_timerfd_settime(int fd, int flags, const struct __kernel_itim if (!hdl) return -EBADF; + if (hdl->type != TYPE_TIMERFD) { + ret = -EINVAL; + goto out; + } + if (hdl->info.timerfd.broken_in_child) { log_warning("Child process tried to access timerfd created by parent process. This is " "disallowed in Gramine."); return -EIO; } - if (hdl->type != TYPE_TIMERFD) { - ret = -EINVAL; - goto out; - } - if (!is_user_memory_readable(value, sizeof(*value))) { ret = -EFAULT; goto out; @@ -253,17 +253,17 @@ long libos_syscall_timerfd_gettime(int fd, struct __kernel_itimerspec* value) { if (!hdl) return -EBADF; + if (hdl->type != TYPE_TIMERFD) { + ret = -EINVAL; + goto out; + } + if (hdl->info.timerfd.broken_in_child) { log_warning("Child process tried to access timerfd created by parent process. This is " "disallowed in Gramine."); return -EIO; } - if (hdl->type != TYPE_TIMERFD) { - ret = -EINVAL; - goto out; - } - if (!is_user_memory_writable(value, sizeof(*value))) { ret = -EFAULT; goto out; diff --git a/libos/test/regression/timerfd.c b/libos/test/regression/timerfd.c index ed12780c50..cd4ee10520 100644 --- a/libos/test/regression/timerfd.c +++ b/libos/test/regression/timerfd.c @@ -210,7 +210,7 @@ static void test_epoll_modes(int fd) { errx(1, "epoll: unexpected number of fds (expected 1, got %u)", nfds); /* waiting for another event without reading the expiration count: here, even though the timer - * expired at least one, there is no event reported because we're in edge-triggered mode (which + * expired at least once, there is no event reported because we're in edge-triggered mode (which * does not "reset" the event since there was no read) */ nfds = CHECK(epoll_wait(epfd, events, 1, /*timeout=*/PERIODIC_INTERVAL * 1000 * 2)); if (nfds != 0)