# Copyright 2018 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

include <uapi/linux/ioctl.h>
include <uapi/linux/fcntl.h>
include <uapi/linux/userfaultfd.h>

resource fd_uffd[fd]

userfaultfd(flags flags[userfaultfd_flags]) fd_uffd

ioctl$UFFDIO_API(fd fd_uffd, cmd const[UFFDIO_API], arg ptr[in, uffdio_api])
ioctl$UFFDIO_REGISTER(fd fd_uffd, cmd const[UFFDIO_REGISTER], arg ptr[in, uffdio_register])
ioctl$UFFDIO_UNREGISTER(fd fd_uffd, cmd const[UFFDIO_UNREGISTER], arg ptr[in, uffdio_range])
ioctl$UFFDIO_WAKE(fd fd_uffd, cmd const[UFFDIO_WAKE], arg ptr[in, uffdio_range])
ioctl$UFFDIO_COPY(fd fd_uffd, cmd const[UFFDIO_COPY], arg ptr[in, uffdio_copy])
ioctl$UFFDIO_ZEROPAGE(fd fd_uffd, cmd const[UFFDIO_ZEROPAGE], arg ptr[in, uffdio_zeropage])

userfaultfd_flags = O_NONBLOCK, O_CLOEXEC
uffdio_register_mode = UFFDIO_REGISTER_MODE_MISSING, UFFDIO_REGISTER_MODE_WP
uffdio_copy_mode = UFFDIO_COPY_MODE_DONTWAKE
uffdio_zero_mode = UFFDIO_ZEROPAGE_MODE_DONTWAKE
uffdio_features = UFFD_FEATURE_PAGEFAULT_FLAG_WP, UFFD_FEATURE_EVENT_FORK, UFFD_FEATURE_EVENT_REMAP, UFFD_FEATURE_EVENT_REMOVE, UFFD_FEATURE_MISSING_HUGETLBFS, UFFD_FEATURE_MISSING_SHMEM, UFFD_FEATURE_EVENT_UNMAP

uffdio_api {
	api	const[UFFD_API, int64]
	featur	flags[uffdio_features, int64]
	ioctls	const[0, int64]
}

uffdio_range {
	start	vma
	len	len[start, int64]
}

uffdio_register {
	range	uffdio_range
	mode	flags[uffdio_register_mode, int64]
	ioctls	const[0, int64]
}

uffdio_copy {
	dst	vma
	src	vma
	len	len[dst, int64]
	mode	flags[uffdio_copy_mode, int64]
	copy	const[0, int64]
}

uffdio_zeropage {
	range	uffdio_range
	mode	flags[uffdio_zero_mode, int64]
	zeropg	const[0, int64]
}