blob: f02158e71ada5f11097c85d2c0bb851137071e63 [file] [log] [blame]
Dmitry V. Levinb5d25ec2014-12-06 03:53:16 +00001#include "defs.h"
2
3#include "xlat/whence_codes.h"
4
5/* Linux kernel has exactly one version of lseek:
6 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
7 * In kernel, off_t is always the same as (kernel's) long
8 * (see include/uapi/asm-generic/posix_types.h),
9 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
10 * Use test/x32_lseek.c to test lseek decoding.
11 */
12#if defined(LINUX_MIPSN32) || defined(X32)
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000013SYS_FUNC(lseek)
Dmitry V. Levinb5d25ec2014-12-06 03:53:16 +000014{
15 long long offset;
16 int whence;
17
Dmitry V. Levined88a502015-07-19 23:58:13 +000018 printfd(tcp, tcp->u_arg[0]);
19 offset = tcp->ext_arg[1];
20 whence = tcp->u_arg[2];
21 if (whence == SEEK_SET)
22 tprintf(", %llu, ", offset);
23 else
24 tprintf(", %lld, ", offset);
25 printxval(whence_codes, whence, "SEEK_???");
26
27 return RVAL_DECODED | RVAL_LUDECIMAL;
Dmitry V. Levinb5d25ec2014-12-06 03:53:16 +000028}
29#else
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000030SYS_FUNC(lseek)
Dmitry V. Levinb5d25ec2014-12-06 03:53:16 +000031{
32 long offset;
33 int whence;
34
Dmitry V. Levined88a502015-07-19 23:58:13 +000035 printfd(tcp, tcp->u_arg[0]);
36 offset = tcp->u_arg[1];
37 whence = tcp->u_arg[2];
38 if (whence == SEEK_SET)
39 tprintf(", %lu, ", offset);
40 else
41 tprintf(", %ld, ", offset);
42 printxval(whence_codes, whence, "SEEK_???");
43
44 return RVAL_DECODED | RVAL_UDECIMAL;
Dmitry V. Levinb5d25ec2014-12-06 03:53:16 +000045}
46#endif
47
48/* llseek syscall takes explicitly two ulong arguments hi, lo,
49 * rather than one 64-bit argument for which LONG_LONG works
50 * appropriate for the native byte order.
51 *
52 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
53 *
54 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
55 * ((loff_t) hi << 32) | lo
56 * Note that for architectures with kernel's long wider than userspace long
57 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
58 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
59 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
60 */
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000061SYS_FUNC(llseek)
Dmitry V. Levinb5d25ec2014-12-06 03:53:16 +000062{
63 if (entering(tcp)) {
64 printfd(tcp, tcp->u_arg[0]);
65 if (tcp->u_arg[4] == SEEK_SET)
66 tprintf(", %llu, ",
67 ((long long) tcp->u_arg[1]) << 32 |
68 (unsigned long long) (unsigned) tcp->u_arg[2]);
69 else
70 tprintf(", %lld, ",
71 ((long long) tcp->u_arg[1]) << 32 |
72 (unsigned long long) (unsigned) tcp->u_arg[2]);
Dmitry V. Levin7db808d2015-07-19 23:55:25 +000073 } else {
74 printnum_int64(tcp, tcp->u_arg[3], "%" PRIu64);
75 tprints(", ");
Dmitry V. Levinb5d25ec2014-12-06 03:53:16 +000076 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
77 }
78 return 0;
79}