From: Lazar Trsic Date: Fri, 14 Jul 2017 09:31:03 +0000 (+0200) Subject: Move is_negated_errno() to new header negated_errno.h X-Git-Tag: v4.19~264 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72aba2be327c3a9035435b79c7d4051285a5ce48;p=strace Move is_negated_errno() to new header negated_errno.h Move is_negated_errno() to a separate new header file negated_errno.h and include it just for architectures which require it. is_negated_errno() is not used on those architectures that have a dedicated register to signal a syscall error. The issue was raised when compiling with clang, which is more strict regarding semantics of unused static inline functions defined in C files and will issue a -Wunused-function warrning if they are not used anywhere. * syscall.c (is_negated_errno): Move to ... * negated_errno.h: ... new file. * Makefile.am (strace_SOURCES): Add it. * linux/aarch64/get_error.c: Include it. * linux/arc/get_error.c: Likewise. * linux/arm/get_error.c: Likewise. * linux/avr32/get_error.c: Likewise. * linux/bfin/get_error.c: Likewise. * linux/crisv10/get_error.c: Likewise. * linux/hppa/get_error.c: Likewise. * linux/i386/get_error.c: Likewise. * linux/ia64/get_error.c: Likewise. * linux/m68k/get_error.c: Likewise. * linux/metag/get_error.c: Likewise. * linux/microblaze/get_error.c: Likewise. * linux/or1k/get_error.c: Likewise. * linux/riscv/get_error.c: Likewise. * linux/s390/get_error.c: Likewise. * linux/sh/get_error.c: Likewise. * linux/sh64/get_error.c: Likewise. * linux/tile/get_error.c: Likewise. * linux/x86_64/get_error.c: Likewise. * linux/xtensa/get_error.c: Likewise. --- diff --git a/Makefile.am b/Makefile.am index 05c2475a..2517c0d4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -179,6 +179,7 @@ strace_SOURCES = \ msghdr.h \ mtd.c \ native_defs.h \ + negated_errno.h \ net.c \ netlink.c \ netlink.h \ diff --git a/linux/aarch64/get_error.c b/linux/aarch64/get_error.c index a3aa1272..b3287a0d 100644 --- a/linux/aarch64/get_error.c +++ b/linux/aarch64/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + #define get_error arm_get_error #include "arm/get_error.c" #undef get_error diff --git a/linux/arc/get_error.c b/linux/arc/get_error.c index e19debc1..39b5d1c0 100644 --- a/linux/arc/get_error.c +++ b/linux/arc/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/arm/get_error.c b/linux/arm/get_error.c index fa81dd76..02d7e65d 100644 --- a/linux/arm/get_error.c +++ b/linux/arm/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/avr32/get_error.c b/linux/avr32/get_error.c index 75e7f67f..b53c8f6c 100644 --- a/linux/avr32/get_error.c +++ b/linux/avr32/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/bfin/get_error.c b/linux/bfin/get_error.c index 80aeb377..76e4099d 100644 --- a/linux/bfin/get_error.c +++ b/linux/bfin/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/crisv10/get_error.c b/linux/crisv10/get_error.c index b9da923f..2c81f1b7 100644 --- a/linux/crisv10/get_error.c +++ b/linux/crisv10/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/hppa/get_error.c b/linux/hppa/get_error.c index a2a7c0ea..8b23f305 100644 --- a/linux/hppa/get_error.c +++ b/linux/hppa/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/i386/get_error.c b/linux/i386/get_error.c index 1f63605e..9e0be03e 100644 --- a/linux/i386/get_error.c +++ b/linux/i386/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/ia64/get_error.c b/linux/ia64/get_error.c index 52daa7f4..41cae92e 100644 --- a/linux/ia64/get_error.c +++ b/linux/ia64/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/m68k/get_error.c b/linux/m68k/get_error.c index 3ad51a08..edd69cfc 100644 --- a/linux/m68k/get_error.c +++ b/linux/m68k/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/metag/get_error.c b/linux/metag/get_error.c index b7d287f9..5415b39b 100644 --- a/linux/metag/get_error.c +++ b/linux/metag/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/microblaze/get_error.c b/linux/microblaze/get_error.c index 878e24f6..1da69c0e 100644 --- a/linux/microblaze/get_error.c +++ b/linux/microblaze/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/or1k/get_error.c b/linux/or1k/get_error.c index 40e00bf4..f6a32713 100644 --- a/linux/or1k/get_error.c +++ b/linux/or1k/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/riscv/get_error.c b/linux/riscv/get_error.c index be640d0a..2b2594fc 100644 --- a/linux/riscv/get_error.c +++ b/linux/riscv/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/s390/get_error.c b/linux/s390/get_error.c index f491962d..6d4d0a5e 100644 --- a/linux/s390/get_error.c +++ b/linux/s390/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/sh/get_error.c b/linux/sh/get_error.c index 158ff9e6..0bb6fc50 100644 --- a/linux/sh/get_error.c +++ b/linux/sh/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/sh64/get_error.c b/linux/sh64/get_error.c index 7858df7c..0a9001d8 100644 --- a/linux/sh64/get_error.c +++ b/linux/sh64/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/tile/get_error.c b/linux/tile/get_error.c index 9949af4f..1f007bad 100644 --- a/linux/tile/get_error.c +++ b/linux/tile/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/x86_64/get_error.c b/linux/x86_64/get_error.c index 9411625b..440fdc74 100644 --- a/linux/x86_64/get_error.c +++ b/linux/x86_64/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/linux/xtensa/get_error.c b/linux/xtensa/get_error.c index 51ccd3b8..f49cc467 100644 --- a/linux/xtensa/get_error.c +++ b/linux/xtensa/get_error.c @@ -1,3 +1,5 @@ +#include "negated_errno.h" + static void get_error(struct tcb *tcp, const bool check_errno) { diff --git a/negated_errno.h b/negated_errno.h new file mode 100644 index 00000000..9ec851b0 --- /dev/null +++ b/negated_errno.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015-2017 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef STRACE_NEGATED_ERRNO_H +#define STRACE_NEGATED_ERRNO_H + +/* + * Check the syscall return value register value for whether it is + * a negated errno code indicating an error, or a success return value. + */ +static inline bool +is_negated_errno(kernel_ulong_t val) +{ + /* Linux kernel defines MAX_ERRNO to 4095. */ + kernel_ulong_t max = -(kernel_long_t) 4095; + +#ifndef current_klongsize + if (current_klongsize < sizeof(val)) { + val = (uint32_t) val; + max = (uint32_t) max; + } +#endif /* !current_klongsize */ + + return val >= max; +} + +#endif /* !STRACE_NEGATED_ERRNO_H */ diff --git a/syscall.c b/syscall.c index 02626c73..f21a1467 100644 --- a/syscall.c +++ b/syscall.c @@ -1047,26 +1047,6 @@ restore_cleared_syserror(struct tcb *tcp) tcp->u_error = saved_u_error; } -/* - * Check the syscall return value register value for whether it is - * a negated errno code indicating an error, or a success return value. - */ -static inline bool -is_negated_errno(kernel_ulong_t val) -{ - /* Linux kernel defines MAX_ERRNO to 4095. */ - kernel_ulong_t max = -(kernel_long_t) 4095; - -#ifndef current_klongsize - if (current_klongsize < sizeof(val)) { - val = (uint32_t) val; - max = (uint32_t) max; - } -#endif /* !current_klongsize */ - - return val >= max; -} - #include "arch_regs.c" #ifdef HAVE_GETRVAL2