[compiler-rt] [compiler-rt] intercept ptrace for *BSD. (PR #78044)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 13 07:49:01 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 8d817f6479a5df874028a8b40fd30aecd3479005 d796f5592ab936b3637dd997b02119d6727349e9 -- compiler-rt/test/sanitizer_common/TestCases/FreeBSD/ptrace.cpp compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index da2ffff246..b0c6c94950 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -10265,27 +10265,31 @@ INTERCEPTOR(int, ptrace, int request, pid_t pid, uptr addr, int data) {
 
   if (request == ptrace_pt_io) {
     // for PT_IO requests, data is ignored for both platforms
-    COMMON_INTERCEPTOR_READ_RANGE(ctx, reinterpret_cast<void *>(addr), struct_ptrace_ptrace_io_desc_struct_sz);
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, reinterpret_cast<void *>(addr),
+                                  struct_ptrace_ptrace_io_desc_struct_sz);
   } else if (request == ptrace_pt_lwpstatus) {
     if (struct_ptrace_ptrace_lwpinfo_struct_sz != static_cast<u64>(data))
       VPrintf(2, "Invalid data argument %d for request %d\n", data, request);
-    COMMON_INTERCEPTOR_READ_RANGE(ctx, reinterpret_cast<void *>(addr), struct_ptrace_ptrace_lwpinfo_struct_sz);
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, reinterpret_cast<void *>(addr),
+                                  struct_ptrace_ptrace_lwpinfo_struct_sz);
   }
 
   int res = REAL(ptrace)(request, pid, addr, data);
 
   if (!res) {
     if (request == ptrace_pt_io) {
-      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, reinterpret_cast<void *>(addr), struct_ptrace_ptrace_io_desc_struct_sz);
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, reinterpret_cast<void *>(addr),
+                                     struct_ptrace_ptrace_io_desc_struct_sz);
     } else if (request == ptrace_pt_lwpstatus) {
-      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, reinterpret_cast<void *>(addr), struct_ptrace_ptrace_lwpinfo_struct_sz);
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, reinterpret_cast<void *>(addr),
+                                     struct_ptrace_ptrace_lwpinfo_struct_sz);
     }
   }
   return res;
 }
-#define INIT_PTRACE_BSD COMMON_INTERCEPT_FUNCTION(ptrace);
+#  define INIT_PTRACE_BSD COMMON_INTERCEPT_FUNCTION(ptrace);
 #else
-#define INIT_PTRACE_BSD
+#  define INIT_PTRACE_BSD
 #endif
 
 #include "sanitizer_common_interceptors_netbsd_compat.inc"
diff --git a/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/ptrace.cpp b/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/ptrace.cpp
index 2638c39631..c3ecb57b98 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/ptrace.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/ptrace.cpp
@@ -1,27 +1,27 @@
 // RUN: %clangxx -O0 %s -o %t && %run %t
 
 #include <assert.h>
-#include <sys/types.h>
+#include <stdlib.h>
 #include <sys/ptrace.h>
+#include <sys/types.h>
 #include <sys/wait.h>
-#include <stdlib.h>
 #include <unistd.h>
 
 int main() {
-	pid_t pid;
-	ptrace_lwpinfo pl;
+  pid_t pid;
+  ptrace_lwpinfo pl;
 
-	if ((pid = fork()) == 0) {
-    		execl("/bin/true", "true", NULL);
-		exit(-1);
-	}
-	assert(pid != -1);
-	waitpid(pid, NULL, 0);
-	auto r = ptrace(PT_ATTACH, pid, NULL, 0);
-	assert(!r);
-	waitpid(pid, NULL, 0);
-	r = ptrace(PT_LWPINFO, pid, reinterpret_cast<caddr_t>(&pl), sizeof(pl));
-	assert(!r);
-	r = ptrace(PT_DETACH, pid, NULL, 0);
-	return 0;
+  if ((pid = fork()) == 0) {
+    execl("/bin/true", "true", NULL);
+    exit(-1);
+  }
+  assert(pid != -1);
+  waitpid(pid, NULL, 0);
+  auto r = ptrace(PT_ATTACH, pid, NULL, 0);
+  assert(!r);
+  waitpid(pid, NULL, 0);
+  r = ptrace(PT_LWPINFO, pid, reinterpret_cast<caddr_t>(&pl), sizeof(pl));
+  assert(!r);
+  r = ptrace(PT_DETACH, pid, NULL, 0);
+  return 0;
 }

``````````

</details>


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


More information about the llvm-commits mailing list