(root)/
strace-6.5/
tests-m32/
io_uring_enter.c
       1  /*
       2   * Check decoding of io_uring_enter syscall.
       3   *
       4   * Copyright (c) 2019-2021 Dmitry V. Levin <ldv@strace.io>
       5   * Copyright (c) 2019-2022 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include "scno.h"
      13  
      14  #include <fcntl.h>
      15  #include <signal.h>
      16  #include <stdio.h>
      17  #include <string.h>
      18  #include <unistd.h>
      19  
      20  static const char *errstr;
      21  
      22  static long
      23  sys_io_uring_enter(unsigned int fd, unsigned int to_submit,
      24  		   unsigned int min_complete, unsigned int flags,
      25  		   const void *sigset_addr, kernel_ulong_t sigset_size)
      26  
      27  {
      28  	kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
      29  	kernel_ulong_t arg1 = fill | fd;
      30  	kernel_ulong_t arg2 = fill | to_submit;
      31  	kernel_ulong_t arg3 = fill | min_complete;
      32  	kernel_ulong_t arg4 = fill | flags;
      33  	kernel_ulong_t arg5 = (unsigned long) sigset_addr;
      34  	kernel_ulong_t arg6 = sigset_size;
      35  
      36  	long rc = syscall(__NR_io_uring_enter,
      37  			  arg1, arg2, arg3, arg4, arg5, arg6);
      38  	errstr = sprintrc(rc);
      39  	return rc;
      40  }
      41  
      42  int
      43  main(void)
      44  {
      45  	static const char path[] = "/dev/null";
      46  
      47  	skip_if_unavailable("/proc/self/fd/");
      48  
      49  	int fd = open(path, O_RDONLY);
      50  	if (fd < 0)
      51  		perror_msg_and_fail("open: %s", path);
      52  
      53  	const unsigned int size = get_sigset_size();
      54  	void *const sigmask = tail_alloc(size);
      55  	sigset_t mask;
      56  
      57  	memset(&mask, -1, sizeof(mask));
      58  	sigdelset(&mask, SIGHUP);
      59  	sigdelset(&mask, SIGKILL);
      60  	sigdelset(&mask, SIGSTOP);
      61  	memcpy(sigmask, &mask, size);
      62  
      63  	const unsigned int to_submit = 0xdeadbeef;
      64  	const unsigned int min_complete = 0xcafef00d;
      65  
      66  	sys_io_uring_enter(fd, to_submit, min_complete, -1U, sigmask, size);
      67  	printf("io_uring_enter(%u<%s>, %u, %u"
      68  	       ", IORING_ENTER_GETEVENTS|IORING_ENTER_SQ_WAKEUP"
      69  	       "|IORING_ENTER_SQ_WAIT|IORING_ENTER_EXT_ARG"
      70  	       "|IORING_ENTER_REGISTERED_RING|%#x, %s, %u) = %s\n",
      71  	       fd, path, to_submit, min_complete, -1U - 31U,
      72  	       "~[HUP KILL STOP]", size, errstr);
      73  
      74  	puts("+++ exited with 0 +++");
      75  	return 0;
      76  }