1 /*
2 * Copyright (c) 2018-2021 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8 #include "defs.h"
9
10 /*
11 * Fetch indirect syscall arguments that are provided as an array.
12 * Return a pointer to a static array of kernel_ulong_t elements,
13 * or NULL in case of fetch failure.
14 */
15 kernel_ulong_t *
16 fetch_indirect_syscall_args(struct tcb *const tcp,
17 const kernel_ulong_t addr,
18 const unsigned int n_args)
19 {
20 static kernel_ulong_t u_arg[MAX_ARGS];
21
22 if (current_wordsize == sizeof(*u_arg)) {
23 if (umoven(tcp, addr, sizeof(*u_arg) * n_args, u_arg))
24 return NULL;
25 } else {
26 uint32_t narrow_arg[ARRAY_SIZE(u_arg)];
27
28 if (umoven(tcp, addr, sizeof(*narrow_arg) * n_args, narrow_arg))
29 return NULL;
30 for (unsigned int i = 0; i < n_args; ++i)
31 u_arg[i] = narrow_arg[i];
32 }
33
34 return u_arg;
35 }