Skip to content

Commit f4d92c5

Browse files
bozutafvivier
authored andcommitted
linux-user: Add strace support for printing arguments of fallocate()
This patch implements strace argument printing functionality for following syscall: *fallocate - manipulate file space int fallocate(int fd, int mode, off_t offset, off_t len) man page: https://www.man7.org/linux/man-pages/man2/fallocate.2.html Implementation notes: This syscall's second argument "mode" is composed of predefined values which represent flags that determine the type of operation that is to be performed on the file space. For that reason, a printing function "print_fallocate" was stated in file "strace.list". This printing function uses an already existing function "print_flags()" to print flags of the "mode" argument. These flags are stated inside an array "falloc_flags" that contains values of type "struct flags". These values are instantiated using an existing macro "FLAG_GENERIC()". Most of these flags are defined after kernel version 3.0 which is why they are enwrapped in an #ifdef directive. The syscall's third ant fourth argument are of type "off_t" which can cause variations between 32/64-bit architectures. To handle this variation, function "target_offset64()" was copied from file "strace.c" and used in "print_fallocate" to print "off_t" arguments for 32-bit architectures. Signed-off-by: Filip Bozuta <[email protected]> Reviewed-by: Laurent Vivier <[email protected]> Message-Id: <[email protected]> Signed-off-by: Laurent Vivier <[email protected]>
1 parent 5844f4b commit f4d92c5

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

linux-user/qemu.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,22 @@ static inline int is_error(abi_long ret)
670670
return (abi_ulong)ret >= (abi_ulong)(-4096);
671671
}
672672

673+
#if TARGET_ABI_BITS == 32
674+
static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
675+
{
676+
#ifdef TARGET_WORDS_BIGENDIAN
677+
return ((uint64_t)word0 << 32) | word1;
678+
#else
679+
return ((uint64_t)word1 << 32) | word0;
680+
#endif
681+
}
682+
#else /* TARGET_ABI_BITS == 32 */
683+
static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
684+
{
685+
return word0;
686+
}
687+
#endif /* TARGET_ABI_BITS != 32 */
688+
673689
/**
674690
* preexit_cleanup: housekeeping before the guest exits
675691
*

linux-user/strace.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,26 @@ UNUSED static struct flags statx_mask[] = {
11351135
FLAG_END,
11361136
};
11371137

1138+
UNUSED static struct flags falloc_flags[] = {
1139+
FLAG_GENERIC(FALLOC_FL_KEEP_SIZE),
1140+
FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE),
1141+
#ifdef FALLOC_FL_NO_HIDE_STALE
1142+
FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE),
1143+
#endif
1144+
#ifdef FALLOC_FL_COLLAPSE_RANGE
1145+
FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE),
1146+
#endif
1147+
#ifdef FALLOC_FL_ZERO_RANGE
1148+
FLAG_GENERIC(FALLOC_FL_ZERO_RANGE),
1149+
#endif
1150+
#ifdef FALLOC_FL_INSERT_RANGE
1151+
FLAG_GENERIC(FALLOC_FL_INSERT_RANGE),
1152+
#endif
1153+
#ifdef FALLOC_FL_UNSHARE_RANGE
1154+
FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE),
1155+
#endif
1156+
};
1157+
11381158
/*
11391159
* print_xxx utility functions. These are used to print syscall
11401160
* parameters in certain format. All of these have parameter
@@ -1552,6 +1572,26 @@ print_faccessat(const struct syscallname *name,
15521572
}
15531573
#endif
15541574

1575+
#ifdef TARGET_NR_fallocate
1576+
static void
1577+
print_fallocate(const struct syscallname *name,
1578+
abi_long arg0, abi_long arg1, abi_long arg2,
1579+
abi_long arg3, abi_long arg4, abi_long arg5)
1580+
{
1581+
print_syscall_prologue(name);
1582+
print_raw_param("%d", arg0, 0);
1583+
print_flags(falloc_flags, arg1, 0);
1584+
#if TARGET_ABI_BITS == 32
1585+
print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0);
1586+
print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1);
1587+
#else
1588+
print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
1589+
print_raw_param(TARGET_ABI_FMT_ld, arg3, 1);
1590+
#endif
1591+
print_syscall_epilogue(name);
1592+
}
1593+
#endif
1594+
15551595
#ifdef TARGET_NR_fchmodat
15561596
static void
15571597
print_fchmodat(const struct syscallname *name,

linux-user/strace.list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
{ TARGET_NR_fadvise64_64, "fadvise64_64" , NULL, NULL, NULL },
183183
#endif
184184
#ifdef TARGET_NR_fallocate
185-
{ TARGET_NR_fallocate, "fallocate" , NULL, NULL, NULL },
185+
{ TARGET_NR_fallocate, "fallocate" , NULL, print_fallocate, NULL },
186186
#endif
187187
#ifdef TARGET_NR_fanotify_init
188188
{ TARGET_NR_fanotify_init, "fanotify_init" , NULL, NULL, NULL },

linux-user/syscall.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6712,22 +6712,6 @@ void syscall_init(void)
67126712
}
67136713
}
67146714

6715-
#if TARGET_ABI_BITS == 32
6716-
static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
6717-
{
6718-
#ifdef TARGET_WORDS_BIGENDIAN
6719-
return ((uint64_t)word0 << 32) | word1;
6720-
#else
6721-
return ((uint64_t)word1 << 32) | word0;
6722-
#endif
6723-
}
6724-
#else /* TARGET_ABI_BITS == 32 */
6725-
static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
6726-
{
6727-
return word0;
6728-
}
6729-
#endif /* TARGET_ABI_BITS != 32 */
6730-
67316715
#ifdef TARGET_NR_truncate64
67326716
static inline abi_long target_truncate64(void *cpu_env, const char *arg1,
67336717
abi_long arg2,

0 commit comments

Comments
 (0)