Skip to contentSkip to conversation

Automatically generate syscalls.h

PATCH Superseded Andrea Cervesato 4 participants 16 messages Oct 31, 2024

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover Automatically generate syscalls.h

The problem we have at the moment is that all syscalls input files must be changed by hand each time we need to test a new syscall. The idea is to simplify this process, providing a script that is able to read from kernel sources and to generate all syscalls files we need.

This patch set adds a new command inside the syscalls folder and it refactors the previous regen.sh code.
The new way we have to generate the syscalls.h file is the following:

include/lapi/syscalls/generate_arch.sh path/to/kernel/source
include/lapi/syscalls/generate_syscalls.sh path/to/syscalls.h

Scripts are independent and they can be run separately. generate_syscalls.sh is the equivalent of regen.sh, but its code has been cleaned up.

---
Changes in v6:
- aesthetic changes in the syscall generator
- fix fallback definitions in the syscalls.h file generator
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- license SPDX inside scripts files
- quote shell variables inside scripts
- some generic code cleanup
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- remove blacklist file
- update syscalls files
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- fix generate_arch.sh to work properly for all architectures
- rename some arch .in files and handle renaming inside
generate_syscalls.sh using the right gcc directives
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- refactor regen.sh
- split syscalls.h and syscalls .in files creation
- updated syscalls .in files
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrea Cervesato (3):
Refactor regen.sh script to generate syscalls Add script to generate arch(s) dependant syscalls Delete obsolete strip_syscall.awk file

 configure.ac                                       |   2 +-
 include/lapi/syscalls/{aarch64.in => arm64.in}     |   0
 include/lapi/syscalls/generate_arch.sh             | 211 +++++++++++++++++++++
 include/lapi/syscalls/generate_syscalls.sh         | 111 +++++++++++
 .../lapi/syscalls/{loongarch.in => loongarch64.in} |   0
 include/lapi/syscalls/{mips_n64.in => mips64.in}   |   0
 .../lapi/syscalls/{mips_n32.in => mips64n32.in}    |   0
 include/lapi/syscalls/{mips_o32.in => mipso32.in}  |   0
 include/lapi/syscalls/{hppa.in => parisc.in}       |   0
 include/lapi/syscalls/regen.sh                     | 129 -------------
 include/lapi/syscalls/strip_syscall.awk            |  19 --
 .../lapi/syscalls/{order => supported-arch.txt}    |  12 +-
 12 files changed, 329 insertions(+), 155 deletions(-)

---
base-commit: 34e6dd2d233abcebae435d34d793b6a49d08c190
change-id: 20240923-generate_syscalls-780dc2227bdb

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v6 1/3 Refactor regen.sh script to generate syscalls

From: Andrea Cervesato <[email protected]>

Rename regen.sh into a more meaningful generate_syscalls.sh name, rename order into a more meaningful supported-syscalls.txt name and rewrite part of the regen.sh script code in order to execute it from anywhere in the filesystem, without need to be in its own folder. The new code is also more clear and concise, using native sh features which are simplifying the code.

---
 configure.ac                                       |   2 +-
 include/lapi/syscalls/generate_syscalls.sh         | 111 ++++++++++++++++++
 include/lapi/syscalls/regen.sh                     | 129 ---------------------
 .../lapi/syscalls/{order => supported-arch.txt}    |   0
 4 files changed, 112 insertions(+), 130 deletions(-)
configure.ac +1 -1
index d327974efa71f263d7f7f5aec9d2c5831d53dd0e..cd1233d19fad376973fc880d6689859845613fb0 100644
@@ -386,7 +386,7 @@ else
     AC_SUBST([WITH_REALTIME_TESTSUITE],["no"])
 fi
 
-AC_CONFIG_COMMANDS([syscalls.h], [cd ${ac_top_srcdir}/include/lapi/syscalls; ./regen.sh; cd - >/dev/null])
+AC_CONFIG_COMMANDS([syscalls.h], [cd ${ac_top_srcdir}/include/lapi/syscalls; ./generate_syscalls.sh ../syscalls.h; cd - >/dev/null])
 
 # custom functions
 # NOTE: don't create custom functions for simple checks, put them into this file
