[PATCH] Move is_negated_errno() to new header negated_errno.h

Miodrag Dinic miodrag.dinic at rt-rk.com
Fri Jul 14 09:31:03 UTC 2017


From: Lazar Trsic <Lazar.Trsic at imgtec.com>

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.
---
 linux/aarch64/get_error.c    |  2 ++
 linux/arc/get_error.c        |  2 ++
 linux/arm/get_error.c        |  2 ++
 linux/avr32/get_error.c      |  2 ++
 linux/bfin/get_error.c       |  2 ++
 linux/crisv10/get_error.c    |  2 ++
 linux/hppa/get_error.c       |  2 ++
 linux/i386/get_error.c       |  2 ++
 linux/ia64/get_error.c       |  2 ++
 linux/m68k/get_error.c       |  2 ++
 linux/metag/get_error.c      |  2 ++
 linux/microblaze/get_error.c |  2 ++
 linux/or1k/get_error.c       |  2 ++
 linux/riscv/get_error.c      |  2 ++
 linux/s390/get_error.c       |  2 ++
 linux/sh/get_error.c         |  2 ++
 linux/sh64/get_error.c       |  2 ++
 linux/tile/get_error.c       |  2 ++
 linux/x86_64/get_error.c     |  2 ++
 linux/xtensa/get_error.c     |  2 ++
 negated_errno.h              | 51 ++++++++++++++++++++++++++++++++++++++++++++
 syscall.c                    | 20 -----------------
 22 files changed, 91 insertions(+), 20 deletions(-)
 create mode 100644 negated_errno.h

diff --git a/linux/aarch64/get_error.c b/linux/aarch64/get_error.c
index a3aa127..b3287a0 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 e19debc..39b5d1c 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 fa81dd7..02d7e65 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 75e7f67..b53c8f6 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 80aeb37..76e4099 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 b9da923..2c81f1b 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 a2a7c0e..8b23f30 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 1f63605..9e0be03 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 52daa7f..41cae92 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 3ad51a0..edd69cf 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 b7d287f..5415b39 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 878e24f..1da69c0 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 40e00bf..f6a3271 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 be640d0..2b2594f 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 f491962..6d4d0a5 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 158ff9e..0bb6fc5 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 7858df7..0a9001d 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 9949af4..1f007ba 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 9411625..440fdc7 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 51ccd3b..f49cc46 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 0000000..6387c9c
--- /dev/null
+++ b/negated_errno.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2017 Dmitry V. Levin <ldv at 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 NEGATED_ERRNO_H
+#define 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 /* !NEGATED_ERRNO_H */
diff --git a/syscall.c b/syscall.c
index 02626c7..f21a146 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
-- 
1.9.1





More information about the Strace-devel mailing list