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.

resource.c 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
  5. * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
  6. * Copyright (c) 1999-2019 The strace developers.
  7. * All rights reserved.
  8. *
  9. * SPDX-License-Identifier: LGPL-2.1-or-later
  10. */
  11. #include "defs.h"
  12. #include <sys/resource.h>
  13. #include "xstring.h"
  14. #include "xlat/resources.h"
  15. static void
  16. print_rlim64_t(uint64_t lim) {
  17. const char *str = NULL;
  18. if (lim == UINT64_MAX)
  19. str = "RLIM64_INFINITY";
  20. else if (lim > 1024 && lim % 1024 == 0) {
  21. static char buf[sizeof(lim) * 3 + sizeof("*1024")];
  22. xsprintf(buf, "%" PRIu64 "*1024", lim / 1024);
  23. str = buf;
  24. }
  25. if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
  26. tprintf("%" PRIu64, lim);
  27. if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
  28. return;
  29. (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
  30. ? tprints_comment : tprints)(str);
  31. }
  32. static void
  33. print_rlimit64(struct tcb *const tcp, const kernel_ulong_t addr)
  34. {
  35. struct rlimit_64 {
  36. uint64_t rlim_cur;
  37. uint64_t rlim_max;
  38. } rlim;
  39. if (!umove_or_printaddr(tcp, addr, &rlim)) {
  40. tprints("{rlim_cur=");
  41. print_rlim64_t(rlim.rlim_cur);
  42. tprints(", rlim_max=");
  43. print_rlim64_t(rlim.rlim_max);
  44. tprints("}");
  45. }
  46. }
  47. #if !defined(current_wordsize) || current_wordsize == 4
  48. static void
  49. print_rlim32_t(uint32_t lim) {
  50. const char *str = NULL;
  51. if (lim == UINT32_MAX)
  52. str = "RLIM_INFINITY";
  53. else if (lim > 1024 && lim % 1024 == 0) {
  54. static char buf[sizeof(lim) * 3 + sizeof("*1024")];
  55. xsprintf(buf, "%" PRIu32 "*1024", lim / 1024);
  56. str = buf;
  57. }
  58. if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
  59. tprintf("%" PRIu32, lim);
  60. if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
  61. return;
  62. (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
  63. ? tprints_comment : tprints)(str);
  64. }
  65. static void
  66. print_rlimit32(struct tcb *const tcp, const kernel_ulong_t addr)
  67. {
  68. struct rlimit_32 {
  69. uint32_t rlim_cur;
  70. uint32_t rlim_max;
  71. } rlim;
  72. if (!umove_or_printaddr(tcp, addr, &rlim)) {
  73. tprints("{rlim_cur=");
  74. print_rlim32_t(rlim.rlim_cur);
  75. tprints(", rlim_max=");
  76. print_rlim32_t(rlim.rlim_max);
  77. tprints("}");
  78. }
  79. }
  80. static void
  81. decode_rlimit(struct tcb *const tcp, const kernel_ulong_t addr)
  82. {
  83. /*
  84. * i386 is the only personality on X86_64 and X32
  85. * with 32-bit rlim_t.
  86. * When current_personality is X32, current_wordsize
  87. * equals to 4 but rlim_t is 64-bit.
  88. */
  89. if (current_klongsize == 4)
  90. print_rlimit32(tcp, addr);
  91. else
  92. print_rlimit64(tcp, addr);
  93. }
  94. #else /* defined(current_wordsize) && current_wordsize != 4 */
  95. # define decode_rlimit print_rlimit64
  96. #endif
  97. SYS_FUNC(getrlimit)
  98. {
  99. if (entering(tcp)) {
  100. printxval(resources, tcp->u_arg[0], "RLIMIT_???");
  101. tprints(", ");
  102. } else {
  103. decode_rlimit(tcp, tcp->u_arg[1]);
  104. }
  105. return 0;
  106. }
  107. SYS_FUNC(setrlimit)
  108. {
  109. printxval(resources, tcp->u_arg[0], "RLIMIT_???");
  110. tprints(", ");
  111. decode_rlimit(tcp, tcp->u_arg[1]);
  112. return RVAL_DECODED;
  113. }
  114. SYS_FUNC(prlimit64)
  115. {
  116. if (entering(tcp)) {
  117. tprintf("%d, ", (int) tcp->u_arg[0]);
  118. printxval(resources, tcp->u_arg[1], "RLIMIT_???");
  119. tprints(", ");
  120. print_rlimit64(tcp, tcp->u_arg[2]);
  121. tprints(", ");
  122. } else {
  123. print_rlimit64(tcp, tcp->u_arg[3]);
  124. }
  125. return 0;
  126. }
  127. #include "xlat/usagewho.h"
  128. SYS_FUNC(getrusage)
  129. {
  130. if (entering(tcp)) {
  131. printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
  132. tprints(", ");
  133. } else
  134. printrusage(tcp, tcp->u_arg[1]);
  135. return 0;
  136. }
  137. #ifdef ALPHA
  138. SYS_FUNC(osf_getrusage)
  139. {
  140. if (entering(tcp)) {
  141. printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
  142. tprints(", ");
  143. } else
  144. printrusage32(tcp, tcp->u_arg[1]);
  145. return 0;
  146. }
  147. #endif /* ALPHA */
  148. #include "xlat/priorities.h"
  149. SYS_FUNC(getpriority)
  150. {
  151. printxval(priorities, tcp->u_arg[0], "PRIO_???");
  152. tprintf(", %d", (int) tcp->u_arg[1]);
  153. return RVAL_DECODED;
  154. }
  155. SYS_FUNC(setpriority)
  156. {
  157. printxval(priorities, tcp->u_arg[0], "PRIO_???");
  158. tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
  159. return RVAL_DECODED;
  160. }