(root)/
strace-6.5/
tests-m32/
nsyscalls.c
       1  /*
       2   * Check decoding of out-of-range syscalls.
       3   *
       4   * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@strace.io>
       5   * Copyright (c) 2016-2021 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include "sysent.h"
      13  #include <errno.h>
      14  #include <stdio.h>
      15  #include <stdlib.h>
      16  #include <unistd.h>
      17  #include "scno.h"
      18  
      19  #include "sysent_shorthand_defs.h"
      20  
      21  static const struct_sysent syscallent[] = {
      22  #include "syscallent.h"
      23  };
      24  
      25  #include "sysent_shorthand_undefs.h"
      26  
      27  #ifndef DEBUG_PRINT
      28  # define DEBUG_PRINT 0
      29  #endif
      30  
      31  #if DEBUG_PRINT
      32  static const char *strace_name;
      33  static FILE *debug_out;
      34  #endif
      35  
      36  static void
      37  test_syscall(const unsigned long nr)
      38  {
      39  	static const kernel_ulong_t a[] = {
      40  		(kernel_ulong_t) 0xface0fedbadc0dedULL,
      41  		(kernel_ulong_t) 0xface1fedbadc1dedULL,
      42  		(kernel_ulong_t) 0xface2fedbadc2dedULL,
      43  		(kernel_ulong_t) 0xface3fedbadc3dedULL,
      44  		(kernel_ulong_t) 0xface4fedbadc4dedULL,
      45  		(kernel_ulong_t) 0xface5fedbadc5dedULL
      46  	};
      47  
      48  	long rc = syscall(nr | SYSCALL_BIT,
      49  			  a[0], a[1], a[2], a[3], a[4], a[5]);
      50  
      51  #if DEBUG_PRINT
      52  	fprintf(debug_out, "%s: pid %d invalid syscall %#lx\n",
      53  		strace_name, getpid(), nr | SYSCALL_BIT);
      54  #endif
      55  
      56  #ifdef LINUX_MIPSO32
      57  	printf("syscall(%#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx)"
      58  	       " = %s\n", nr | SYSCALL_BIT,
      59  	       a[0], a[1], a[2], a[3], a[4], a[5], sprintrc(rc));
      60  #else
      61  	printf("syscall_%#lx(%#llx, %#llx, %#llx, %#llx, %#llx, %#llx)"
      62  	       " = %s\n", nr | SYSCALL_BIT,
      63  	       (unsigned long long) a[0],
      64  	       (unsigned long long) a[1],
      65  	       (unsigned long long) a[2],
      66  	       (unsigned long long) a[3],
      67  	       (unsigned long long) a[4],
      68  	       (unsigned long long) a[5],
      69  	       sprintrc(rc));
      70  #endif
      71  }
      72  
      73  int
      74  main(int argc, char *argv[])
      75  {
      76  #if DEBUG_PRINT
      77  	if (argc < 3)
      78  		error_msg_and_fail("Not enough arguments. "
      79  				   "Usage: %s STRACE_NAME DEBUG_OUT_FD",
      80  				   argv[0]);
      81  
      82  	strace_name = argv[1];
      83  
      84  	errno = 0;
      85  	int debug_out_fd = strtol(argv[2], NULL, 0);
      86  	if (errno)
      87  		error_msg_and_fail("Not a number: %s", argv[2]);
      88  
      89  	debug_out = fdopen(debug_out_fd, "a");
      90  	if (!debug_out)
      91  		perror_msg_and_fail("fdopen: %d", debug_out_fd);
      92  #endif
      93  
      94  	test_syscall(ARRAY_SIZE(syscallent));
      95  	(void) syscallent;	/* workaround for clang bug #33068 */
      96  
      97  #ifdef SYS_socket_subcall
      98  	test_syscall(SYS_socket_subcall + 1);
      99  #endif
     100  
     101  #ifdef SYS_ipc_subcall
     102  	test_syscall(SYS_ipc_subcall + 1);
     103  #endif
     104  
     105  	puts("+++ exited with 0 +++");
     106  	return 0;
     107  }