include/lapi/syscalls/generate_syscalls.sh new file +111 -0

111 lines not on this page · raw message

include/lapi/syscalls/regen.sh deleted +0 -129

129 lines not on this page · raw message

include/lapi/syscalls/supported-arch.txt renamed from include/lapi/syscalls/order +0 -0
similarity index 100%
rename from include/lapi/syscalls/order
rename to include/lapi/syscalls/supported-arch.txt
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

Hi Andrea,

whole patchset LGTM, thank you!

I was comparing the old include/lapi/syscalls.h (21579 lines) and the new one (20054). Having new file shorter is a bit surprising to me. I haven't found what is missing, probably I'm missing something myself :).

Quoted 6 lines

Rename regen.sh into a more meaningful generate_syscalls.sh name, rename order into a more meaningful supported-syscalls.txt name and rewrite part of the regen.sh script code in order to execute it from anywhere in the filesystem, without need to be in its own folder. The new code is also more clear and concise, using native sh features which are simplifying the code.

Purely out of curiosity (nothing to block this), which "native sh features"?

Quoted 1 line

+++ b/include/lapi/syscalls/generate_syscalls.sh

...

include/lapi/syscalls/generate_syscalls.sh line 21

Quoted 5 lines
include/lapi/syscalls/generate_syscalls.sh new file +5 -0
+SCRIPT_DIR="$(realpath $(dirname "$0"))"
+SUPPORTED_ARCH="${SCRIPT_DIR}/supported-arch.txt"
+
+echo '
+// SPDX-License-Identifier: GPL-2.0-or-later

very nit stylish: This produce new line. Why not just:

echo '// SPDX-License-Identifier: GPL-2.0-or-later /************************************************

Feel free to ignore or amend before push.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

Hi!

Quoted 3 lines

I was comparing the old include/lapi/syscalls.h (21579 lines) and the new one (20054). Having new file shorter is a bit surprising to me. I haven't found what is missing, probably I'm missing something myself :).

That is strange, I got exactly same content minus some whitespaces and slightly different macros that check for arch support:

syscalls.h 2024-10-31 11:23:38.326891830 +0100 renamed from syscalls.h.old 2024-10-31 11:17:04.840217056 +0100 +20 -20
@@ -1,3 +1,5 @@
+
+// SPDX-License-Identifier: GPL-2.0-or-later
 /************************************************
  * GENERATED FILE: DO NOT EDIT/PATCH THIS FILE  *
  *  change your arch specific .in file instead  *
@@ -6,8 +8,6 @@
 /*
  * Here we stick all the ugly *fallback* logic for linux
  * system call numbers (those __NR_ thingies).
- *
- * Licensed under the GPLv2 or later, see the COPYING file.
  */
 
 #ifndef LAPI_SYSCALLS_H__
@@ -19,30 +19,30 @@
 
 #ifdef TST_TEST_H__
 #define TST_SYSCALL_BRK__(NR, SNR) ({ \
-       tst_brk(TCONF, \
-               "syscall(%d) " SNR " not supported on your arch", NR); \
+tst_brk(TCONF, \
+       "syscall(%d) " SNR " not supported on your arch", NR); \
 })
 #else
 inline static void dummy_cleanup(void) {}
 
 #define TST_SYSCALL_BRK__(NR, SNR) ({ \
-       tst_brkm(TCONF, dummy_cleanup, \
-               "syscall(%d) " SNR " not supported on your arch", NR); \
+tst_brkm(TCONF, dummy_cleanup, \
+       "syscall(%d) " SNR " not supported on your arch", NR); \
 })
 #endif
 
 #define tst_syscall(NR, ...) ({ \
