]> granicus.if.org Git - strace/commitdiff
Remove wrong x32-specific lseek
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 17 Feb 2013 12:17:49 +0000 (13:17 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 17 Feb 2013 12:17:49 +0000 (13:17 +0100)
Testing confirmed what I suspected: x32 lseek uses kernel-sized
(i.e. wide) long for offset parameter.

* file.c: Delete sys_lseek32.
* linux/syscall.h: Likewise.
* linux/x32/syscallent1.h: Likewise.
* test/x32_lseek.c: New file.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
file.c
linux/syscall.h
linux/x32/syscallent1.h
test/x32_lseek.c [new file with mode: 0644]

diff --git a/file.c b/file.c
index 3a98674c5f597a02f8ccaa5b0805d0585629a612..e5354487d1fd4f1af3d1d1f80709b0abfaf784d6 100644 (file)
--- a/file.c
+++ b/file.c
@@ -528,6 +528,7 @@ static const struct xlat whence_codes[] = {
  * In kernel, off_t is always the same as (kernel's) long
  * (see include/uapi/asm-generic/posix_types.h),
  * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
+ * Use test/x32_lseek.c to test lseek decoding.
  */
 #if defined(LINUX_MIPSN32) || defined(X32)
 int
@@ -548,27 +549,6 @@ sys_lseek(struct tcb *tcp)
        }
        return RVAL_LUDECIMAL;
 }
-
-# if defined(X32)
-int
-sys_lseek32(struct tcb *tcp)
-{
-       long offset;
-       int whence;
-
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               offset = tcp->u_arg[1];
-               whence = tcp->u_arg[2];
-               if (whence == SEEK_SET)
-                       tprintf(", %lu, ", offset);
-               else
-                       tprintf(", %ld, ", offset);
-               printxval(whence_codes, whence, "SEEK_???");
-       }
-       return RVAL_UDECIMAL;
-}
-# endif
 #else
 int
 sys_lseek(struct tcb *tcp)
@@ -598,9 +578,9 @@ sys_lseek(struct tcb *tcp)
  *
  * hi,lo are "unsigned longs" and combined exactly this way in kernel:
  * ((loff_t) hi << 32) | lo
- * Note that for architectures with kernel's long wider than userspace longs
+ * Note that for architectures with kernel's long wider than userspace long
  * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
- * for hi and lo. You may need to use tcp->ext_arg[N]!
+ * for hi and lo. We may need to use tcp->ext_arg[N]!
  */
 int
 sys_llseek(struct tcb *tcp)
index c0f955b977c9f14706b8b289776d14918cc73e04..010756498d199ef95d2e2b7507590dc3a3004555 100644 (file)
@@ -373,7 +373,3 @@ int sys_shmsys();
 #define SYS_shmsys_subcall     207
 #define SYS_shmsys_nsubcalls   4
 #endif
-
-#ifdef X32
-int sys_lseek32();
-#endif
index 20c65292c6ad291af337597e03bd625f3b07756c..e58372ee39f2856ed6dc199a2683a0be218716a5 100644 (file)
@@ -4,7 +4,6 @@
 #define sys_oldstat printargs
 #define sys_oldfstat printargs
 #define sys_oldlstat printargs
-#define sys_lseek sys_lseek32
 #define sys_lstat64 sys_stat64
 #define sys_truncate64 sys_truncate
 #define sys_ftruncate64 sys_ftruncate
diff --git a/test/x32_lseek.c b/test/x32_lseek.c
new file mode 100644 (file)
index 0000000..6faa2fa
--- /dev/null
@@ -0,0 +1,38 @@
+// Test program which explores whether lseek syscall (not llseek!)
+// on x32 uses 64-bit offset argument.
+// IOW: does _kernel_ truncate it on entry?
+// The answer appears to be "no, full 64-bit offset is used".
+// strace must show it correctly too - tricky if strace itself is x32 one!
+//
+// Build: x86_64-gcc -static -Wall -ox32_lseek x32_lseek.c
+// Run:   $ strace ./x32_lseek 2>&1 | grep lseek | grep 1250999896321
+//        lseek(0, 1250999896321, SEEK_SET) = 1250999896321
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+// Ensure we are compiling to 64 bits
+struct bug { int t[sizeof(long) > 4 ? 1 : -1]; };
+int main(int argc, char **argv)
+{
+       long ofs = 0x12345678901;
+       errno = 0;
+       close(0);
+       if (open("/etc/passwd", O_RDONLY))
+               return 1;
+       long r = syscall(
+               (long) (__NR_lseek | 0x40000000), // make x32 call
+               (long) (0),
+               (long) (ofs),
+               (long) (SEEK_SET)
+       );
+       printf("pos:%ld(0x%lx) errno:%m\n", r, r);
+       if (!errno)
+               printf((r == ofs) ? "64-bit offset used\n" : "Kernel truncated offset\n");
+       return 0;
+}