(root)/
strace-6.5/
tests/
s390_runtime_instr.c
       1  /*
       2   * Check decoding of s390_runtime_instr syscall.
       3   *
       4   * Copyright (c) 2018-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 "scno.h"
      12  
      13  #if defined __NR_s390_runtime_instr
      14  
      15  # include <errno.h>
      16  # include <signal.h>
      17  # include <stdio.h>
      18  # include <unistd.h>
      19  
      20  int
      21  main(void)
      22  {
      23  	static struct {
      24  		kernel_ulong_t cmd;
      25  		const char * cmd_str;
      26  	} cmd_args[] = {
      27  		{ 0, "0 /* S390_RUNTIME_INSTR_??? */" },
      28  		{ 4, "4 /* S390_RUNTIME_INSTR_??? */" },
      29  		{ (kernel_ulong_t) 0xdeafbeefdeadc0deULL,
      30  			"-559038242 /* S390_RUNTIME_INSTR_??? */" },
      31  		{ 2, "S390_RUNTIME_INSTR_STOP"  },
      32  	};
      33  
      34  	static struct {
      35  		kernel_ulong_t sig;
      36  		const char * sig_str;
      37  	} start_sig_args[] = {
      38  		{ 0, "0" },
      39  		{ (kernel_ulong_t) 0xfacefeedac0ffeedULL, NULL },
      40  		{ ARG_STR(SIGALRM) },
      41  		{ 33, "SIGRT_1" },
      42  		{ 63, "SIGRT_31" },
      43  	};
      44  
      45  	long rc;
      46  
      47  	for (unsigned int i = 0; i < ARRAY_SIZE(cmd_args); ++i) {
      48  		rc = syscall(__NR_s390_runtime_instr, cmd_args[i].cmd, 0xdead);
      49  		printf("s390_runtime_instr(%s) = %s\n",
      50  		       cmd_args[i].cmd_str, sprintrc(rc));
      51  	}
      52  
      53  	for (unsigned int i = 0; i < ARRAY_SIZE(start_sig_args); ++i) {
      54  		long saved_errno;
      55  
      56  		rc = syscall(__NR_s390_runtime_instr, 1, start_sig_args[i].sig);
      57  		saved_errno = errno;
      58  		printf("s390_runtime_instr(S390_RUNTIME_INSTR_START, ");
      59  
      60  		if (start_sig_args[i].sig_str)
      61  			printf("%s", start_sig_args[i].sig_str);
      62  		else
      63  			printf("%d", (int) start_sig_args[i].sig);
      64  
      65  		errno = saved_errno;
      66  		printf(") = %s\n", sprintrc(rc));
      67  	}
      68  
      69  	puts("+++ exited with 0 +++");
      70  	return 0;
      71  }
      72  
      73  #else
      74  
      75  SKIP_MAIN_UNDEFINED("__NR_s390_runtime_instr")
      76  
      77  #endif