[PATCH] D19159: [sanitizer] [SystemZ] Implement internal_clone.

Marcin Koƛcielnicki via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 03:47:14 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL267547: [sanitizer] [SystemZ] Implement internal_clone. (authored by koriakin).

Changed prior to commit:
  http://reviews.llvm.org/D19159?vs=53938&id=54990#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19159

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_s390.cc

Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
@@ -44,7 +44,7 @@
 int internal_sigaction_norestorer(int signum, const void *act, void *oldact);
 void internal_sigdelset(__sanitizer_sigset_t *set, int signum);
 #if defined(__x86_64__) || defined(__mips__) || defined(__aarch64__) \
-  || defined(__powerpc64__)
+  || defined(__powerpc64__) || defined(__s390__)
 uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
                     int *parent_tidptr, void *newtls, int *child_tidptr);
 #endif
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_s390.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_s390.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_s390.cc
@@ -18,6 +18,7 @@
 
 #include "sanitizer_linux.h"
 
+#include <errno.h>
 #include <sys/syscall.h>
 #include <unistd.h>
 
@@ -52,6 +53,67 @@
 # endif
 }
 
+uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
+                    int *parent_tidptr, void *newtls, int *child_tidptr) {
+  if (!fn || !child_stack)
+    return -EINVAL;
+  CHECK_EQ(0, (uptr)child_stack % 16);
+  // Minimum frame size.
+#ifdef __s390x__
+  child_stack = (char *)child_stack - 160;
+#else
+  child_stack = (char *)child_stack - 96;
+#endif
+  // Terminate unwind chain.
+  ((unsigned long *)child_stack)[0] = 0;
+  // And pass parameters.
+  ((unsigned long *)child_stack)[1] = (uptr)fn;
+  ((unsigned long *)child_stack)[2] = (uptr)arg;
+  register long res __asm__("r2");
+  register void *__cstack      __asm__("r2") = child_stack;
+  register int __flags         __asm__("r3") = flags;
+  register int * __ptidptr     __asm__("r4") = parent_tidptr;
+  register int * __ctidptr     __asm__("r5") = child_tidptr;
+  register void * __newtls     __asm__("r6") = newtls;
+
+  __asm__ __volatile__(
+                       /* Clone. */
+                       "svc    %1\n"
+
+                       /* if (%r2 != 0)
+                        *   return;
+                        */
+#ifdef __s390x__
+                       "cghi   %%r2, 0\n"
+#else
+                       "chi    %%r2, 0\n"
+#endif
+                       "jne    1f\n"
+
+                       /* Call "fn(arg)". */
+#ifdef __s390x__
+                       "lmg    %%r1, %%r2, 8(%%r15)\n"
+#else
+                       "lm     %%r1, %%r2, 4(%%r15)\n"
+#endif
+                       "basr   %%r14, %%r1\n"
+
+                       /* Call _exit(%r2). */
+                       "svc %2\n"
+
+                       /* Return to parent. */
+                     "1:\n"
+                       : "=r" (res)
+                       : "i"(__NR_clone), "i"(__NR_exit),
+                         "r"(__cstack),
+                         "r"(__flags),
+                         "r"(__ptidptr),
+                         "r"(__ctidptr),
+                         "r"(__newtls)
+                       : "memory", "cc");
+  return res;
+}
+
 } // namespace __sanitizer
 
 #endif // SANITIZER_LINUX && SANITIZER_S390


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19159.54990.patch
Type: text/x-patch
Size: 3289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160426/628559fe/attachment.bin>


More information about the llvm-commits mailing list