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.
This commit is contained in:
Lazar Trsic 2017-07-14 11:31:03 +02:00 committed by Dmitry V. Levin
parent eb4467d09b
commit 72aba2be32
23 changed files with 92 additions and 20 deletions

View File

@ -179,6 +179,7 @@ strace_SOURCES = \
msghdr.h \
mtd.c \
native_defs.h \
negated_errno.h \
net.c \
netlink.c \
netlink.h \

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
#define get_error arm_get_error
#include "arm/get_error.c"
#undef get_error

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

View File

@ -1,3 +1,5 @@
#include "negated_errno.h"
static void
get_error(struct tcb *tcp, const bool check_errno)
{

51
negated_errno.h Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
* 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 */

View File

@ -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