1 /* 2 * Check decoding of s390_runtime_instr syscall. 3 * 4 * Copyright (c) 2018 The strace developers. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include "tests.h" 31 #include <asm/unistd.h> 32 33 #if defined __NR_s390_runtime_instr 34 35 # include <errno.h> 36 # include <signal.h> 37 # include <stdio.h> 38 # include <unistd.h> 39 40 int 41 main(void) 42 { 43 static struct { 44 kernel_ulong_t cmd; 45 const char * cmd_str; 46 } cmd_args[] = { 47 { 0, "???" }, 48 { 4, "???" }, 49 { (kernel_ulong_t) 0xdeafbeefdeadc0deULL, "???" }, 50 { 2, "STOP", }, 51 }; 52 53 static struct { 54 kernel_ulong_t sig; 55 const char * sig_str; 56 } start_sig_args[] = { 57 { 0, "SIG_0" }, 58 { (kernel_ulong_t) 0xfacefeedac0ffeedULL, NULL }, 59 { ARG_STR(SIGALRM) }, 60 { 33, "SIGRT_1" }, 61 { 63, "SIGRT_31" }, 62 }; 63 64 unsigned int i; 65 long rc; 66 67 for (i = 0; i < ARRAY_SIZE(cmd_args); i++) { 68 rc = syscall(__NR_s390_runtime_instr, cmd_args[i].cmd, 0xdead); 69 printf("s390_runtime_instr(%d /* S390_RUNTIME_INSTR_%s */) = " 70 "%s\n", 71 (int) cmd_args[i].cmd, cmd_args[i].cmd_str, 72 sprintrc(rc)); 73 } 74 75 for (i = 0; i < ARRAY_SIZE(start_sig_args); i++) { 76 long saved_errno; 77 78 rc = syscall(__NR_s390_runtime_instr, 1, start_sig_args[i].sig); 79 saved_errno = errno; 80 printf("s390_runtime_instr(1 /* S390_RUNTIME_INSTR_START */, "); 81 82 if (start_sig_args[i].sig_str) 83 printf("%s", start_sig_args[i].sig_str); 84 else 85 printf("%d", (int) start_sig_args[i].sig); 86 87 errno = saved_errno; 88 printf(") = %s\n", sprintrc(rc)); 89 } 90 91 puts("+++ exited with 0 +++"); 92 return 0; 93 } 94 95 #else 96 97 SKIP_MAIN_UNDEFINED("__NR_s390_runtime_instr") 98 99 #endif 100