1*cf84ac9aSAndroid Build Coastguard Worker /*
2*cf84ac9aSAndroid Build Coastguard Worker * Copyright (c) 2016 Dmitry V. Levin <[email protected]>
3*cf84ac9aSAndroid Build Coastguard Worker * Copyright (c) 2016-2018 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 #ifndef STRACE_TESTS_H
30*cf84ac9aSAndroid Build Coastguard Worker #define STRACE_TESTS_H
31*cf84ac9aSAndroid Build Coastguard Worker
32*cf84ac9aSAndroid Build Coastguard Worker #ifdef HAVE_CONFIG_H
33*cf84ac9aSAndroid Build Coastguard Worker # include "config.h"
34*cf84ac9aSAndroid Build Coastguard Worker #endif
35*cf84ac9aSAndroid Build Coastguard Worker
36*cf84ac9aSAndroid Build Coastguard Worker #ifdef TESTS_SIZEOF_KERNEL_LONG_T
37*cf84ac9aSAndroid Build Coastguard Worker # undef SIZEOF_KERNEL_LONG_T
38*cf84ac9aSAndroid Build Coastguard Worker # define SIZEOF_KERNEL_LONG_T TESTS_SIZEOF_KERNEL_LONG_T
39*cf84ac9aSAndroid Build Coastguard Worker #endif
40*cf84ac9aSAndroid Build Coastguard Worker
41*cf84ac9aSAndroid Build Coastguard Worker #ifdef TESTS_SIZEOF_LONG
42*cf84ac9aSAndroid Build Coastguard Worker # undef SIZEOF_LONG
43*cf84ac9aSAndroid Build Coastguard Worker # define SIZEOF_LONG TESTS_SIZEOF_LONG
44*cf84ac9aSAndroid Build Coastguard Worker #endif
45*cf84ac9aSAndroid Build Coastguard Worker
46*cf84ac9aSAndroid Build Coastguard Worker #include <stdbool.h>
47*cf84ac9aSAndroid Build Coastguard Worker #include <sys/types.h>
48*cf84ac9aSAndroid Build Coastguard Worker #include "kernel_types.h"
49*cf84ac9aSAndroid Build Coastguard Worker #include "gcc_compat.h"
50*cf84ac9aSAndroid Build Coastguard Worker #include "macros.h"
51*cf84ac9aSAndroid Build Coastguard Worker
52*cf84ac9aSAndroid Build Coastguard Worker /*
53*cf84ac9aSAndroid Build Coastguard Worker * The printf-like function to use in header files
54*cf84ac9aSAndroid Build Coastguard Worker * shared between strace and its tests.
55*cf84ac9aSAndroid Build Coastguard Worker */
56*cf84ac9aSAndroid Build Coastguard Worker #ifndef STRACE_PRINTF
57*cf84ac9aSAndroid Build Coastguard Worker # define STRACE_PRINTF printf
58*cf84ac9aSAndroid Build Coastguard Worker #endif
59*cf84ac9aSAndroid Build Coastguard Worker
60*cf84ac9aSAndroid Build Coastguard Worker /* Tests of "strace -v" are expected to define VERBOSE to 1. */
61*cf84ac9aSAndroid Build Coastguard Worker #ifndef VERBOSE
62*cf84ac9aSAndroid Build Coastguard Worker # define VERBOSE 0
63*cf84ac9aSAndroid Build Coastguard Worker #endif
64*cf84ac9aSAndroid Build Coastguard Worker
65*cf84ac9aSAndroid Build Coastguard Worker /* xlat verbosity defaults */
66*cf84ac9aSAndroid Build Coastguard Worker #ifndef XLAT_RAW
67*cf84ac9aSAndroid Build Coastguard Worker # define XLAT_RAW 0
68*cf84ac9aSAndroid Build Coastguard Worker #endif
69*cf84ac9aSAndroid Build Coastguard Worker #ifndef XLAT_VERBOSE
70*cf84ac9aSAndroid Build Coastguard Worker # define XLAT_VERBOSE 0
71*cf84ac9aSAndroid Build Coastguard Worker #endif
72*cf84ac9aSAndroid Build Coastguard Worker
73*cf84ac9aSAndroid Build Coastguard Worker #ifndef DEFAULT_STRLEN
74*cf84ac9aSAndroid Build Coastguard Worker /* Default maximum # of bytes printed in printstr et al. */
75*cf84ac9aSAndroid Build Coastguard Worker # define DEFAULT_STRLEN 32
76*cf84ac9aSAndroid Build Coastguard Worker #endif
77*cf84ac9aSAndroid Build Coastguard Worker
78*cf84ac9aSAndroid Build Coastguard Worker /* Cached sysconf(_SC_PAGESIZE). */
79*cf84ac9aSAndroid Build Coastguard Worker size_t get_page_size(void);
80*cf84ac9aSAndroid Build Coastguard Worker
81*cf84ac9aSAndroid Build Coastguard Worker /* The size of kernel's sigset_t. */
82*cf84ac9aSAndroid Build Coastguard Worker unsigned int get_sigset_size(void);
83*cf84ac9aSAndroid Build Coastguard Worker
84*cf84ac9aSAndroid Build Coastguard Worker /* Print message and strerror(errno) to stderr, then exit(1). */
85*cf84ac9aSAndroid Build Coastguard Worker void perror_msg_and_fail(const char *, ...)
86*cf84ac9aSAndroid Build Coastguard Worker ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
87*cf84ac9aSAndroid Build Coastguard Worker /* Print message to stderr, then exit(1). */
88*cf84ac9aSAndroid Build Coastguard Worker void error_msg_and_fail(const char *, ...)
89*cf84ac9aSAndroid Build Coastguard Worker ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
90*cf84ac9aSAndroid Build Coastguard Worker /* Print message to stderr, then exit(77). */
91*cf84ac9aSAndroid Build Coastguard Worker void error_msg_and_skip(const char *, ...)
92*cf84ac9aSAndroid Build Coastguard Worker ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
93*cf84ac9aSAndroid Build Coastguard Worker /* Print message and strerror(errno) to stderr, then exit(77). */
94*cf84ac9aSAndroid Build Coastguard Worker void perror_msg_and_skip(const char *, ...)
95*cf84ac9aSAndroid Build Coastguard Worker ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
96*cf84ac9aSAndroid Build Coastguard Worker
97*cf84ac9aSAndroid Build Coastguard Worker #ifndef perror_msg_and_fail
98*cf84ac9aSAndroid Build Coastguard Worker # define perror_msg_and_fail(fmt_, ...) \
99*cf84ac9aSAndroid Build Coastguard Worker perror_msg_and_fail("%s:%d: " fmt_, __FILE__, __LINE__, ##__VA_ARGS__)
100*cf84ac9aSAndroid Build Coastguard Worker #endif
101*cf84ac9aSAndroid Build Coastguard Worker #ifndef perror_msg_and_fail
102*cf84ac9aSAndroid Build Coastguard Worker # define error_msg_and_fail(fmt_, ...) \
103*cf84ac9aSAndroid Build Coastguard Worker error_msg_and_fail("%s:%d: " fmt_, __FILE__, __LINE__, ##__VA_ARGS__)
104*cf84ac9aSAndroid Build Coastguard Worker #endif
105*cf84ac9aSAndroid Build Coastguard Worker
106*cf84ac9aSAndroid Build Coastguard Worker /* Stat the specified file and skip the test if the stat call failed. */
107*cf84ac9aSAndroid Build Coastguard Worker void skip_if_unavailable(const char *);
108*cf84ac9aSAndroid Build Coastguard Worker
109*cf84ac9aSAndroid Build Coastguard Worker /*
110*cf84ac9aSAndroid Build Coastguard Worker * Allocate memory that ends on the page boundary.
111*cf84ac9aSAndroid Build Coastguard Worker * Pages allocated by this call are preceded by an unmapped page
112*cf84ac9aSAndroid Build Coastguard Worker * and followed also by an unmapped page.
113*cf84ac9aSAndroid Build Coastguard Worker */
114*cf84ac9aSAndroid Build Coastguard Worker void *tail_alloc(const size_t)
115*cf84ac9aSAndroid Build Coastguard Worker ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
116*cf84ac9aSAndroid Build Coastguard Worker /* Allocate memory using tail_alloc, then memcpy. */
117*cf84ac9aSAndroid Build Coastguard Worker void *tail_memdup(const void *, const size_t)
118*cf84ac9aSAndroid Build Coastguard Worker ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((2));
119*cf84ac9aSAndroid Build Coastguard Worker
120*cf84ac9aSAndroid Build Coastguard Worker #define midtail_alloc(after_, before_) \
121*cf84ac9aSAndroid Build Coastguard Worker ((void *) ((char *) tail_alloc(((before_) + (after_))) + (before_)))
122*cf84ac9aSAndroid Build Coastguard Worker
123*cf84ac9aSAndroid Build Coastguard Worker /*
124*cf84ac9aSAndroid Build Coastguard Worker * Allocate an object of the specified type at the end
125*cf84ac9aSAndroid Build Coastguard Worker * of a mapped memory region.
126*cf84ac9aSAndroid Build Coastguard Worker * Assign its address to the specified constant pointer.
127*cf84ac9aSAndroid Build Coastguard Worker */
128*cf84ac9aSAndroid Build Coastguard Worker #define TAIL_ALLOC_OBJECT_CONST_PTR(type_name, type_ptr) \
129*cf84ac9aSAndroid Build Coastguard Worker type_name *const type_ptr = tail_alloc(sizeof(*type_ptr))
130*cf84ac9aSAndroid Build Coastguard Worker
131*cf84ac9aSAndroid Build Coastguard Worker /*
132*cf84ac9aSAndroid Build Coastguard Worker * Allocate an object of the specified type at the end
133*cf84ac9aSAndroid Build Coastguard Worker * of a mapped memory region.
134*cf84ac9aSAndroid Build Coastguard Worker * Assign its address to the specified variable pointer.
135*cf84ac9aSAndroid Build Coastguard Worker */
136*cf84ac9aSAndroid Build Coastguard Worker #define TAIL_ALLOC_OBJECT_VAR_PTR(type_name, type_ptr) \
137*cf84ac9aSAndroid Build Coastguard Worker type_name *type_ptr = tail_alloc(sizeof(*type_ptr))
138*cf84ac9aSAndroid Build Coastguard Worker
139*cf84ac9aSAndroid Build Coastguard Worker /*
140*cf84ac9aSAndroid Build Coastguard Worker * Fill memory (pointed by ptr, having size bytes) with different bytes (with
141*cf84ac9aSAndroid Build Coastguard Worker * values starting with start and resetting every period) in order to catch
142*cf84ac9aSAndroid Build Coastguard Worker * sign, byte order and/or alignment errors.
143*cf84ac9aSAndroid Build Coastguard Worker */
144*cf84ac9aSAndroid Build Coastguard Worker void fill_memory_ex(void *ptr, size_t size, unsigned char start,
145*cf84ac9aSAndroid Build Coastguard Worker unsigned char period);
146*cf84ac9aSAndroid Build Coastguard Worker /* Shortcut for fill_memory_ex(ptr, size, 0x80, 0x80) */
147*cf84ac9aSAndroid Build Coastguard Worker void fill_memory(void *ptr, size_t size);
148*cf84ac9aSAndroid Build Coastguard Worker
149*cf84ac9aSAndroid Build Coastguard Worker /* Close stdin, move stdout to a non-standard descriptor, and print. */
150*cf84ac9aSAndroid Build Coastguard Worker void tprintf(const char *, ...)
151*cf84ac9aSAndroid Build Coastguard Worker ATTRIBUTE_FORMAT((printf, 1, 2));
152*cf84ac9aSAndroid Build Coastguard Worker
153*cf84ac9aSAndroid Build Coastguard Worker /* Make a hexdump copy of C string */
154*cf84ac9aSAndroid Build Coastguard Worker const char *hexdump_strdup(const char *);
155*cf84ac9aSAndroid Build Coastguard Worker
156*cf84ac9aSAndroid Build Coastguard Worker /* Make a hexdump copy of memory */
157*cf84ac9aSAndroid Build Coastguard Worker const char *hexdump_memdup(const char *, size_t);
158*cf84ac9aSAndroid Build Coastguard Worker
159*cf84ac9aSAndroid Build Coastguard Worker /* Make a hexquoted copy of a string */
160*cf84ac9aSAndroid Build Coastguard Worker const char *hexquote_strndup(const char *, size_t);
161*cf84ac9aSAndroid Build Coastguard Worker
162*cf84ac9aSAndroid Build Coastguard Worker /* Return inode number of socket descriptor. */
163*cf84ac9aSAndroid Build Coastguard Worker unsigned long inode_of_sockfd(int);
164*cf84ac9aSAndroid Build Coastguard Worker
165*cf84ac9aSAndroid Build Coastguard Worker /* Print string in a quoted form with optional escape characters. */
166*cf84ac9aSAndroid Build Coastguard Worker void print_quoted_string_ex(const char *, bool quote, const char *escape_str);
167*cf84ac9aSAndroid Build Coastguard Worker
168*cf84ac9aSAndroid Build Coastguard Worker /* Print string in a quoted form. */
169*cf84ac9aSAndroid Build Coastguard Worker void print_quoted_string(const char *);
170*cf84ac9aSAndroid Build Coastguard Worker
171*cf84ac9aSAndroid Build Coastguard Worker /*
172*cf84ac9aSAndroid Build Coastguard Worker * Print a NUL-terminated string `str' of length up to `size' - 1
173*cf84ac9aSAndroid Build Coastguard Worker * in a quoted form.
174*cf84ac9aSAndroid Build Coastguard Worker */
175*cf84ac9aSAndroid Build Coastguard Worker void print_quoted_cstring(const char *str, size_t size);
176*cf84ac9aSAndroid Build Coastguard Worker
177*cf84ac9aSAndroid Build Coastguard Worker /*
178*cf84ac9aSAndroid Build Coastguard Worker * Print a NUL-terminated string `str' of length up to `size'
179*cf84ac9aSAndroid Build Coastguard Worker * in a quoted form.
180*cf84ac9aSAndroid Build Coastguard Worker */
181*cf84ac9aSAndroid Build Coastguard Worker void print_quoted_stringn(const char *str, size_t size);
182*cf84ac9aSAndroid Build Coastguard Worker
183*cf84ac9aSAndroid Build Coastguard Worker /* Print memory in a quoted form with optional escape characters. */
184*cf84ac9aSAndroid Build Coastguard Worker void print_quoted_memory_ex(const void *, size_t, bool quote,
185*cf84ac9aSAndroid Build Coastguard Worker const char *escape_chars);
186*cf84ac9aSAndroid Build Coastguard Worker
187*cf84ac9aSAndroid Build Coastguard Worker /* Print memory in a quoted form. */
188*cf84ac9aSAndroid Build Coastguard Worker void print_quoted_memory(const void *, size_t);
189*cf84ac9aSAndroid Build Coastguard Worker
190*cf84ac9aSAndroid Build Coastguard Worker /* Print memory in a hexquoted form. */
191*cf84ac9aSAndroid Build Coastguard Worker void print_quoted_hex(const void *, size_t);
192*cf84ac9aSAndroid Build Coastguard Worker
193*cf84ac9aSAndroid Build Coastguard Worker /* Print time_t and nanoseconds in symbolic format. */
194*cf84ac9aSAndroid Build Coastguard Worker void print_time_t_nsec(time_t, unsigned long long, int);
195*cf84ac9aSAndroid Build Coastguard Worker
196*cf84ac9aSAndroid Build Coastguard Worker /* Print time_t and microseconds in symbolic format. */
197*cf84ac9aSAndroid Build Coastguard Worker void print_time_t_usec(time_t, unsigned long long, int);
198*cf84ac9aSAndroid Build Coastguard Worker
199*cf84ac9aSAndroid Build Coastguard Worker /* Read an int from the file. */
200*cf84ac9aSAndroid Build Coastguard Worker int read_int_from_file(const char *, int *);
201*cf84ac9aSAndroid Build Coastguard Worker
202*cf84ac9aSAndroid Build Coastguard Worker /* Check whether given uid matches kernel overflowuid. */
203*cf84ac9aSAndroid Build Coastguard Worker void check_overflowuid(const int);
204*cf84ac9aSAndroid Build Coastguard Worker
205*cf84ac9aSAndroid Build Coastguard Worker /* Check whether given gid matches kernel overflowgid. */
206*cf84ac9aSAndroid Build Coastguard Worker void check_overflowgid(const int);
207*cf84ac9aSAndroid Build Coastguard Worker
208*cf84ac9aSAndroid Build Coastguard Worker /* Translate errno to its name. */
209*cf84ac9aSAndroid Build Coastguard Worker const char *errno2name(void);
210*cf84ac9aSAndroid Build Coastguard Worker
211*cf84ac9aSAndroid Build Coastguard Worker /* Translate signal number to its name. */
212*cf84ac9aSAndroid Build Coastguard Worker const char *signal2name(int);
213*cf84ac9aSAndroid Build Coastguard Worker
214*cf84ac9aSAndroid Build Coastguard Worker /* Print return code and, in case return code is -1, errno information. */
215*cf84ac9aSAndroid Build Coastguard Worker const char *sprintrc(long rc);
216*cf84ac9aSAndroid Build Coastguard Worker /* sprintrc variant suitable for usage as part of grep pattern. */
217*cf84ac9aSAndroid Build Coastguard Worker const char *sprintrc_grep(long rc);
218*cf84ac9aSAndroid Build Coastguard Worker
219*cf84ac9aSAndroid Build Coastguard Worker struct xlat;
220*cf84ac9aSAndroid Build Coastguard Worker
221*cf84ac9aSAndroid Build Coastguard Worker /* Print flags in symbolic form according to xlat table. */
222*cf84ac9aSAndroid Build Coastguard Worker int printflags(const struct xlat *, const unsigned long long, const char *);
223*cf84ac9aSAndroid Build Coastguard Worker
224*cf84ac9aSAndroid Build Coastguard Worker /* Print constant in symbolic form according to xlat table. */
225*cf84ac9aSAndroid Build Coastguard Worker int printxval(const struct xlat *, const unsigned long long, const char *);
226*cf84ac9aSAndroid Build Coastguard Worker
227*cf84ac9aSAndroid Build Coastguard Worker /* Invoke a socket syscall, either directly or via __NR_socketcall. */
228*cf84ac9aSAndroid Build Coastguard Worker int socketcall(const int nr, const int call,
229*cf84ac9aSAndroid Build Coastguard Worker long a1, long a2, long a3, long a4, long a5);
230*cf84ac9aSAndroid Build Coastguard Worker
231*cf84ac9aSAndroid Build Coastguard Worker /* Wrappers for recvmmsg and sendmmsg syscalls. */
232*cf84ac9aSAndroid Build Coastguard Worker struct mmsghdr;
233*cf84ac9aSAndroid Build Coastguard Worker struct timespec;
234*cf84ac9aSAndroid Build Coastguard Worker int recv_mmsg(int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *);
235*cf84ac9aSAndroid Build Coastguard Worker int send_mmsg(int, struct mmsghdr *, unsigned int, unsigned int);
236*cf84ac9aSAndroid Build Coastguard Worker
237*cf84ac9aSAndroid Build Coastguard Worker /* Create a netlink socket. */
238*cf84ac9aSAndroid Build Coastguard Worker int create_nl_socket_ext(int proto, const char *name);
239*cf84ac9aSAndroid Build Coastguard Worker #define create_nl_socket(proto) create_nl_socket_ext((proto), #proto)
240*cf84ac9aSAndroid Build Coastguard Worker
241*cf84ac9aSAndroid Build Coastguard Worker /* Create a pipe with maximized descriptor numbers. */
242*cf84ac9aSAndroid Build Coastguard Worker void pipe_maxfd(int pipefd[2]);
243*cf84ac9aSAndroid Build Coastguard Worker
244*cf84ac9aSAndroid Build Coastguard Worker /* if_nametoindex("lo") */
245*cf84ac9aSAndroid Build Coastguard Worker unsigned int ifindex_lo(void);
246*cf84ac9aSAndroid Build Coastguard Worker
247*cf84ac9aSAndroid Build Coastguard Worker #ifdef HAVE_IF_INDEXTONAME
248*cf84ac9aSAndroid Build Coastguard Worker # define IFINDEX_LO_STR "if_nametoindex(\"lo\")"
249*cf84ac9aSAndroid Build Coastguard Worker #else
250*cf84ac9aSAndroid Build Coastguard Worker # define IFINDEX_LO_STR "1"
251*cf84ac9aSAndroid Build Coastguard Worker #endif
252*cf84ac9aSAndroid Build Coastguard Worker
253*cf84ac9aSAndroid Build Coastguard Worker #define F8ILL_KULONG_SUPPORTED (sizeof(void *) < sizeof(kernel_ulong_t))
254*cf84ac9aSAndroid Build Coastguard Worker #define F8ILL_KULONG_MASK ((kernel_ulong_t) 0xffffffff00000000ULL)
255*cf84ac9aSAndroid Build Coastguard Worker
256*cf84ac9aSAndroid Build Coastguard Worker /*
257*cf84ac9aSAndroid Build Coastguard Worker * For 64-bit kernel_ulong_t and 32-bit pointer,
258*cf84ac9aSAndroid Build Coastguard Worker * return a kernel_ulong_t value by filling higher bits.
259*cf84ac9aSAndroid Build Coastguard Worker * For other architertures, return the original pointer.
260*cf84ac9aSAndroid Build Coastguard Worker */
261*cf84ac9aSAndroid Build Coastguard Worker static inline kernel_ulong_t
f8ill_ptr_to_kulong(const void * const ptr)262*cf84ac9aSAndroid Build Coastguard Worker f8ill_ptr_to_kulong(const void *const ptr)
263*cf84ac9aSAndroid Build Coastguard Worker {
264*cf84ac9aSAndroid Build Coastguard Worker const unsigned long uptr = (unsigned long) ptr;
265*cf84ac9aSAndroid Build Coastguard Worker return F8ILL_KULONG_SUPPORTED
266*cf84ac9aSAndroid Build Coastguard Worker ? F8ILL_KULONG_MASK | uptr : (kernel_ulong_t) uptr;
267*cf84ac9aSAndroid Build Coastguard Worker }
268*cf84ac9aSAndroid Build Coastguard Worker
269*cf84ac9aSAndroid Build Coastguard Worker # define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1)
270*cf84ac9aSAndroid Build Coastguard Worker
271*cf84ac9aSAndroid Build Coastguard Worker /* Zero-extend a signed integer type to unsigned long long. */
272*cf84ac9aSAndroid Build Coastguard Worker #define zero_extend_signed_to_ull(v) \
273*cf84ac9aSAndroid Build Coastguard Worker (sizeof(v) == sizeof(char) ? (unsigned long long) (unsigned char) (v) : \
274*cf84ac9aSAndroid Build Coastguard Worker sizeof(v) == sizeof(short) ? (unsigned long long) (unsigned short) (v) : \
275*cf84ac9aSAndroid Build Coastguard Worker sizeof(v) == sizeof(int) ? (unsigned long long) (unsigned int) (v) : \
276*cf84ac9aSAndroid Build Coastguard Worker sizeof(v) == sizeof(long) ? (unsigned long long) (unsigned long) (v) : \
277*cf84ac9aSAndroid Build Coastguard Worker (unsigned long long) (v))
278*cf84ac9aSAndroid Build Coastguard Worker
279*cf84ac9aSAndroid Build Coastguard Worker /* Sign-extend an unsigned integer type to long long. */
280*cf84ac9aSAndroid Build Coastguard Worker #define sign_extend_unsigned_to_ll(v) \
281*cf84ac9aSAndroid Build Coastguard Worker (sizeof(v) == sizeof(char) ? (long long) (char) (v) : \
282*cf84ac9aSAndroid Build Coastguard Worker sizeof(v) == sizeof(short) ? (long long) (short) (v) : \
283*cf84ac9aSAndroid Build Coastguard Worker sizeof(v) == sizeof(int) ? (long long) (int) (v) : \
284*cf84ac9aSAndroid Build Coastguard Worker sizeof(v) == sizeof(long) ? (long long) (long) (v) : \
285*cf84ac9aSAndroid Build Coastguard Worker (long long) (v))
286*cf84ac9aSAndroid Build Coastguard Worker
287*cf84ac9aSAndroid Build Coastguard Worker #define SKIP_MAIN_UNDEFINED(arg) \
288*cf84ac9aSAndroid Build Coastguard Worker int main(void) { error_msg_and_skip("undefined: %s", arg); }
289*cf84ac9aSAndroid Build Coastguard Worker
290*cf84ac9aSAndroid Build Coastguard Worker #if WORDS_BIGENDIAN
291*cf84ac9aSAndroid Build Coastguard Worker # define LL_PAIR(HI, LO) (HI), (LO)
292*cf84ac9aSAndroid Build Coastguard Worker #else
293*cf84ac9aSAndroid Build Coastguard Worker # define LL_PAIR(HI, LO) (LO), (HI)
294*cf84ac9aSAndroid Build Coastguard Worker #endif
295*cf84ac9aSAndroid Build Coastguard Worker #define LL_VAL_TO_PAIR(llval) LL_PAIR((long) ((llval) >> 32), (long) (llval))
296*cf84ac9aSAndroid Build Coastguard Worker
297*cf84ac9aSAndroid Build Coastguard Worker #define ARG_STR(_arg) (_arg), #_arg
298*cf84ac9aSAndroid Build Coastguard Worker #define ARG_ULL_STR(_arg) _arg##ULL, #_arg
299*cf84ac9aSAndroid Build Coastguard Worker
300*cf84ac9aSAndroid Build Coastguard Worker /*
301*cf84ac9aSAndroid Build Coastguard Worker * Assign an object of type DEST_TYPE at address DEST_ADDR
302*cf84ac9aSAndroid Build Coastguard Worker * using memcpy to avoid potential unaligned access.
303*cf84ac9aSAndroid Build Coastguard Worker */
304*cf84ac9aSAndroid Build Coastguard Worker #define SET_STRUCT(DEST_TYPE, DEST_ADDR, ...) \
305*cf84ac9aSAndroid Build Coastguard Worker do { \
306*cf84ac9aSAndroid Build Coastguard Worker DEST_TYPE dest_type_tmp_var = { __VA_ARGS__ }; \
307*cf84ac9aSAndroid Build Coastguard Worker memcpy(DEST_ADDR, &dest_type_tmp_var, sizeof(dest_type_tmp_var)); \
308*cf84ac9aSAndroid Build Coastguard Worker } while (0)
309*cf84ac9aSAndroid Build Coastguard Worker
310*cf84ac9aSAndroid Build Coastguard Worker #define NLMSG_ATTR(nlh, hdrlen) ((void *)(nlh) + NLMSG_SPACE(hdrlen))
311*cf84ac9aSAndroid Build Coastguard Worker
312*cf84ac9aSAndroid Build Coastguard Worker #endif /* !STRACE_TESTS_H */
313