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 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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-2017 The strace developers.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "defs.h"
  30. static bool
  31. print_node(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  32. {
  33. if (elem_size < sizeof(kernel_ulong_t)) {
  34. tprintf("%#0*x", (int) elem_size * 2 + 2,
  35. *(unsigned int *) elem_buf);
  36. } else {
  37. tprintf("%#0*" PRI_klx, (int) elem_size * 2 + 2,
  38. *(kernel_ulong_t *) elem_buf);
  39. }
  40. return true;
  41. }
  42. static void
  43. print_nodemask(struct tcb *const tcp, const kernel_ulong_t addr,
  44. const kernel_ulong_t maxnodes)
  45. {
  46. const unsigned int bits_per_long = 8 * current_wordsize;
  47. const kernel_ulong_t nmemb =
  48. (maxnodes + bits_per_long - 2) / bits_per_long;
  49. if (nmemb < maxnodes / bits_per_long ||
  50. (maxnodes && !nmemb)) {
  51. printaddr(addr);
  52. return;
  53. }
  54. kernel_ulong_t buf;
  55. print_array(tcp, addr, nmemb, &buf, current_wordsize,
  56. umoven_or_printaddr, print_node, 0);
  57. }
  58. SYS_FUNC(migrate_pages)
  59. {
  60. tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], tcp->u_arg[1]);
  61. print_nodemask(tcp, tcp->u_arg[2], tcp->u_arg[1]);
  62. tprints(", ");
  63. print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[1]);
  64. return RVAL_DECODED;
  65. }
  66. #include "xlat/policies.h"
  67. #include "xlat/mbindflags.h"
  68. SYS_FUNC(mbind)
  69. {
  70. printaddr(tcp->u_arg[0]);
  71. tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
  72. printxval64(policies, tcp->u_arg[2], "MPOL_???");
  73. tprints(", ");
  74. print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[4]);
  75. tprintf(", %" PRI_klu ", ", tcp->u_arg[4]);
  76. printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
  77. return RVAL_DECODED;
  78. }
  79. SYS_FUNC(set_mempolicy)
  80. {
  81. printxval(policies, tcp->u_arg[0], "MPOL_???");
  82. tprints(", ");
  83. print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  84. tprintf(", %" PRI_klu, tcp->u_arg[2]);
  85. return RVAL_DECODED;
  86. }
  87. #include "xlat/mempolicyflags.h"
  88. SYS_FUNC(get_mempolicy)
  89. {
  90. if (exiting(tcp)) {
  91. int pol;
  92. if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol)) {
  93. tprints("[");
  94. printxval(policies, pol, "MPOL_???");
  95. tprints("]");
  96. }
  97. tprints(", ");
  98. print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  99. tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
  100. printaddr(tcp->u_arg[3]);
  101. tprints(", ");
  102. printflags64(mempolicyflags, tcp->u_arg[4], "MPOL_???");
  103. }
  104. return 0;
  105. }
  106. #include "xlat/move_pages_flags.h"
  107. static bool
  108. print_addr(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  109. {
  110. kernel_ulong_t addr;
  111. if (elem_size < sizeof(addr)) {
  112. addr = *(unsigned int *) elem_buf;
  113. } else {
  114. addr = *(kernel_ulong_t *) elem_buf;
  115. }
  116. printaddr(addr);
  117. return true;
  118. }
  119. static bool
  120. print_status(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  121. {
  122. const int status = *(int *) elem_buf;
  123. if (status < 0 && (unsigned) -status < nerrnos)
  124. tprintf("-%s", errnoent[-status]);
  125. else
  126. tprintf("%d", status);
  127. return true;
  128. }
  129. static bool
  130. print_int(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  131. {
  132. tprintf("%d", *(int *) elem_buf);
  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. umoven_or_printaddr, print_addr, 0);
  143. tprints(", ");
  144. print_array(tcp, tcp->u_arg[3], npages, &buf, sizeof(int),
  145. umoven_or_printaddr, print_int, 0);
  146. tprints(", ");
  147. } else {
  148. print_array(tcp, tcp->u_arg[4], npages, &buf, sizeof(int),
  149. umoven_or_printaddr, print_status, 0);
  150. tprints(", ");
  151. printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
  152. }
  153. return 0;
  154. }