diff mbox series

[1/2] tools/nolibc: s390: provide custom implementation for sys_fork

Message ID 20230415-nolibc-fork-v1-1-9747c73651c5@weissschuh.net (mailing list archive)
State New
Headers show
Series tools/nolibc: fork: fix on s390 and add test | expand

Commit Message

Thomas Weißschuh April 15, 2023, 9:28 p.m. UTC
On s390 the first two arguments to the clone() syscall are swapped,
as documented in clone(2).

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/arch-s390.h | 8 ++++++++
 tools/include/nolibc/sys.h       | 2 ++
 2 files changed, 10 insertions(+)

Comments

Sven Schnelle May 9, 2023, 7:53 a.m. UTC | #1
Thomas Weißschuh <linux@weissschuh.net> writes:

> On s390 the first two arguments to the clone() syscall are swapped,
> as documented in clone(2).
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  tools/include/nolibc/arch-s390.h | 8 ++++++++
>  tools/include/nolibc/sys.h       | 2 ++
>  2 files changed, 10 insertions(+)

Acked-by: Sven Schnelle <svens@linux.ibm.com>
diff mbox series

Patch

diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s390.h
index 6b0e54ed543d..db4ea51a4dbb 100644
--- a/tools/include/nolibc/arch-s390.h
+++ b/tools/include/nolibc/arch-s390.h
@@ -5,6 +5,7 @@ 
 
 #ifndef _NOLIBC_ARCH_S390_H
 #define _NOLIBC_ARCH_S390_H
+#include <asm/signal.h>
 #include <asm/unistd.h>
 
 /* The struct returned by the stat() syscall, equivalent to stat64(). The
@@ -223,4 +224,11 @@  void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
 	return (void *)my_syscall1(__NR_mmap, &args);
 }
 #define sys_mmap sys_mmap
+
+static __attribute__((unused))
+pid_t sys_fork(void)
+{
+	return my_syscall5(__NR_clone, 0, SIGCHLD, 0, 0, 0);
+}
+#define sys_fork sys_fork
 #endif // _NOLIBC_ARCH_S390_H
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index bea9760dbd16..f5a450153a63 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -336,6 +336,7 @@  void exit(int status)
  * pid_t fork(void);
  */
 
+#ifndef sys_fork
 static __attribute__((unused))
 pid_t sys_fork(void)
 {
@@ -351,6 +352,7 @@  pid_t sys_fork(void)
 #error Neither __NR_clone nor __NR_fork defined, cannot implement sys_fork()
 #endif
 }
+#endif
 
 static __attribute__((unused))
 pid_t fork(void)