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