-       intptr_t tst_ret; \
-       if (NR == __LTP__NR_INVALID_SYSCALL) { \
-               errno = ENOSYS; \
-               tst_ret = -1; \
-       } else { \
-               tst_ret = syscall(NR, ##__VA_ARGS__); \
-       } \
-       if (tst_ret == -1 && errno == ENOSYS) { \
-               TST_SYSCALL_BRK__(NR, #NR); \
-       } \
-       tst_ret; \
+intptr_t tst_ret; \
+if (NR == __LTP__NR_INVALID_SYSCALL) { \
+       errno = ENOSYS; \
+       tst_ret = -1; \
+} else { \
+       tst_ret = syscall(NR, ##__VA_ARGS__); \
+} \
+if (tst_ret == -1 && errno == ENOSYS) { \
+       TST_SYSCALL_BRK__(NR, #NR); \
+} \
+tst_ret; \
 })
 
 #define __LTP__NR_INVALID_SYSCALL -1
@@ -6681,7 +6681,7 @@
 #endif
 
 
-#if defined(__mips__) && defined(_ABIN32)
+#ifdef __mips_n32__
 # ifndef __NR_read
 #  define __NR_read 6000
 # endif
@@ -7828,7 +7828,7 @@
 #endif
 
 
-#if defined(__mips__) && defined(_ABI64)
+#ifdef __mips_n64__
 # ifndef __NR_read
 #  define __NR_read 5000
 # endif
@@ -8903,7 +8903,7 @@
 #endif
 
 
-#if defined(__mips__) && defined(_ABIO32) && _MIPS_SZLONG == 32
+#ifdef __mips_o32__
 # ifndef __NR_syscall
 #  define __NR_syscall 4000
 # endif
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

Hi,

Quoted 71 lines · Cyril Hrubis

Hi!

Quoted 3 lines

I was comparing the old include/lapi/syscalls.h (21579 lines) and the new one (20054). Having new file shorter is a bit surprising to me. I haven't found what is missing, probably I'm missing something myself :).

That is strange, I got exactly same content minus some whitespaces and slightly different macros that check for arch support:

syscalls.h 2024-10-31 11:23:38.326891830 +0100 renamed from syscalls.h.old 2024-10-31 11:17:04.840217056 +0100 +17 -17
@@ -1,3 +1,5 @@
+
+// SPDX-License-Identifier: GPL-2.0-or-later
  /************************************************
   * GENERATED FILE: DO NOT EDIT/PATCH THIS FILE  *
   *  change your arch specific .in file instead  *
@@ -6,8 +8,6 @@
  /*
   * Here we stick all the ugly *fallback* logic for linux
   * system call numbers (those __NR_ thingies).
- *
- * Licensed under the GPLv2 or later, see the COPYING file.
   */
 
  #ifndef LAPI_SYSCALLS_H__
@@ -19,30 +19,30 @@
 
  #ifdef TST_TEST_H__
  #define TST_SYSCALL_BRK__(NR, SNR) ({ \
-       tst_brk(TCONF, \
-               "syscall(%d) " SNR " not supported on your arch", NR); \
+tst_brk(TCONF, \
+       "syscall(%d) " SNR " not supported on your arch", NR); \
  })
  #else
  inline static void dummy_cleanup(void) {}
 
  #define TST_SYSCALL_BRK__(NR, SNR) ({ \
-       tst_brkm(TCONF, dummy_cleanup, \
-               "syscall(%d) " SNR " not supported on your arch", NR); \
+tst_brkm(TCONF, dummy_cleanup, \
+       "syscall(%d) " SNR " not supported on your arch", NR); \
  })
  #endif
 
  #define tst_syscall(NR, ...) ({ \
