Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nsyscalls.c 2.4KB

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