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.

numa.c 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2003-2007 Ulrich Drepper <drepper@redhat.com>
  3. * Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org>
  4. * Copyright (c) 2016-2019 The strace developers.
  5. * All rights reserved.
  6. *
  7. * SPDX-License-Identifier: LGPL-2.1-or-later
  8. */
  9. #include "defs.h"
  10. static bool
  11. print_node(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  12. {
  13. if (elem_size < sizeof(kernel_ulong_t)) {
  14. tprintf("%#0*x", (int) elem_size * 2 + 2,
  15. *(unsigned int *) elem_buf);
  16. } else {
  17. tprintf("%#0*" PRI_klx, (int) elem_size * 2 + 2,
  18. *(kernel_ulong_t *) elem_buf);
  19. }
  20. return true;
  21. }
  22. static void
  23. print_nodemask(struct tcb *const tcp, const kernel_ulong_t addr,
  24. const kernel_ulong_t maxnodes)
  25. {
  26. const unsigned int bits_per_long = 8 * current_wordsize;
  27. const kernel_ulong_t nmemb =
  28. (maxnodes + bits_per_long - 2) / bits_per_long;
  29. if (nmemb < maxnodes / bits_per_long ||
  30. (maxnodes && !nmemb)) {
  31. printaddr(addr);
  32. return;
  33. }
  34. kernel_ulong_t buf;
  35. print_array(tcp, addr, nmemb, &buf, current_wordsize,
  36. tfetch_mem, print_node, 0);
  37. }
  38. SYS_FUNC(migrate_pages)
  39. {
  40. tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], tcp->u_arg[1]);
  41. print_nodemask(tcp, tcp->u_arg[2], tcp->u_arg[1]);
  42. tprints(", ");
  43. print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[1]);
  44. return RVAL_DECODED;
  45. }
  46. #include "xlat/mpol_modes.h"
  47. #include "xlat/mpol_mode_flags.h"
  48. #include "xlat/mbind_flags.h"
  49. static void
  50. print_mode(struct tcb *const tcp, const kernel_ulong_t mode_arg)
  51. {
  52. const kernel_ulong_t flags_mask =
  53. MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES;
  54. const kernel_ulong_t mode = mode_arg & ~flags_mask;
  55. const unsigned int flags = mode_arg & flags_mask;
  56. if (!flags) {
  57. printxval64(mpol_modes, mode, "MPOL_???");
  58. return;
  59. }
  60. const char *mode_str = xlookup(mpol_modes, mode);
  61. if (!mode_str) {
  62. printflags64(mpol_mode_flags, mode_arg, "MPOL_???");
  63. return;
  64. }
  65. if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
  66. tprintf("%#" PRI_klx, mode_arg);
  67. if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
  68. return;
  69. if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
  70. tprints(" /* ");
  71. tprints(mode_str);
  72. tprints("|");
  73. printflags_ex(flags, NULL, XLAT_STYLE_ABBREV, mpol_mode_flags, NULL);
  74. if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
  75. tprints(" */");
  76. }
  77. SYS_FUNC(mbind)
  78. {
  79. printaddr(tcp->u_arg[0]);
  80. tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
  81. print_mode(tcp, tcp->u_arg[2]);
  82. tprints(", ");
  83. print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[4]);
  84. tprintf(", %" PRI_klu ", ", tcp->u_arg[4]);
  85. printflags(mbind_flags, tcp->u_arg[5], "MPOL_???");
  86. return RVAL_DECODED;
  87. }
  88. SYS_FUNC(set_mempolicy)
  89. {
  90. print_mode(tcp, (unsigned int) tcp->u_arg[0]);
  91. tprints(", ");
  92. print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  93. tprintf(", %" PRI_klu, tcp->u_arg[2]);
  94. return RVAL_DECODED;
  95. }
  96. #include "xlat/get_mempolicy_flags.h"
  97. SYS_FUNC(get_mempolicy)
  98. {
  99. if (exiting(tcp)) {
  100. int pol;
  101. if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol)) {
  102. tprints("[");
  103. printxval(mpol_modes, pol, "MPOL_???");
  104. tprints("]");
  105. }
  106. tprints(", ");
  107. print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  108. tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
  109. printaddr(tcp->u_arg[3]);
  110. tprints(", ");
  111. printflags64(get_mempolicy_flags, tcp->u_arg[4], "MPOL_???");
  112. }
  113. return 0;
  114. }
  115. #include "xlat/move_pages_flags.h"
  116. static bool
  117. print_addr(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  118. {
  119. kernel_ulong_t addr;
  120. if (elem_size < sizeof(addr)) {
  121. addr = *(unsigned int *) elem_buf;
  122. } else {
  123. addr = *(kernel_ulong_t *) elem_buf;
  124. }
  125. printaddr(addr);
  126. return true;
  127. }
  128. static bool
  129. print_status(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  130. {
  131. const int status = *(int *) elem_buf;
  132. print_err(status, true);
  133. return true;
  134. }
  135. SYS_FUNC(move_pages)
  136. {
  137. const kernel_ulong_t npages = tcp->u_arg[1];
  138. kernel_ulong_t buf;
  139. if (entering(tcp)) {
  140. tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], npages);
  141. print_array(tcp, tcp->u_arg[2], npages, &buf, current_wordsize,
  142. tfetch_mem, print_addr, 0);
  143. tprints(", ");
  144. print_array(tcp, tcp->u_arg[3], npages, &buf, sizeof(int),
  145. tfetch_mem, print_int32_array_member, 0);
  146. tprints(", ");
  147. } else {
  148. print_array(tcp, tcp->u_arg[4], npages, &buf, sizeof(int),
  149. tfetch_mem, print_status, 0);
  150. tprints(", ");
  151. printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
  152. }
  153. return 0;
  154. }