-       intptr_t tst_ret; \
-       if (NR == __LTP__NR_INVALID_SYSCALL) { \
-               errno = ENOSYS; \
-               tst_ret = -1; \
-       } else { \
-               tst_ret = syscall(NR, ##__VA_ARGS__); \
-       } \
-       if (tst_ret == -1 && errno == ENOSYS) { \
-               TST_SYSCALL_BRK__(NR, #NR); \
-       } \
-       tst_ret; \
+intptr_t tst_ret; \
+if (NR == __LTP__NR_INVALID_SYSCALL) { \
+       errno = ENOSYS; \
+       tst_ret = -1; \
+} else { \
+       tst_ret = syscall(NR, ##__VA_ARGS__); \
+} \
+if (tst_ret == -1 && errno == ENOSYS) { \
+       TST_SYSCALL_BRK__(NR, #NR); \
+} \
+tst_ret; \
  })
 
  #define __LTP__NR_INVALID_SYSCALL -1

syscalls.h 2024-10-31 11:23:38.326891830 +0100 line 6684

Quoted 5 lines
syscalls.h 2024-10-31 11:23:38.326891830 +0100 renamed from syscalls.h.old 2024-10-31 11:17:04.840217056 +0100 +1 -1
@@ -6681,7 +6681,7 @@
  #endif
 
 
-#if defined(__mips__) && defined(_ABIN32)
+#ifdef __mips_n32__

Do you believe these lines are an error? I'm checking the code and it seems fine.

Quoted 14 lines
syscalls.h 2024-10-31 11:23:38.326891830 +0100 renamed from syscalls.h.old 2024-10-31 11:17:04.840217056 +0100 +1 -1
  # ifndef __NR_read
  #  define __NR_read 6000
  # endif
@@ -7828,7 +7828,7 @@
  #endif
 
 
-#if defined(__mips__) && defined(_ABI64)
+#ifdef __mips_n64__
  # ifndef __NR_read
  #  define __NR_read 5000
  # endif

syscalls.h 2024-10-31 11:23:38.326891830 +0100 line 8909

Quoted 8 lines
syscalls.h 2024-10-31 11:23:38.326891830 +0100 renamed from syscalls.h.old 2024-10-31 11:17:04.840217056 +0100 +1 -1
@@ -8903,7 +8903,7 @@
  #endif
 
 
-#if defined(__mips__) && defined(_ABIO32) && _MIPS_SZLONG == 32
+#ifdef __mips_o32__
  # ifndef __NR_syscall
  #  define __NR_syscall 4000
  # endif

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

Hi!

Quoted 4 lines

syscalls.h 2024-10-31 11:23:38.326891830 +0100 line 6684

Quoted 2 lines
syscalls.h 2024-10-31 11:23:38.326891830 +0100 renamed from syscalls.h.old 2024-10-31 11:17:04.840217056 +0100 +1 -1
-#if defined(__mips__) && defined(_ABIN32)
+#ifdef __mips_n32__

Do you believe these lines are an error? I'm checking the code and it seems fine.

I guess that these are mostly equivalent, there may be a special cases where the are not though. I guess that Peter can check with the buildroot folks, they probably know which one is more correct.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

In reply to Cyril Hrubis
Quoted 90 lines · Cyril Hrubis

Hi!

Quoted 3 lines

I was comparing the old include/lapi/syscalls.h (21579 lines) and the new one (20054). Having new file shorter is a bit surprising to me. I haven't found what is missing, probably I'm missing something myself :).

That is strange, I got exactly same content minus some whitespaces and slightly different macros that check for arch support:

syscalls.h 2024-10-31 11:23:38.326891830 +0100 renamed from syscalls.h.old 2024-10-31 11:17:04.840217056 +0100 +19 -19
@@ -1,3 +1,5 @@
+
+// SPDX-License-Identifier: GPL-2.0-or-later
  /************************************************
   * GENERATED FILE: DO NOT EDIT/PATCH THIS FILE  *
   *  change your arch specific .in file instead  *
@@ -6,8 +8,6 @@
  /*
   * Here we stick all the ugly *fallback* logic for linux
   * system call numbers (those __NR_ thingies).
- *
- * Licensed under the GPLv2 or later, see the COPYING file.
   */
 
  #ifndef LAPI_SYSCALLS_H__
@@ -19,30 +19,30 @@
 
  #ifdef TST_TEST_H__
  #define TST_SYSCALL_BRK__(NR, SNR) ({ \
-       tst_brk(TCONF, \
-               "syscall(%d) " SNR " not supported on your arch", NR); \
+tst_brk(TCONF, \
+       "syscall(%d) " SNR " not supported on your arch", NR); \
  })
  #else
  inline static void dummy_cleanup(void) {}
 
  #define TST_SYSCALL_BRK__(NR, SNR) ({ \
