void mono_threads_core_abort_syscall (MonoThreadInfo *info) { kern_return_t ret; do { ret = thread_suspend (info->native_handle); } while (ret == KERN_ABORTED); if (ret != KERN_SUCCESS) return; do { ret = thread_abort_safely (info->native_handle); } while (ret == KERN_ABORTED); /* * We are doing thread_abort when thread_abort_safely returns KERN_SUCCESS because * for some reason accept is not interrupted by thread_abort_safely. * The risk of aborting non-atomic operations while calling thread_abort should not * exist because by the time thread_abort_safely returns KERN_SUCCESS the target * thread should have return from the kernel and should be waiting for thread_resume * to resume the user code. */ if (ret == KERN_SUCCESS) ret = thread_abort (info->native_handle); do { ret = thread_resume (info->native_handle); } while (ret == KERN_ABORTED); g_assert (ret == KERN_SUCCESS); }
int __cdecl ThreadPThread__SuspendThread (m3_pthread_t mt) { kern_return_t status = { 0 }; mach_port_t mach_thread = PTHREAD_FROM_M3(mt); status = thread_suspend(mach_thread); if (status != KERN_SUCCESS) { fprintf(stderr, "thread_suspend returned %d instead of %d\n", (int)status, (int)KERN_SUCCESS); return 0; } status = thread_abort_safely(mach_thread); if (status != KERN_SUCCESS) { fprintf(stderr, "thread_abort_safely returned %d instead of %d\n", (int)status, (int)KERN_SUCCESS); status = thread_resume(mach_thread); if (status != KERN_SUCCESS) { fprintf(stderr, "thread_resume returned %d instead of %d\n", (int)status, (int)KERN_SUCCESS); abort(); } return 0; } return 1; }
int SuspendThread (pthread_t t) { mach_port_t mach_thread = pthread_mach_thread_np(t); if (thread_suspend(mach_thread) != KERN_SUCCESS) return 0; if (thread_abort_safely(mach_thread) != KERN_SUCCESS) { kern_return_t status = thread_resume(mach_thread); assert(status == KERN_SUCCESS); return 0; } return 1; }