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.

fetch_struct_flock.c 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 DEF_MPERS_TYPE(struct_flock)
  10. #include DEF_MPERS_TYPE(struct_flock64)
  11. #include "flock.h"
  12. typedef struct_kernel_flock struct_flock;
  13. typedef struct_kernel_flock64 struct_flock64;
  14. #include MPERS_DEFS
  15. #define SIZEOF_MEMBER(type, member) \
  16. sizeof(((type *) NULL)->member)
  17. #define FLOCK_MEMBERS_EQ(type, member) \
  18. (SIZEOF_MEMBER(struct_kernel_flock64, member) == SIZEOF_MEMBER(type, member) \
  19. && offsetof(struct_kernel_flock64, member) == offsetof(type, member))
  20. #define FLOCK_STRUCTS_EQ(type) \
  21. (sizeof(struct_kernel_flock64) == sizeof(type) \
  22. && FLOCK_MEMBERS_EQ(type, l_type) \
  23. && FLOCK_MEMBERS_EQ(type, l_whence) \
  24. && FLOCK_MEMBERS_EQ(type, l_start) \
  25. && FLOCK_MEMBERS_EQ(type, l_len) \
  26. && FLOCK_MEMBERS_EQ(type, l_pid))
  27. MPERS_PRINTER_DECL(bool, fetch_struct_flock, struct tcb *const tcp,
  28. const kernel_ulong_t addr, void *const p)
  29. {
  30. struct_kernel_flock64 *pfl = p;
  31. struct_flock mfl;
  32. if (FLOCK_STRUCTS_EQ(struct_flock))
  33. return !umove_or_printaddr(tcp, addr, pfl);
  34. if (umove_or_printaddr(tcp, addr, &mfl))
  35. return false;
  36. pfl->l_type = mfl.l_type;
  37. pfl->l_whence = mfl.l_whence;
  38. pfl->l_start = mfl.l_start;
  39. pfl->l_len = mfl.l_len;
  40. pfl->l_pid = mfl.l_pid;
  41. return true;
  42. }
  43. MPERS_PRINTER_DECL(bool, fetch_struct_flock64, struct tcb *const tcp,
  44. const kernel_ulong_t addr, void *const p)
  45. {
  46. struct_kernel_flock64 *pfl = p;
  47. struct_flock64 mfl;
  48. if (FLOCK_STRUCTS_EQ(struct_flock64))
  49. return !umove_or_printaddr(tcp, addr, pfl);
  50. if (umove_or_printaddr(tcp, addr, &mfl))
  51. return false;
  52. pfl->l_type = mfl.l_type;
  53. pfl->l_whence = mfl.l_whence;
  54. pfl->l_start = mfl.l_start;
  55. pfl->l_len = mfl.l_len;
  56. pfl->l_pid = mfl.l_pid;
  57. return true;
  58. }