Skip to content

Commit 3858b93

Browse files
committed
Add helper functions to clear/restore syserror
* defs.h (temporarily_clear_syserror, restore_cleared_syserror): New prototypes. * syscall.c (saved_u_error): New variable. (temporarily_clear_syserror, restore_cleared_syserror): New functions. * aio.c (sys_io_getevents): Use temporarily_clear_syserror and restore_cleared_syserror. * mq.c (sys_mq_timedreceive): Likewise. * signal.c (sys_rt_sigtimedwait): Likewise.
1 parent 593602c commit 3858b93

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

aio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,14 @@ SYS_FUNC(io_getevents)
244244
tprints("], ");
245245
}
246246

247+
/*
248+
* Since the timeout parameter is read by the kernel
249+
* on entering syscall, it has to be decoded the same way
250+
* whether the syscall has failed or not.
251+
*/
252+
temporarily_clear_syserror(tcp);
247253
print_timespec(tcp, tcp->u_arg[4]);
254+
restore_cleared_syserror(tcp);
248255
}
249256
return 0;
250257
}

defs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ extern void get_regs(pid_t pid);
538538
extern int get_scno(struct tcb *tcp);
539539
extern const char *syscall_name(long scno);
540540

541+
extern void temporarily_clear_syserror(struct tcb *);
542+
extern void restore_cleared_syserror(struct tcb *);
543+
541544
extern int umoven(struct tcb *, long, unsigned int, void *);
542545
#define umove(pid, addr, objp) \
543546
umoven((pid), (addr), sizeof(*(objp)), (void *) (objp))

mq.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ SYS_FUNC(mq_timedreceive)
5959
else {
6060
printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
6161
tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]);
62+
/*
63+
* Since the timeout parameter is read by the kernel
64+
* on entering syscall, it has to be decoded the same way
65+
* whether the syscall has failed or not.
66+
*/
67+
temporarily_clear_syserror(tcp);
6268
printtv(tcp, tcp->u_arg[4]);
69+
restore_cleared_syserror(tcp);
6370
}
6471
return 0;
6572
}

signal.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,16 @@ SYS_FUNC(rt_sigtimedwait)
673673
/* syscall exit, and u_arg[1] was NULL */
674674
return 0;
675675
}
676+
677+
/*
678+
* Since the timeout parameter is read by the kernel
679+
* on entering syscall, it has to be decoded the same way
680+
* whether the syscall has failed or not.
681+
*/
682+
temporarily_clear_syserror(tcp);
676683
print_timespec(tcp, tcp->u_arg[2]);
684+
restore_cleared_syserror(tcp);
685+
677686
tprintf(", %lu", tcp->u_arg[3]);
678687
return 0;
679688
};

syscall.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,21 @@ trace_syscall(struct tcb *tcp)
11311131
trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);
11321132
}
11331133

1134+
static int saved_u_error;
1135+
1136+
void
1137+
temporarily_clear_syserror(struct tcb *tcp)
1138+
{
1139+
saved_u_error = tcp->u_error;
1140+
tcp->u_error = 0;
1141+
}
1142+
1143+
void
1144+
restore_cleared_syserror(struct tcb *tcp)
1145+
{
1146+
tcp->u_error = saved_u_error;
1147+
}
1148+
11341149
/*
11351150
* Cannot rely on __kernel_[u]long_t being defined,
11361151
* it is quite a recent feature of <asm/posix_types.h>.

0 commit comments

Comments
 (0)