1 // Test program which explores whether lseek syscall (not llseek!)
2 // on x32 uses 64-bit offset argument.
3 // IOW: does _kernel_ truncate it on entry?
4 // The answer appears to be "no, full 64-bit offset is used".
5 // strace must show it correctly too - tricky if strace itself is x32 one!
7 // Build: x86_64-gcc -static -Wall -ox32_lseek x32_lseek.c
8 // Run: $ strace ./x32_lseek 2>&1 | grep lseek | grep 1250999896321
9 // lseek(0, 1250999896321, SEEK_SET) = 1250999896321
11 #include <sys/types.h>
18 #include <sys/syscall.h>
19 // Ensure we are compiling to 64 bits
20 struct bug { int t[sizeof(long) > 4 ? 1 : -1]; };
21 int main(int argc, char **argv)
23 long ofs = 0x12345678901;
26 if (open("/etc/passwd", O_RDONLY))
29 (long) (__NR_lseek | 0x40000000), // make x32 call
34 printf("pos:%ld(0x%lx) errno:%m\n", r, r);
36 printf((r == ofs) ? "64-bit offset used\n" : "Kernel truncated offset\n");