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_stat64.c 2.5KB

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