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.

execve.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
  3. * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
  4. * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
  5. * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
  6. * Copyright (c) 2007 Roland McGrath <roland@redhat.com>
  7. * Copyright (c) 2011-2012 Denys Vlasenko <vda.linux@googlemail.com>
  8. * Copyright (c) 2010-2015 Dmitry V. Levin <ldv@altlinux.org>
  9. * Copyright (c) 2014-2018 The strace developers.
  10. * All rights reserved.
  11. *
  12. * SPDX-License-Identifier: LGPL-2.1-or-later
  13. */
  14. #include "defs.h"
  15. static void
  16. printargv(struct tcb *const tcp, kernel_ulong_t addr)
  17. {
  18. if (!addr || !verbose(tcp)) {
  19. printaddr(addr);
  20. return;
  21. }
  22. const char *const start_sep = "[";
  23. const char *sep = start_sep;
  24. const unsigned int wordsize = current_wordsize;
  25. unsigned int n;
  26. for (n = 0; addr; sep = ", ", addr += wordsize, ++n) {
  27. union {
  28. unsigned int p32;
  29. kernel_ulong_t p64;
  30. char data[sizeof(kernel_ulong_t)];
  31. } cp;
  32. if (umoven(tcp, addr, wordsize, cp.data)) {
  33. if (sep == start_sep)
  34. printaddr(addr);
  35. else {
  36. tprints(", ...");
  37. printaddr_comment(addr);
  38. tprints("]");
  39. }
  40. return;
  41. }
  42. if (!(wordsize < sizeof(cp.p64) ? cp.p32 : cp.p64)) {
  43. if (sep == start_sep)
  44. tprints(start_sep);
  45. break;
  46. }
  47. if (abbrev(tcp) && n >= max_strlen) {
  48. tprintf("%s...", sep);
  49. break;
  50. }
  51. tprints(sep);
  52. printstr(tcp, wordsize < sizeof(cp.p64) ? cp.p32 : cp.p64);
  53. }
  54. tprints("]");
  55. }
  56. static void
  57. printargc(struct tcb *const tcp, kernel_ulong_t addr)
  58. {
  59. printaddr(addr);
  60. if (!addr || !verbose(tcp))
  61. return;
  62. bool unterminated = false;
  63. unsigned int count = 0;
  64. char *cp = NULL;
  65. for (; addr; addr += current_wordsize, ++count) {
  66. if (umoven(tcp, addr, current_wordsize, &cp)) {
  67. if (!count)
  68. return;
  69. unterminated = true;
  70. break;
  71. }
  72. if (!cp)
  73. break;
  74. }
  75. tprintf_comment("%u var%s%s",
  76. count, count == 1 ? "" : "s",
  77. unterminated ? ", unterminated" : "");
  78. }
  79. static void
  80. decode_execve(struct tcb *tcp, const unsigned int index)
  81. {
  82. printpath(tcp, tcp->u_arg[index + 0]);
  83. tprints(", ");
  84. printargv(tcp, tcp->u_arg[index + 1]);
  85. tprints(", ");
  86. (abbrev(tcp) ? printargc : printargv) (tcp, tcp->u_arg[index + 2]);
  87. }
  88. SYS_FUNC(execve)
  89. {
  90. decode_execve(tcp, 0);
  91. return RVAL_DECODED;
  92. }
  93. SYS_FUNC(execveat)
  94. {
  95. print_dirfd(tcp, tcp->u_arg[0]);
  96. decode_execve(tcp, 1);
  97. tprints(", ");
  98. printflags(at_flags, tcp->u_arg[4], "AT_???");
  99. return RVAL_DECODED;
  100. }
  101. #if defined(SPARC) || defined(SPARC64)
  102. SYS_FUNC(execv)
  103. {
  104. printpath(tcp, tcp->u_arg[0]);
  105. tprints(", ");
  106. printargv(tcp, tcp->u_arg[1]);
  107. return RVAL_DECODED;
  108. }
  109. #endif /* SPARC || SPARC64 */