(root)/
strace-6.5/
tests-mx32/
tkill.c
       1  /*
       2   * Check decoding of tkill syscall.
       3   *
       4   * Copyright (c) 2020 Dmitry V. Levin <ldv@strace.io>
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include "scno.h"
      12  #include "pidns.h"
      13  
      14  #ifdef __NR_tkill
      15  
      16  # include <signal.h>
      17  # include <stdio.h>
      18  # include <unistd.h>
      19  
      20  static const char *errstr;
      21  
      22  static long
      23  k_tkill(const unsigned int tid, const unsigned int sig)
      24  {
      25          const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
      26          const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
      27          const kernel_ulong_t arg1 = fill | tid;
      28          const kernel_ulong_t arg2 = fill | sig;
      29          const long rc = syscall(__NR_tkill, arg1, arg2, bad, bad, bad, bad);
      30          errstr = sprintrc(rc);
      31          return rc;
      32  }
      33  
      34  int
      35  main(void)
      36  {
      37  	PIDNS_TEST_INIT;
      38  
      39  	const int tid = syscall(__NR_gettid);
      40  	const char *tid_str = pidns_pid2str(PT_TID);
      41  	const int bad_pid = -1;
      42  	const int bad_sig = 0xface;
      43  
      44  	k_tkill(tid, 0);
      45  	pidns_print_leader();
      46  	printf("tkill(%d%s, 0) = %s\n", tid, tid_str, errstr);
      47  
      48  	k_tkill(tid, SIGCONT);
      49  	pidns_print_leader();
      50  	printf("tkill(%d%s, SIGCONT) = %s\n", tid, tid_str, errstr);
      51  
      52  	k_tkill(bad_pid, bad_sig);
      53  	pidns_print_leader();
      54  	printf("tkill(%d, %d) = %s\n", bad_pid, bad_sig, errstr);
      55  
      56  	k_tkill(bad_pid, -bad_sig);
      57  	pidns_print_leader();
      58  	printf("tkill(%d, %d) = %s\n", bad_pid, -bad_sig, errstr);
      59  
      60  	pidns_print_leader();
      61  	puts("+++ exited with 0 +++");
      62  	return 0;
      63  }
      64  
      65  #else
      66  
      67  SKIP_MAIN_UNDEFINED("__NR_tkill")
      68  
      69  #endif