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

Ilya Leoshkevich via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 10:49:46 PDT 2024


https://github.com/iii-i created https://github.com/llvm/llvm-project/pull/99908

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.

>From 3dd938e0919d6fdd65292fab4fc80cbed33ffe23 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii at linux.ibm.com>
Date: Mon, 22 Jul 2024 18:48:07 +0200
Subject: [PATCH] [sanitizer_common][PowerPC64] Fix internal_clone() error
 handling

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.
---
 .../lib/sanitizer_common/sanitizer_linux.cpp        | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

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__)



More information about the llvm-commits mailing list