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.

kcmp.c 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
  3. * Copyright (c) 2015-2018 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #include "defs.h"
  9. #include "print_fields.h"
  10. #include "xlat/kcmp_types.h"
  11. struct strace_kcmp_epoll_slot {
  12. uint32_t efd;
  13. uint32_t tfd;
  14. uint32_t toff;
  15. };
  16. static void
  17. printpidfd(struct tcb *tcp, pid_t pid, int fd)
  18. {
  19. /*
  20. * XXX We want to use printfd here, but we should figure out which
  21. * process in strace's PID NS is referred to first.
  22. */
  23. tprintf("%d", fd);
  24. }
  25. #define PRINT_FIELD_PIDFD(prefix_, where_, field_, tcp_, pid_) \
  26. do { \
  27. STRACE_PRINTF("%s%s=", (prefix_), #field_); \
  28. printpidfd((tcp_), (pid_), (where_).field_); \
  29. } while (0)
  30. SYS_FUNC(kcmp)
  31. {
  32. pid_t pid1 = tcp->u_arg[0];
  33. pid_t pid2 = tcp->u_arg[1];
  34. int type = tcp->u_arg[2];
  35. kernel_ulong_t idx1 = tcp->u_arg[3];
  36. kernel_ulong_t idx2 = tcp->u_arg[4];
  37. tprintf("%d, %d, ", pid1, pid2);
  38. printxval(kcmp_types, type, "KCMP_???");
  39. switch (type) {
  40. case KCMP_FILE:
  41. tprints(", ");
  42. printpidfd(tcp, pid1, idx1);
  43. tprints(", ");
  44. printpidfd(tcp, pid1, idx2);
  45. break;
  46. case KCMP_EPOLL_TFD: {
  47. struct strace_kcmp_epoll_slot slot;
  48. tprints(", ");
  49. printpidfd(tcp, pid1, idx1);
  50. tprints(", ");
  51. if (umove_or_printaddr(tcp, idx2, &slot))
  52. break;
  53. PRINT_FIELD_PIDFD("{", slot, efd, tcp, pid2);
  54. PRINT_FIELD_PIDFD(", ", slot, tfd, tcp, pid2);
  55. PRINT_FIELD_U(", ", slot, toff);
  56. tprints("}");
  57. break;
  58. }
  59. case KCMP_FILES:
  60. case KCMP_FS:
  61. case KCMP_IO:
  62. case KCMP_SIGHAND:
  63. case KCMP_SYSVSEM:
  64. case KCMP_VM:
  65. break;
  66. default:
  67. tprintf(", %#" PRI_klx ", %#" PRI_klx, idx1, idx2);
  68. }
  69. return RVAL_DECODED;
  70. }