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_stat.c 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
  3. * Copyright (c) 2016-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_stat)
  10. #include "asm_stat.h"
  11. #if defined MPERS_IS_m32
  12. # undef HAVE_STRUCT_STAT
  13. # undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
  14. # ifdef HAVE_M32_STRUCT_STAT
  15. # define HAVE_STRUCT_STAT 1
  16. # ifdef HAVE_M32_STRUCT_STAT_ST_MTIME_NSEC
  17. # define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
  18. # endif /* HAVE_M32_STRUCT_STAT_ST_MTIME_NSEC */
  19. # endif /* HAVE_M32_STRUCT_STAT */
  20. #elif defined MPERS_IS_mx32
  21. # undef HAVE_STRUCT_STAT
  22. # undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
  23. # ifdef HAVE_MX32_STRUCT_STAT
  24. # define HAVE_STRUCT_STAT 1
  25. # ifdef HAVE_MX32_STRUCT_STAT_ST_MTIME_NSEC
  26. # define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
  27. # endif /* HAVE_MX32_STRUCT_STAT_ST_MTIME_NSEC */
  28. # endif /* HAVE_MX32_STRUCT_STAT */
  29. #else /* !MPERS_IS_m32 && !MPERS_IS_mx32 */
  30. # define HAVE_STRUCT_STAT 1
  31. #endif
  32. #ifndef HAVE_STRUCT_STAT
  33. struct stat {};
  34. #endif
  35. typedef struct stat struct_stat;
  36. #include MPERS_DEFS
  37. #include "stat.h"
  38. #ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC
  39. # define TIME_NSEC(arg) zero_extend_signed_to_ull(arg)
  40. # define HAVE_NSEC true
  41. #else
  42. # define TIME_NSEC(arg) 0
  43. # define HAVE_NSEC false
  44. #endif
  45. MPERS_PRINTER_DECL(bool, fetch_struct_stat,
  46. struct tcb *const tcp, const kernel_ulong_t addr,
  47. struct strace_stat *const dst)
  48. {
  49. #ifdef HAVE_STRUCT_STAT
  50. struct_stat buf;
  51. if (umove_or_printaddr(tcp, addr, &buf))
  52. return false;
  53. dst->dev = zero_extend_signed_to_ull(buf.st_dev);
  54. dst->ino = zero_extend_signed_to_ull(buf.st_ino);
  55. dst->rdev = zero_extend_signed_to_ull(buf.st_rdev);
  56. dst->size = zero_extend_signed_to_ull(buf.st_size);
  57. dst->blocks = zero_extend_signed_to_ull(buf.st_blocks);
  58. dst->blksize = zero_extend_signed_to_ull(buf.st_blksize);
  59. dst->mode = zero_extend_signed_to_ull(buf.st_mode);
  60. dst->nlink = zero_extend_signed_to_ull(buf.st_nlink);
  61. dst->uid = zero_extend_signed_to_ull(buf.st_uid);
  62. dst->gid = zero_extend_signed_to_ull(buf.st_gid);
  63. dst->atime = sign_extend_unsigned_to_ll(buf.st_atime);
  64. dst->ctime = sign_extend_unsigned_to_ll(buf.st_ctime);
  65. dst->mtime = sign_extend_unsigned_to_ll(buf.st_mtime);
  66. dst->atime_nsec = TIME_NSEC(buf.st_atime_nsec);
  67. dst->ctime_nsec = TIME_NSEC(buf.st_ctime_nsec);
  68. dst->mtime_nsec = TIME_NSEC(buf.st_mtime_nsec);
  69. dst->has_nsec = HAVE_NSEC;
  70. return true;
  71. #else /* !HAVE_STRUCT_STAT */
  72. printaddr(addr);
  73. return false;
  74. #endif
  75. }