-       tst_brkm(TCONF, dummy_cleanup, \
-               "syscall(%d) " SNR " not supported on your arch", NR); \
+tst_brkm(TCONF, dummy_cleanup, \
+       "syscall(%d) " SNR " not supported on your arch", NR); \
  })
  #endif
 
  #define tst_syscall(NR, ...) ({ \
-       intptr_t tst_ret; \
-       if (NR == __LTP__NR_INVALID_SYSCALL) { \
-               errno = ENOSYS; \
-               tst_ret = -1; \
-       } else { \
-               tst_ret = syscall(NR, ##__VA_ARGS__); \
-       } \
-       if (tst_ret == -1 && errno == ENOSYS) { \
-               TST_SYSCALL_BRK__(NR, #NR); \
-       } \
-       tst_ret; \
+intptr_t tst_ret; \
+if (NR == __LTP__NR_INVALID_SYSCALL) { \
+       errno = ENOSYS; \
+       tst_ret = -1; \
+} else { \
+       tst_ret = syscall(NR, ##__VA_ARGS__); \
+} \
+if (tst_ret == -1 && errno == ENOSYS) { \
+       TST_SYSCALL_BRK__(NR, #NR); \
+} \
+tst_ret; \
  })
 
  #define __LTP__NR_INVALID_SYSCALL -1
@@ -6681,7 +6681,7 @@
  #endif
 
 
-#if defined(__mips__) && defined(_ABIN32)
+#ifdef __mips_n32__
  # ifndef __NR_read
  #  define __NR_read 6000
  # endif
@@ -7828,7 +7828,7 @@
  #endif
 
 
-#if defined(__mips__) && defined(_ABI64)
+#ifdef __mips_n64__
  # ifndef __NR_read
  #  define __NR_read 5000
  # endif

syscalls.h 2024-10-31 11:23:38.326891830 +0100 line 8909

Quoted 8 lines
syscalls.h 2024-10-31 11:23:38.326891830 +0100 renamed from syscalls.h.old 2024-10-31 11:17:04.840217056 +0100 +1 -1
@@ -8903,7 +8903,7 @@
  #endif
 
 
-#if defined(__mips__) && defined(_ABIO32) && _MIPS_SZLONG == 32
+#ifdef __mips_o32__
  # ifndef __NR_syscall
  #  define __NR_syscall 4000
  # endif

I just realized that these are errors. The reason is that files are changed now, so I need to change the way architecture is seen at compile time. For example, mips64n32 is now mips_n32 and that has to be handled in the syscalls file generator.

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

In reply to Cyril Hrubis
Quoted 7 lines

Hi!

Quoted 3 lines

I was comparing the old include/lapi/syscalls.h (21579 lines) and the new one (20054). Having new file shorter is a bit surprising to me. I haven't found what is missing, probably I'm missing something myself :).

That is strange, I got exactly same content minus some whitespaces and slightly different macros that check for arch support:

Hm, that must be on my side than. I was doing that on old version, but even with update to the current master and deleting all:

rm -rf *; git reset --hard; make autotools && ./configure

I still get:

21579 for master (84e77afb3a)
20054 for v6.

Because diff is big, I posted: diff [1], old master [2], new v6 [3]

Now I see the reason - what I pushed as Anrea's v6 [4] is broken for many distros [5].

Reason for the failure itself is quite obvious [6]:

414 ../include/lapi/syscalls.h:13:2: error: unterminated conditional directive 415 #ifndef LAPI_SYSCALLS_H__
416 ^
417 1 error generated.

Looking it's broken on Debian any version I suspect include/lapi/syscalls/generate_syscalls.sh works differently on dash. But it works on ash. Maybe it's not a shell syntax but some dependency.

I suppose include/lapi/syscalls/generate_syscalls.sh should use:
#!/bin/sh -eux
instead of plain #!/bin/sh, that will show the error immediately. (set -eu is useful for shell scripts which should not fail).

Kind regards,
Petr

[1] https://github.com/pevik/ltp/wiki/diff-master-and-v6
[2] https://github.com/pevik/ltp/wiki/syscalls.h-old-master-(84e77afb3a)
[3] https://github.com/pevik/ltp/wiki/syscalls.h-v6-(new)
[4] https://github.com/pevik/ltp/tree/refs/heads/andrea/automatically-generate-syscalls.h.v6
[5] https://github.com/pevik/ltp/actions/runs/11609439723
[6] https://github.com/pevik/ltp/actions/runs/11609439723/job/32326686364

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

Hi!

Quoted 3 lines

Looking it's broken on Debian any version I suspect include/lapi/syscalls/generate_syscalls.sh works differently on dash. But it works on ash. Maybe it's not a shell syntax but some dependency.

That is strange, I checked with dash here as well, no differencies. But I did so only for the generate_syscalls.sh script. If you tested the whole patchset together it's the code that generates the *.in files that differs.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 3 lines

Looking it's broken on Debian any version I suspect include/lapi/syscalls/generate_syscalls.sh works differently on dash. But it works on ash. Maybe it's not a shell syntax but some dependency.

That is strange, I checked with dash here as well, no differencies. But I did so only for the generate_syscalls.sh script. If you tested the whole patchset together it's the code that generates the *.in files that differs.

Yes it's strange. Check v7 which introduces /bin/sh -eux. The CI passes without issues: https://github.com/acerv/ltp/actions/runs/11611080151

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

In reply to Andrea Cervesato

Hi!

Quoted 1 line

+echo '

^
This adds an empty line to the start of the file.

Quoted 74 lines
include/lapi/syscalls/generate_syscalls.sh new file +74 -0
+// SPDX-License-Identifier: GPL-2.0-or-later
+/************************************************
+ * GENERATED FILE: DO NOT EDIT/PATCH THIS FILE  *
+ *  change your arch specific .in file instead  *
+ ************************************************/
+
+/*
+ * Here we stick all the ugly *fallback* logic for linux
+ * system call numbers (those __NR_ thingies).
+ */
+
+#ifndef LAPI_SYSCALLS_H__
+#define LAPI_SYSCALLS_H__
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <asm/unistd.h>
+
+#ifdef TST_TEST_H__
+#define TST_SYSCALL_BRK__(NR, SNR) ({ \
+tst_brk(TCONF, \
+	"syscall(%d) " SNR " not supported on your arch", NR); \
+})
+#else
+inline static void dummy_cleanup(void) {}
+
+#define TST_SYSCALL_BRK__(NR, SNR) ({ \
+tst_brkm(TCONF, dummy_cleanup, \
+	"syscall(%d) " SNR " not supported on your arch", NR); \
+})
+#endif
+
+#define tst_syscall(NR, ...) ({ \
+intptr_t tst_ret; \
+if (NR == __LTP__NR_INVALID_SYSCALL) { \
+	errno = ENOSYS; \
+	tst_ret = -1; \
+} else { \
+	tst_ret = syscall(NR, ##__VA_ARGS__); \
+} \
+if (tst_ret == -1 && errno == ENOSYS) { \
+	TST_SYSCALL_BRK__(NR, #NR); \
+} \
+tst_ret; \
+})
+
+#define __LTP__NR_INVALID_SYSCALL -1' >${SYSCALLS_FILE}
+
+while IFS= read -r arch; do
+	(
+		echo
+		case ${arch} in
+		sparc64) echo "#if defined(__sparc__) && defined(__arch64__)" ;;
+		sparc) echo "#if defined(__sparc__) && !defined(__arch64__)" ;;
+		s390) echo "#if defined(__s390__) && !defined(__s390x__)" ;;
+		mips64n32) echo "#if defined(__mips__) && defined(_ABIN32)" ;;
+		mips64) echo "#if defined(__mips__) && defined(_ABI64)" ;;
+		mipso32) echo "#if defined(__mips__) && defined(_ABIO32) && _MIPS_SZLONG == 32" ;;
+		parisc) echo "#ifdef __hppa__" ;;
+		loongarch64) echo "#ifdef __loongarch__" ;;
+		arm64) echo "#ifdef __aarch64__" ;;
+		*) echo "#ifdef __${arch}__" ;;
+		esac
+
+		while read -r line; do
+			set -- ${line}
+			syscall_nr="__NR_$1"
+			shift
+
+			echo "# ifndef ${syscall_nr}"
+			echo "#  define ${syscall_nr} $*"
+			echo "# endif"
+		done <"${SCRIPT_DIR}/${arch}.in"
+		echo "#endif"

