1 /*
2 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@strace.io>
3 * Copyright (c) 2017-2021 The strace developers.
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8
9 #ifndef STRACE_NEGATED_ERRNO_H
10 # define STRACE_NEGATED_ERRNO_H
11
12 /*
13 * Check the syscall return value register value for whether it is
14 * a negated errno code indicating an error, or a success return value.
15 */
16 static inline bool
17 is_negated_errno(kernel_ulong_t val)
18 {
19 kernel_ulong_t max = -(kernel_long_t) MAX_ERRNO_VALUE;
20
21 # ifndef current_klongsize
22 if (current_klongsize < sizeof(val)) {
23 val = (uint32_t) val;
24 max = (uint32_t) max;
25 }
26 # endif /* !current_klongsize */
27
28 return val >= max;
29 }
30
31 #endif /* !STRACE_NEGATED_ERRNO_H */