• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
3  * Copyright (c) 2016-2017 The strace developers.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "defs.h"
30 
31 #include DEF_MPERS_TYPE(struct_stat64)
32 
33 #include "asm_stat.h"
34 
35 #if defined MPERS_IS_m32
36 # undef HAVE_STRUCT_STAT64
37 # undef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
38 # ifdef HAVE_M32_STRUCT_STAT64
39 #  define HAVE_STRUCT_STAT64 1
40 #  ifdef HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC
41 #   define HAVE_STRUCT_STAT64_ST_MTIME_NSEC 1
42 #  endif /* HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC */
43 # endif /* HAVE_M32_STRUCT_STAT64 */
44 #elif defined MPERS_IS_mx32
45 # undef HAVE_STRUCT_STAT64
46 # undef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
47 # ifdef HAVE_MX32_STRUCT_STAT64
48 #  define HAVE_STRUCT_STAT64 1
49 #  ifdef HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC
50 #   define HAVE_STRUCT_STAT64_ST_MTIME_NSEC 1
51 #  endif /* HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC */
52 # endif /* HAVE_MX32_STRUCT_STAT64 */
53 #endif /* MPERS_IS_m32 || MPERS_IS_mx32 */
54 
55 #ifndef HAVE_STRUCT_STAT64
56 struct stat64 {};
57 #endif
58 
59 typedef struct stat64 struct_stat64;
60 
61 #include MPERS_DEFS
62 
63 #include "stat.h"
64 
65 #ifdef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
66 # define TIME_NSEC(arg) zero_extend_signed_to_ull(arg)
67 # define HAVE_NSEC true
68 #else
69 # define TIME_NSEC(arg) 0
70 # define HAVE_NSEC false
71 #endif
72 
MPERS_PRINTER_DECL(bool,fetch_struct_stat64,struct tcb * const tcp,const kernel_ulong_t addr,struct strace_stat * const dst)73 MPERS_PRINTER_DECL(bool, fetch_struct_stat64,
74 		   struct tcb *const tcp, const kernel_ulong_t addr,
75 		   struct strace_stat *const dst)
76 {
77 #ifdef HAVE_STRUCT_STAT64
78 	struct_stat64 buf;
79 	if (umove_or_printaddr(tcp, addr, &buf))
80 		return false;
81 
82 	dst->dev = zero_extend_signed_to_ull(buf.st_dev);
83 	dst->ino = zero_extend_signed_to_ull(buf.st_ino);
84 	dst->rdev = zero_extend_signed_to_ull(buf.st_rdev);
85 	dst->size = zero_extend_signed_to_ull(buf.st_size);
86 	dst->blocks = zero_extend_signed_to_ull(buf.st_blocks);
87 	dst->blksize = zero_extend_signed_to_ull(buf.st_blksize);
88 	dst->mode = zero_extend_signed_to_ull(buf.st_mode);
89 	dst->nlink = zero_extend_signed_to_ull(buf.st_nlink);
90 	dst->uid = zero_extend_signed_to_ull(buf.st_uid);
91 	dst->gid = zero_extend_signed_to_ull(buf.st_gid);
92 	dst->atime = sign_extend_unsigned_to_ll(buf.st_atime);
93 	dst->ctime = sign_extend_unsigned_to_ll(buf.st_ctime);
94 	dst->mtime = sign_extend_unsigned_to_ll(buf.st_mtime);
95 	dst->atime_nsec = TIME_NSEC(buf.st_atime_nsec);
96 	dst->ctime_nsec = TIME_NSEC(buf.st_ctime_nsec);
97 	dst->mtime_nsec = TIME_NSEC(buf.st_mtime_nsec);
98 	dst->has_nsec = HAVE_NSEC;
99 	return true;
100 #else /* !HAVE_STRUCT_STAT64 */
101 	printaddr(addr);
102 	return false;
103 #endif
104 }
105