aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2023-02-01 16:10:54 -0500
committerJuan Quintela <quintela@redhat.com>2023-02-06 19:22:56 +0100
commitd5890ea0722831eea76a0efd23a496b3e8815fe8 (patch)
treec9d365c7db03036f2928100155bb8d77ccad6bee /util
parentd9df92925ef2b7ca8774ef44b0e1f859a91d4cd6 (diff)
util/userfaultfd: Add uffd_open()
Add a helper to create the uffd handle. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/userfaultfd.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/util/userfaultfd.c b/util/userfaultfd.c
index f1cd6af2b1..4953b3137d 100644
--- a/util/userfaultfd.c
+++ b/util/userfaultfd.c
@@ -19,6 +19,15 @@
#include <sys/syscall.h>
#include <sys/ioctl.h>
+int uffd_open(int flags)
+{
+#if defined(__NR_userfaultfd)
+ return syscall(__NR_userfaultfd, flags);
+#else
+ return -EINVAL;
+#endif
+}
+
/**
* uffd_query_features: query UFFD features
*
@@ -32,7 +41,7 @@ int uffd_query_features(uint64_t *features)
struct uffdio_api api_struct = { 0 };
int ret = -1;
- uffd_fd = syscall(__NR_userfaultfd, O_CLOEXEC);
+ uffd_fd = uffd_open(O_CLOEXEC);
if (uffd_fd < 0) {
trace_uffd_query_features_nosys(errno);
return -1;
@@ -69,7 +78,7 @@ int uffd_create_fd(uint64_t features, bool non_blocking)
uint64_t ioctl_mask = BIT(_UFFDIO_REGISTER) | BIT(_UFFDIO_UNREGISTER);
flags = O_CLOEXEC | (non_blocking ? O_NONBLOCK : 0);
- uffd_fd = syscall(__NR_userfaultfd, flags);
+ uffd_fd = uffd_open(flags);
if (uffd_fd < 0) {
trace_uffd_create_fd_nosys(errno);
return -1;