include/lapi/syscalls/generate_syscalls.sh line 104

Quoted 10 lines
include/lapi/syscalls/generate_syscalls.sh new file +10 -0
+		echo
+	) >>${SYSCALLS_FILE}
+done <${SUPPORTED_ARCH}
+
+(
+	echo
+	echo "/* Common stubs */"
+	for num in $(awk '{print $1}' "${SCRIPT_DIR}/"*.in | sort -u); do
+		syscall_nr="__NR_${num}"
+		shift

This shift is not needed here anymore and generates a lot of warnings.

Quoted 6 lines
include/lapi/syscalls/generate_syscalls.sh new file +6 -0
+		echo "# ifndef ${syscall_nr}"
+		echo "#  define ${syscall_nr} __LTP__NR_INVALID_SYSCALL"
+		echo "# endif"
+	done
+	echo "#endif"
+) >>${SYSCALLS_FILE}
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by
#11 lore raw

Re: [LTP] [PATCH v6 1/3] Refactor regen.sh script to generate syscalls

Hi!
And besides these two issues I pointed out it seems to work fine and the code looks fine, so with these two fixed:

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

PATCH v6 2/3 Add script to generate arch(s) dependant syscalls

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Add generate_arch.sh script which can be used to generate arch(s) dependant syscalls file. The way it works is pretty simple: for each architecture defined into supported-arch.txt, compile kernel headers, extract the list of syscalls and generate a .in file containing all of them, associated with their own syscall's number.
The way syscalls files are generated, passes through a C application which is automatically checking the availability of the syscalls in the user space environment.

