Home | History | Annotate | Download | only in tests
      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, "0 /* S390_RUNTIME_INSTR_??? */" },
     48 		{ 4, "4 /* S390_RUNTIME_INSTR_??? */" },
     49 		{ (kernel_ulong_t) 0xdeafbeefdeadc0deULL,
     50 			"-559038242 /* S390_RUNTIME_INSTR_??? */" },
     51 		{ 2, "S390_RUNTIME_INSTR_STOP"  },
     52 	};
     53 
     54 	static struct {
     55 		kernel_ulong_t sig;
     56 		const char * sig_str;
     57 	} start_sig_args[] = {
     58 		{ 0, "SIG_0" },
     59 		{ (kernel_ulong_t) 0xfacefeedac0ffeedULL, NULL },
     60 		{ ARG_STR(SIGALRM) },
     61 		{ 33, "SIGRT_1" },
     62 		{ 63, "SIGRT_31" },
     63 	};
     64 
     65 	unsigned int i;
     66 	long rc;
     67 
     68 	for (i = 0; i < ARRAY_SIZE(cmd_args); i++) {
     69 		rc = syscall(__NR_s390_runtime_instr, cmd_args[i].cmd, 0xdead);
     70 		printf("s390_runtime_instr(%s) = %s\n",
     71 		       cmd_args[i].cmd_str, sprintrc(rc));
     72 	}
     73 
     74 	for (i = 0; i < ARRAY_SIZE(start_sig_args); i++) {
     75 		long saved_errno;
     76 
     77 		rc = syscall(__NR_s390_runtime_instr, 1, start_sig_args[i].sig);
     78 		saved_errno = errno;
     79 		printf("s390_runtime_instr(S390_RUNTIME_INSTR_START, ");
     80 
     81 		if (start_sig_args[i].sig_str)
     82 			printf("%s", start_sig_args[i].sig_str);
     83 		else
     84 			printf("%d", (int) start_sig_args[i].sig);
     85 
     86 		errno = saved_errno;
     87 		printf(") = %s\n", sprintrc(rc));
     88 	}
     89 
     90 	puts("+++ exited with 0 +++");
     91 	return 0;
     92 }
     93 
     94 #else
     95 
     96 SKIP_MAIN_UNDEFINED("__NR_s390_runtime_instr")
     97 
     98 #endif
     99