[PATCH] D32189: Implement StopTheWorld for Darwin
Francis Ricci via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 14:21:07 PDT 2017
fjricci created this revision.
https://reviews.llvm.org/D32189
Files:
lib/lsan/lsan_common_mac.cc
lib/sanitizer_common/sanitizer_stoptheworld_mac.cc
Index: lib/sanitizer_common/sanitizer_stoptheworld_mac.cc
===================================================================
--- lib/sanitizer_common/sanitizer_stoptheworld_mac.cc
+++ lib/sanitizer_common/sanitizer_stoptheworld_mac.cc
@@ -17,6 +17,8 @@
defined(__i386))
#include <mach/mach.h>
+#include <mach/thread_info.h>
+#include <pthread.h>
#include "sanitizer_stoptheworld.h"
@@ -44,8 +46,56 @@
InternalMmapVector<SuspendedThreadInfo> threads_;
};
+struct RunThreadArgs {
+ StopTheWorldCallback callback;
+ void *argument;
+};
+
+void RunThread(void *arg) {
+ struct RunThreadArgs *run_args = (struct RunThreadArgs *) arg;
+ SuspendedThreadsListMac suspended_threads_list;
+
+ mach_port_t task;
+ kern_return_t err = task_for_pid(mach_task_self(), internal_getpid(), &task);
+ if (err != KERN_SUCCESS) {
+ VReport(1, "Getting task from pid failed (errno %d).\n", err);
+ return;
+ }
+
+ thread_array_t threads;
+ mach_msg_type_number_t num_threads;
+
+ err = task_threads(task, &threads, &num_threads);
+ if (err != KERN_SUCCESS) {
+ VReport(1, "Failed to get threads for task (errno %d).\n", err);
+ return;
+ }
+
+ for (unsigned int i = 0; i < num_threads; ++i) {
+ if (threads[i] == mach_thread_self() ||
+ suspended_threads_list.ContainsThread(threads[i])) {
+ continue;
+ }
+
+ thread_suspend(threads[i]);
+ suspended_threads_list.Append(threads[i]);
+ }
+
+ run_args->callback(suspended_threads_list, run_args->argument);
+
+ for (unsigned int i = 0; i < num_threads; ++i) {
+ if (threads[i] == mach_thread_self()) {
+ continue;
+ }
+
+ thread_resume(threads[i]);
+ }
+}
+
void StopTheWorld(StopTheWorldCallback callback, void *argument) {
- CHECK(0 && "unimplemented");
+ struct RunThreadArgs arg = { callback, argument };
+ pthread_t run_thread = (pthread_t) internal_start_thread(RunThread, &arg);
+ internal_join_thread(run_thread);
}
#if defined(__x86_64__)
Index: lib/lsan/lsan_common_mac.cc
===================================================================
--- lib/lsan/lsan_common_mac.cc
+++ lib/lsan/lsan_common_mac.cc
@@ -146,7 +146,7 @@
}
void DoStopTheWorld(StopTheWorldCallback callback, void *argument) {
- CHECK(0 && "unimplemented");
+ StopTheWorld(callback, argument);
}
} // namespace __lsan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32189.95629.patch
Type: text/x-patch
Size: 2349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170418/0a2c9d1f/attachment.bin>
More information about the llvm-commits
mailing list