---
 include/lapi/syscalls/{aarch64.in => arm64.in}     |   0
 include/lapi/syscalls/generate_arch.sh             | 211 +++++++++++++++++++++
 .../lapi/syscalls/{loongarch.in => loongarch64.in} |   0
 include/lapi/syscalls/{mips_n64.in => mips64.in}   |   0
 .../lapi/syscalls/{mips_n32.in => mips64n32.in}    |   0
 include/lapi/syscalls/{mips_o32.in => mipso32.in}  |   0
 include/lapi/syscalls/{hppa.in => parisc.in}       |   0
 include/lapi/syscalls/supported-arch.txt           |  12 +-
 8 files changed, 217 insertions(+), 6 deletions(-)
include/lapi/syscalls/arm64.in renamed from include/lapi/syscalls/aarch64.in +0 -0
similarity index 100%
rename from include/lapi/syscalls/aarch64.in
rename to include/lapi/syscalls/arm64.in
include/lapi/syscalls/generate_arch.sh new file +211 -0

211 lines not on this page · raw message

include/lapi/syscalls/loongarch64.in renamed from include/lapi/syscalls/loongarch.in +0 -0
similarity index 100%
rename from include/lapi/syscalls/loongarch.in
rename to include/lapi/syscalls/loongarch64.in
include/lapi/syscalls/mips64.in renamed from include/lapi/syscalls/mips_n64.in +0 -0
similarity index 100%
rename from include/lapi/syscalls/mips_n64.in
rename to include/lapi/syscalls/mips64.in
include/lapi/syscalls/mips64n32.in renamed from include/lapi/syscalls/mips_n32.in +0 -0
similarity index 100%
rename from include/lapi/syscalls/mips_n32.in
rename to include/lapi/syscalls/mips64n32.in
include/lapi/syscalls/mipso32.in renamed from include/lapi/syscalls/mips_o32.in +0 -0
similarity index 100%
rename from include/lapi/syscalls/mips_o32.in
rename to include/lapi/syscalls/mipso32.in
include/lapi/syscalls/parisc.in renamed from include/lapi/syscalls/hppa.in +0 -0
similarity index 100%
rename from include/lapi/syscalls/hppa.in
rename to include/lapi/syscalls/parisc.in
include/lapi/syscalls/supported-arch.txt +6 -6
index c18aa38cf4546cdf3ac8c89a45bd1b202ffa7711..c5c5191ac08482d89f0a8c39dfae936538f58f7f 100644
@@ -1,13 +1,13 @@
-aarch64
 arc
