[compiler-rt] [sanitizer_common][PowerPC64] Fix internal_clone() error handling (PR #99908)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 10:50:18 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Ilya Leoshkevich (iii-i)

<details>
<summary>Changes</summary>

Return -1 on error and set errno, which is what internal_iserror() expects. Currently a non-negated errno is returned, and errno is not set.

---
Full diff: https://github.com/llvm/llvm-project/pull/99908.diff


1 Files Affected:

- (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp (+11-2) 


``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 47f9f0c4590fb..cd13cbdef3f71 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -1601,8 +1601,8 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
       "sc\n\t"
 
       /* Test if syscall was successful */
+      "bso-   0f\n\t"
       "cmpdi  cr1, 3, 0\n\t"
-      "crandc cr1*4+eq, cr1*4+eq, cr0*4+so\n\t"
       "bne-   cr1, 1f\n\t"
 
       /* Set up stack frame */
@@ -1630,13 +1630,22 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
       "sc\n\t"
 
       /* Return to parent */
+      "0:\n\t"
+      "neg %0,3\n\t"
+      "b 2f\n\t"
       "1:\n\t"
-      "mr %0, 3\n\t"
+      "mr %0,3\n\t"
+      "2:\n\t"
+
       : "=r"(res)
       : "0"(-1), "i"(EINVAL), "i"(__NR_clone), "i"(__NR_exit), "r"(__fn),
         "r"(__cstack), "r"(__flags), "r"(__arg), "r"(__ptidptr), "r"(__newtls),
         "r"(__ctidptr), "i"(FRAME_SIZE), "i"(FRAME_TOC_SAVE_OFFSET)
       : "cr0", "cr1", "memory", "ctr", "r0", "r27", "r28", "r29");
+  if ((uptr)res >= (uptr)-4095) {
+    errno = -res;
+    res = -1;
+  }
   return res;
 }
 #    elif defined(__i386__)

``````````

</details>


https://github.com/llvm/llvm-project/pull/99908


More information about the llvm-commits mailing list