]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: set errno in raw_clone() on sparc
authorMike Gilbert <floppym@gentoo.org>
Thu, 31 May 2018 03:06:33 +0000 (23:06 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Jun 2018 07:48:19 +0000 (09:48 +0200)
sparc sets the carry bit when a syscall fails. Use this information to
set errno and return -1 as appropriate.

The added test case calls raw_clone() with flags known to be invalid
according to the clone(2) manpage.

src/basic/raw-clone.h
src/test/test-util.c

index d35540903ab30ec44de10ad1e7070d3d0f722f80..6505e5a3cd1475f5e1a9d284d4e57f2d0a0b9162 100644 (file)
@@ -8,6 +8,7 @@
   Copyright 2016 Michael Karcher
 ***/
 
+#include <errno.h>
 #include <sched.h>
 #include <sys/syscall.h>
 
@@ -47,23 +48,28 @@ static inline pid_t raw_clone(unsigned long flags) {
                  * %o1. Inline assembly is needed to get the flag returned
                  * in %o1.
                  */
-                int in_child, child_pid;
+                int in_child, child_pid, error;
 
-                asm volatile("mov %2, %%g1\n\t"
-                             "mov %3, %%o0\n\t"
+                asm volatile("mov %3, %%g1\n\t"
+                             "mov %4, %%o0\n\t"
                              "mov 0 , %%o1\n\t"
 #if defined(__arch64__)
                              "t 0x6d\n\t"
 #else
                              "t 0x10\n\t"
 #endif
+                             "addx %%g0, 0, %2\n\t"
                              "mov %%o1, %0\n\t"
                              "mov %%o0, %1" :
-                             "=r"(in_child), "=r"(child_pid) :
+                             "=r"(in_child), "=r"(child_pid), "=r"(error) :
                              "i"(__NR_clone), "r"(flags) :
-                             "%o1", "%o0", "%g1" );
+                             "%o1", "%o0", "%g1" "cc" );
 
-                ret = in_child ? 0 : child_pid;
+                if (error) {
+                        errno = child_pid;
+                        ret = -1;
+                } else
+                        ret = in_child ? 0 : child_pid;
         }
 #else
         ret = (pid_t) syscall(__NR_clone, flags, NULL);
index 92d2c776904d67be242222e2eb70e4cdf53d488d..af0ada7d2a243ac02ce13277def8217aeb712514 100644 (file)
@@ -214,6 +214,10 @@ static void test_raw_clone(void) {
                 waitpid(pid, &status, __WCLONE);
                 assert_se(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
         }
+
+        errno = 0;
+        assert_se(raw_clone(CLONE_FS|CLONE_NEWNS) == -1);
+        assert_se(errno == EINVAL);
 }
 
 static void test_physical_memory(void) {