+arm64
 arm
-hppa
 i386
 ia64
-loongarch
-mips_n32
-mips_n64
-mips_o32
+loongarch64
+mips64n32
+mips64
+mipso32
+parisc
 powerpc64
 powerpc
 s390x
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v6 3/3 Delete obsolete strip_syscall.awk file

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

---
 include/lapi/syscalls/strip_syscall.awk | 19 -------------------
 1 file changed, 19 deletions(-)
include/lapi/syscalls/strip_syscall.awk deleted +0 -19
deleted file mode 100755
index e8dff422e2667745c144ed984a4d66461fcce0c6..0000000000000000000000000000000000000000
@@ -1,19 +0,0 @@
-#!/usr/bin/awk -f
-#
-# Dumb script that can be used to strip all of the syscall information from
-# the arch-respective unistd*.h.
-#
-# Examples:
-#
-# 1. Grab the i386 32-bit syscalls from unistd_32.h and put them in i386.in
-# strip_syscall.awk arch/x86/include/asm/unistd_32.h > i386.in
-#
-
-/^#define[[:space:]]+__NR_[0-9a-z]+/ {
-
-	sub (/#define[[:space:]]+__NR_/, "", $0);
-	sub (/[[:space:]]*(\/\*.*)/, "", $0);
-	sub (/[[:space:]]+/, " ", $0);
-
-	print
-}
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw
In reply to Andrea Cervesato

Hi Andrea,

Quoted 9 lines

The problem we have at the moment is that all syscalls input files must be changed by hand each time we need to test a new syscall. The idea is to simplify this process, providing a script that is able to read from kernel sources and to generate all syscalls files we need.

This patch set adds a new command inside the syscalls folder and it refactors the previous regen.sh code.
The new way we have to generate the syscalls.h file is the following:

Quoted 6 lines

include/lapi/syscalls/generate_arch.sh path/to/kernel/source
include/lapi/syscalls/generate_syscalls.sh path/to/syscalls.h

Scripts are independent and they can be run separately. generate_syscalls.sh is the equivalent of regen.sh, but its code has been cleaned up.

it would be nice to have this documented (as a separate effort, not blocking to merge this). Specially the new generate_arch.sh, which is not part of ./configure run.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

Hi!

Quoted 12 lines
Quoted 11 lines

The problem we have at the moment is that all syscalls input files must be changed by hand each time we need to test a new syscall. The idea is to simplify this process, providing a script that is able to read from kernel sources and to generate all syscalls files we need.

This patch set adds a new command inside the syscalls folder and it refactors the previous regen.sh code.
The new way we have to generate the syscalls.h file is the following:

include/lapi/syscalls/generate_arch.sh path/to/kernel/source
include/lapi/syscalls/generate_syscalls.sh path/to/syscalls.h

Quoted 7 lines
Quoted 3 lines

Scripts are independent and they can be run separately. generate_syscalls.sh is the equivalent of regen.sh, but its code has been cleaned up.

it would be nice to have this documented (as a separate effort, not blocking to merge this). Specially the new generate_arch.sh, which is not part of ./configure run.

We need something as:

The generate_arch.sh is supposed to be run when you start writing new test and find out that the syscall number definitions you need are not available in the LTP fallback header include/syscalls.h. You need to point the script to a recent Linux kernel sources and it will pull an update for the LTP syscall number tables. The tables then needs to be updated in a separate git commit. You also need to re-run configure to get the header updated from the tables.

To be put into the "how to write a test" documentation.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp