This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC PATCH] Test for syscall templates


The patch [1] fixes the bug in (not public available yet) aarc64/ilp32 port
in SYSCALL_ERROR_HANDLER() macro - wrong calculation of errno location. The
macro is called in error path of a syscall generated from syscall templates
with PSEUDO* machinery.

The bug has been discovered during the work on LTP tests, and it looks like
there's no a glibc test to check it. For sure, there's no specific test for 
syscall templates.

The following test sets the errno to invalid value (0xdead), and then calls
write() with intentionally wrong file descriptor to force kernel to return
EBADF which should be stored at errno location by SYSCALL_ERROR_HANDLER().

The test is failed before and passed after [1] for aarch64/ilp32 [2-3].

This is RFC because I'm not sure this is right way to check the macro
as it implicitly assumes that the write() is implemented with templates,
which may be wrong for some platform, or will become wrong in future.

Though, if the test is OK, please apply it.

[1] https://sourceware.org/ml/libc-alpha/2017-02/msg00110.html
[2] https://github.com/norov/glibc/tree/dev9
[3] https://github.com/norov/linux/tree/ilp32-20170203

	* sysdeps/unix/sysv/linux/Makefile: Enable new test tst-syscall-template.
	* sysdeps/unix/sysv/linux/tst-syscall-template.c: New test.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 sysdeps/unix/sysv/linux/Makefile               |  2 +-
 sysdeps/unix/sysv/linux/tst-syscall-template.c | 55 ++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/tst-syscall-template.c

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index b3d6866..8c4cfd0 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -43,7 +43,7 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \
 		  bits/mman-linux.h
 
 tests += tst-clone tst-clone2 tst-fanotify tst-personality tst-quota \
-	 tst-sync_file_range
+	 tst-sync_file_range tst-syscall-template
 
 # Generate the list of SYS_* macros for the system calls (__NR_* macros).
 
diff --git a/sysdeps/unix/sysv/linux/tst-syscall-template.c b/sysdeps/unix/sysv/linux/tst-syscall-template.c
new file mode 100644
index 0000000..47e47d0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-syscall-template.c
@@ -0,0 +1,55 @@
+/* Basic tests for syscall template errno setup.
+
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+
+static int do_test (void);
+#define TEST_FUNCTION           do_test ()
+
+/* This defines the `main' function and some more.  */
+#include <test-skeleton.c>
+
+static int
+do_test (void)
+{
+  const char str[] = "Hello wold!\n";
+  int err;
+
+  errno = 0xDEAD;
+
+  if (errno != 0xDEAD)
+    FAIL_EXIT1 ("Cannot access errno location");
+
+  /* Write at intectionally invalid file descriptor.
+     Function should return -1, and set errno to EBADF.  */
+  err = write (-1, str, sizeof (str));
+
+  if (err != -1)
+     FAIL_EXIT1 ("Unexpected write success");
+
+  if (errno == 0xDEAD)
+     FAIL_EXIT1 ("Errno is not updated");
+
+  if (errno != EBADF)
+     FAIL_EXIT1 ("Wrong error code: %d", errno);
+
+  return 0;
+}
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]