From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:33 +0000 (-0700) Subject: Better Panic_BreakOnPanic implementation on macOS. X-Git-Tag: stable-10.2.0~270 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11094b0656ea13eff9b88cc207a4826f6ecd47b4;p=thirdparty%2Fopen-vm-tools.git Better Panic_BreakOnPanic implementation on macOS. There's actually a documented way to check whether a process is being debugged on macOS. This change updates panic lib to use it. --- diff --git a/open-vm-tools/lib/panic/panic.c b/open-vm-tools/lib/panic/panic.c index 5895a27b1..2a7b43533 100644 --- a/open-vm-tools/lib/panic/panic.c +++ b/open-vm-tools/lib/panic/panic.c @@ -32,6 +32,10 @@ #else // Posix # include # include +# ifdef __APPLE__ +# include +# include +# endif #endif // Win32 vs Posix #include "vmware.h" @@ -289,6 +293,11 @@ Panic_BreakOnPanic(void) Warning("Panic: breaking into debugger\n"); DebugBreak(); } +#elif defined(__APPLE__) + if (Panic_GetBreakOnPanic()) { + Warning("Panic: breaking into debugger\n"); + __asm__ __volatile__ ("int3"); + } #else // Posix switch (panicState.breakOnPanic) { case PanicBreakAction_Never: @@ -392,8 +401,25 @@ Panic_GetBreakOnPanic(void) case PanicBreakAction_Never: break; case PanicBreakAction_IfDebuggerAttached: -#ifdef _WIN32 +#if defined(_WIN32) shouldBreak = IsDebuggerPresent(); +#elif defined(__APPLE__) + { + /* + * https://developer.apple.com/library/content/qa/qa1361/ + */ + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; + struct kinfo_proc info; + size_t size; + int ret; + + info.kp_proc.p_flag = 0; + size = sizeof info; + ret = sysctl(mib, ARRAYSIZE(mib), &info, &size, NULL, 0); + if (ret == 0) { + shouldBreak = (info.kp_proc.p_flag & P_TRACED) != 0; + } + } #else /* * This case is handled by Panic_BreakOnPanic for Posix as there is no