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