(root)/
strace-6.5/
tests/
pidfd_send_signal.c
       1  /*
       2   * Check decoding of pidfd_send_signal syscall.
       3   *
       4   * Copyright (c) 2015-2021 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include <unistd.h>
      12  #include "scno.h"
      13  #include "pidns.h"
      14  
      15  #include <fcntl.h>
      16  #include <stdio.h>
      17  #include <signal.h>
      18  
      19  static const char *errstr;
      20  
      21  static long
      22  sys_pidfd_send_signal(int pidfd, int sig, const void *info, int flags)
      23  {
      24  	kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
      25  	kernel_ulong_t arg1 = fill | (unsigned int) pidfd;
      26  	kernel_ulong_t arg2 = fill | (unsigned int) sig;
      27  	kernel_ulong_t arg3 = (unsigned long) info;
      28  	kernel_ulong_t arg4 = fill | (unsigned int) flags;
      29  
      30  	long rc = syscall(__NR_pidfd_send_signal, arg1, arg2, arg3, arg4);
      31  	errstr = sprintrc(rc);
      32  	return rc;
      33  }
      34  
      35  int
      36  main(void)
      37  {
      38  	PIDNS_TEST_INIT;
      39  
      40  	static const char null_path[] = "/dev/null";
      41  
      42  	int fd = open(null_path, O_RDONLY);
      43  	if (fd < 0)
      44  		perror_msg_and_fail("open: %s", null_path);
      45  
      46  	TAIL_ALLOC_OBJECT_CONST_PTR(siginfo_t, si);
      47  	const void *esi = (const void *) si + 1;
      48  
      49  	sys_pidfd_send_signal(fd, SIGUSR1, esi, 0);
      50  	pidns_print_leader();
      51  	printf("pidfd_send_signal(%d, SIGUSR1, %p, 0) = %s\n",
      52  	       fd, esi, errstr);
      53  
      54  	si->si_signo = SIGUSR1;
      55  	si->si_code = SI_QUEUE;
      56  	si->si_pid = getpid();
      57  
      58  	sys_pidfd_send_signal(fd, SIGUSR2, si, -1);
      59  	pidns_print_leader();
      60  	printf("pidfd_send_signal(%d, SIGUSR2, {si_signo=SIGUSR1"
      61  	       ", si_code=SI_QUEUE, si_errno=%u, si_pid=%d%s, si_uid=%d"
      62  	       ", si_int=%d, si_ptr=%p}, %#x) = %s\n",
      63  	       fd, si->si_errno, si->si_pid, pidns_pid2str(PT_TGID), si->si_uid,
      64  	       si->si_int, si->si_ptr, -1U, errstr);
      65  
      66  	pidns_print_leader();
      67  	puts("+++ exited with 0 +++");
      68  	return 0;
      69  }