chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / basic / raw-clone.h
index 8c95380305cd502dbc847130c66e08a03b1dad4e..7cf86aaf0db28f1c10bdaf65f74f57e0da923951 100644 (file)
@@ -2,24 +2,11 @@
 #pragma once
 
 /***
-  This file is part of systemd.
-
   Copyright 2010 Lennart Poettering
   Copyright 2016 Michael Karcher
-  systemd 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.
-
-  systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+//#include <errno.h>
 #include <sched.h>
 #include <sys/syscall.h>
 
@@ -51,27 +38,36 @@ static inline pid_t raw_clone(unsigned long flags) {
         /* On s390/s390x and cris the order of the first and second arguments
          * of the raw clone() system call is reversed. */
         ret = (pid_t) syscall(__NR_clone, NULL, flags);
-#elif defined(__sparc__) && defined(__arch64__)
+#elif defined(__sparc__)
         {
                 /**
-                 * sparc64 always returns the other process id in %o0, and
+                 * sparc always returns the other process id in %o0, and
                  * a boolean flag whether this is the child or the parent in
                  * %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);