File: io_uring_enter.c

package info (click to toggle)
strace 6.13%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 71,488 kB
  • sloc: ansic: 176,497; sh: 9,675; makefile: 4,133; cpp: 885; awk: 353; perl: 267; exp: 62; sed: 9
file content (79 lines) | stat: -rw-r--r-- 2,054 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Check decoding of io_uring_enter syscall.
 *
 * Copyright (c) 2019-2021 Dmitry V. Levin <ldv@strace.io>
 * Copyright (c) 2019-2024 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "tests.h"
#include "scno.h"

#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

static const char *errstr;

static long
sys_io_uring_enter(unsigned int fd, unsigned int to_submit,
		   unsigned int min_complete, unsigned int flags,
		   const void *sigset_addr, kernel_ulong_t sigset_size)

{
	kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
	kernel_ulong_t arg1 = fill | fd;
	kernel_ulong_t arg2 = fill | to_submit;
	kernel_ulong_t arg3 = fill | min_complete;
	kernel_ulong_t arg4 = fill | flags;
	kernel_ulong_t arg5 = (unsigned long) sigset_addr;
	kernel_ulong_t arg6 = sigset_size;

	long rc = syscall(__NR_io_uring_enter,
			  arg1, arg2, arg3, arg4, arg5, arg6);
	errstr = sprintrc(rc);
	return rc;
}

int
main(void)
{
	static const char path[] = "/dev/null";

	skip_if_unavailable("/proc/self/fd/");

	int fd = open(path, O_RDONLY);
	if (fd < 0)
		perror_msg_and_fail("open: %s", path);

	const unsigned int size = get_sigset_size();
	void *const sigmask = tail_alloc(size);
	sigset_t mask;

	memset(&mask, -1, sizeof(mask));
	sigdelset(&mask, SIGHUP);
	sigdelset(&mask, SIGKILL);
	sigdelset(&mask, SIGSTOP);
	memcpy(sigmask, &mask, size);

	const unsigned int to_submit = 0xdeadbeef;
	const unsigned int min_complete = 0xcafef00d;

	sys_io_uring_enter(fd, to_submit, min_complete, -1U, sigmask, size);
	printf("io_uring_enter(%u<%s>, %u, %u"
	       ", IORING_ENTER_GETEVENTS|IORING_ENTER_SQ_WAKEUP"
	       "|IORING_ENTER_SQ_WAIT|IORING_ENTER_EXT_ARG"
	       "|IORING_ENTER_REGISTERED_RING"
	       "|IORING_ENTER_ABS_TIMER"
	       "|IORING_ENTER_EXT_ARG_REG"
	       "|%#x, %s, %u) = %s\n",
	       fd, path, to_submit, min_complete, -1U - 127U,
	       "~[HUP KILL STOP]", size, errstr);

	puts("+++ exited with 0 +++");
	return 0;
}