From: Dmitry V. Levin Date: Mon, 15 Feb 2016 18:30:02 +0000 (+0000) Subject: Print offsets in lseek and _llseek syscalls as signed integers X-Git-Tag: v4.12~541 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddbede5d9c452c076a46e9096fe5ed1921d1d008;p=strace Print offsets in lseek and _llseek syscalls as signed integers * lseek.c (SYS_FUNC(lseek)): Print offset using %lld format. (SYS_FUNC(llseek)): Likewise. Treat high and low components of offset as unsigned long integers. * tests/llseek.c (main): Check that negative offset is printed properly. * tests/lseek.c (main): Likewise. --- diff --git a/lseek.c b/lseek.c index fe4b695c..cfc6b586 100644 --- a/lseek.c +++ b/lseek.c @@ -7,7 +7,7 @@ * Copyright (c) 2009 Andreas Schwab * Copyright (c) 2012 H.J. Lu * Copyright (c) 2013 Denys Vlasenko - * Copyright (c) 2014-2015 Dmitry V. Levin + * Copyright (c) 2014-2016 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,10 +47,9 @@ #if defined(LINUX_MIPSN32) || defined(X32) SYS_FUNC(lseek) { - long long offset; - int whence; - printfd(tcp, tcp->u_arg[0]); + + long long offset; # ifdef X32 /* tcp->ext_arg is not initialized for i386 personality */ if (current_personality == 1) @@ -58,11 +57,9 @@ SYS_FUNC(lseek) else # endif offset = tcp->ext_arg[1]; - whence = tcp->u_arg[2]; - if (whence == SEEK_SET) - tprintf(", %llu, ", offset); - else - tprintf(", %lld, ", offset); + int whence = tcp->u_arg[2]; + + tprintf(", %lld, ", offset); printxval(whence_codes, whence, "SEEK_???"); return RVAL_DECODED | RVAL_LUDECIMAL; @@ -70,16 +67,23 @@ SYS_FUNC(lseek) #else SYS_FUNC(lseek) { - long offset; - int whence; - 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); + + long offset = +# if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 +# ifdef X86_64 + current_personality == 1 ? + (long)(int) tcp->u_arg[1] : tcp->u_arg[1]; +# else + current_wordsize == 4 ? + (long)(int) tcp->u_arg[1] : tcp->u_arg[1]; +# endif +# else + tcp->u_arg[1]; +# endif + int whence = tcp->u_arg[2]; + + tprintf(", %ld, ", offset); printxval(whence_codes, whence, "SEEK_???"); return RVAL_DECODED | RVAL_UDECIMAL; @@ -103,14 +107,9 @@ SYS_FUNC(llseek) { if (entering(tcp)) { printfd(tcp, tcp->u_arg[0]); - if (tcp->u_arg[4] == SEEK_SET) - tprintf(", %llu, ", - ((long long) tcp->u_arg[1]) << 32 | - (unsigned long long) (unsigned) tcp->u_arg[2]); - else - tprintf(", %lld, ", - ((long long) tcp->u_arg[1]) << 32 | - (unsigned long long) (unsigned) tcp->u_arg[2]); + tprintf(", %lld, ", + ((unsigned long long) (unsigned long) tcp->u_arg[1]) << 32 + | (unsigned long long) (unsigned long) tcp->u_arg[2]); } else { printnum_int64(tcp, tcp->u_arg[3], "%" PRIu64); tprints(", "); diff --git a/tests/llseek.c b/tests/llseek.c index a9d1914a..2f691711 100644 --- a/tests/llseek.c +++ b/tests/llseek.c @@ -38,16 +38,16 @@ int main(void) { - const unsigned long high = 0xdefaced; + const unsigned long high = 0xfacefeed; const unsigned long low = 0xdeadbeef; - const unsigned long long offset = 0xdefaceddeadbeef; + const long long offset = 0xfacefeeddeadbeefLL; unsigned long long result; assert(syscall(__NR__llseek, -1, high, low, &result, SEEK_SET) == -1); if (EBADF != errno) perror_msg_and_skip("_llseek"); - printf("_llseek(-1, %llu, %p, SEEK_SET) = -1 EBADF (%m)\n", + printf("_llseek(-1, %lld, %p, SEEK_SET) = -1 EBADF (%m)\n", offset, &result); puts("+++ exited with 0 +++"); diff --git a/tests/lseek.c b/tests/lseek.c index 9dcf0cad..227c4e30 100644 --- a/tests/lseek.c +++ b/tests/lseek.c @@ -39,7 +39,7 @@ int main(void) { - const kernel_ulong_t offset = (kernel_ulong_t) 0xdefaced0badc0deULL; + const kernel_ulong_t offset = (kernel_ulong_t) 0xfacefeeddeadbeefULL; if (sizeof(offset) > sizeof(long)) assert(lseek(-1, offset, SEEK_SET) == -1); @@ -49,8 +49,12 @@ main(void) if (EBADF != errno) perror_msg_and_skip("lseek"); - printf("lseek(-1, %llu, SEEK_SET) = -1 EBADF (%m)\n", - (unsigned long long) offset); + if (sizeof(offset) > sizeof(long)) + printf("lseek(-1, %lld, SEEK_SET) = -1 EBADF (%m)\n", + (long long) offset); + else + printf("lseek(-1, %ld, SEEK_SET) = -1 EBADF (%m)\n", + (long) offset); puts("+++ exited with 0 +++"); return 0;