1 /*
2 * Copyright (c) 2015-2021 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8 #include "negated_errno.h"
9
10 static void
11 arch_get_error(struct tcb *tcp, const bool check_errno)
12 {
13 /*
14 * In X32, return value is 64-bit (llseek uses one).
15 * Using merely "long rax" would not work.
16 */
17 long long rax;
18
19 if (x86_io.iov_len == sizeof(i386_regs)) {
20 /* Sign extend from 32 bits */
21 rax = (int32_t) i386_regs.eax;
22 } else {
23 rax = x86_64_regs.rax;
24 }
25
26 if (check_errno && is_negated_errno(rax)) {
27 tcp->u_rval = -1;
28 tcp->u_error = -rax;
29 } else {
30 if (x86_io.iov_len == sizeof(i386_regs))
31 tcp->u_rval = (uint32_t) rax;
32 else
33 tcp->u_rval = rax;
34 }
35 }