Index: trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp	(revision 57074)
@@ -89,5 +89,7 @@
     {
 
+        IPRT_DARWIN_SAVE_EFL_AC();
         pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr));
+        IPRT_DARWIN_RESTORE_EFL_AC();
         if (RT_UNLIKELY(!pHdr))
         {
@@ -119,5 +121,9 @@
     }
     else
+    {
+        IPRT_DARWIN_SAVE_EFL_AC();
         IOFree(pHdr, pHdr->cb + sizeof(*pHdr));
+        IPRT_DARWIN_RESTORE_EFL_AC();
+    }
 }
 
@@ -131,4 +137,5 @@
     Assert(cb > 0);
     RT_ASSERT_PREEMPTIBLE();
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     /*
@@ -146,4 +153,5 @@
             {
                 *pPhys = PhysAddr;
+                IPRT_DARWIN_RESTORE_EFL_AC();
                 return pv;
             }
@@ -154,4 +162,6 @@
         IOFreeContiguous(pv, cb);
     }
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return NULL;
 }
@@ -165,7 +175,10 @@
         Assert(cb > 0);
         AssertMsg(!((uintptr_t)pv & PAGE_OFFSET_MASK), ("pv=%p\n", pv));
+        IPRT_DARWIN_SAVE_EFL_AC();
 
         cb = RT_ALIGN_Z(cb, PAGE_SIZE);
         IOFreeContiguous(pv, cb);
+
+        IPRT_DARWIN_RESTORE_EFL_AC();
     }
 }
Index: trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp	(revision 57074)
@@ -355,4 +355,5 @@
 {
     PRTR0MEMOBJDARWIN pMemDarwin = (PRTR0MEMOBJDARWIN)pMem;
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     /*
@@ -405,8 +406,10 @@
         case RTR0MEMOBJTYPE_PHYS_NC:
             AssertMsgFailed(("RTR0MEMOBJTYPE_PHYS_NC\n"));
+            IPRT_DARWIN_RESTORE_EFL_AC();
             return VERR_INTERNAL_ERROR;
 
         case RTR0MEMOBJTYPE_RES_VIRT:
             AssertMsgFailed(("RTR0MEMOBJTYPE_RES_VIRT\n"));
+            IPRT_DARWIN_RESTORE_EFL_AC();
             return VERR_INTERNAL_ERROR;
 
@@ -417,7 +420,9 @@
         default:
             AssertMsgFailed(("enmType=%d\n", pMemDarwin->Core.enmType));
+            IPRT_DARWIN_RESTORE_EFL_AC();
             return VERR_INTERNAL_ERROR;
     }
 
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return VINF_SUCCESS;
 }
@@ -610,6 +615,11 @@
 DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
 {
-    return rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, false /* fContiguous */,
-                                       0 /* PhysMask */, UINT64_MAX, RTR0MEMOBJTYPE_PAGE);
+    IPRT_DARWIN_SAVE_EFL_AC();
+
+    int rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, false /* fContiguous */,
+                                         0 /* PhysMask */, UINT64_MAX, RTR0MEMOBJTYPE_PAGE);
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
+    return rc;
 }
 
@@ -617,4 +627,6 @@
 DECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
 {
+    IPRT_DARWIN_SAVE_EFL_AC();
+
     /*
      * Try IOMallocPhysical/IOMallocAligned first.
@@ -629,4 +641,6 @@
         rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, false /* fContiguous */,
                                          0 /* PhysMask */, _4G - PAGE_SIZE, RTR0MEMOBJTYPE_LOW);
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return rc;
 }
@@ -635,4 +649,6 @@
 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
 {
+    IPRT_DARWIN_SAVE_EFL_AC();
+
     int rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, true /* fContiguous */,
                                          ~(uint32_t)PAGE_OFFSET_MASK, _4G - PAGE_SIZE,
@@ -647,4 +663,5 @@
                                          ~(uint32_t)PAGE_OFFSET_MASK, _4G - PAGE_SIZE,
                                          RTR0MEMOBJTYPE_CONT);
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return rc;
 }
@@ -656,4 +673,6 @@
     if (uAlignment != PAGE_SIZE)
         return VERR_NOT_SUPPORTED;
+
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     /*
@@ -676,4 +695,6 @@
                                          PhysMask, PhysHighest, RTR0MEMOBJTYPE_PHYS);
     }
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return rc;
 }
@@ -694,4 +715,5 @@
 {
     AssertReturn(uCachePolicy == RTMEM_CACHE_POLICY_DONT_CARE, VERR_NOT_SUPPORTED);
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     /*
@@ -725,4 +747,5 @@
                 pMemDarwin->pMemDesc = pMemDesc;
                 *ppMem = &pMemDarwin->Core;
+                IPRT_DARWIN_RESTORE_EFL_AC();
                 return VINF_SUCCESS;
             }
@@ -736,4 +759,5 @@
     else
         AssertMsgFailed(("%#llx %llx\n", (unsigned long long)Phys, (unsigned long long)cb));
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return rc;
 }
@@ -754,4 +778,5 @@
 static int rtR0MemObjNativeLock(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess, task_t Task)
 {
+    IPRT_DARWIN_SAVE_EFL_AC();
     NOREF(fAccess);
 #ifdef USE_VM_MAP_WIRE
@@ -778,4 +803,6 @@
             pMemDarwin->Core.u.Lock.R0Process = (RTR0PROCESS)Task;
             *ppMem = &pMemDarwin->Core;
+
+            IPRT_DARWIN_RESTORE_EFL_AC();
             return VINF_SUCCESS;
         }
@@ -807,4 +834,6 @@
                 pMemDarwin->pMemDesc = pMemDesc;
                 *ppMem = &pMemDarwin->Core;
+
+                IPRT_DARWIN_RESTORE_EFL_AC();
                 return VINF_SUCCESS;
             }
@@ -818,4 +847,5 @@
     }
 #endif
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return rc;
 }
@@ -856,4 +886,6 @@
     if (uAlignment > PAGE_SIZE)
         return VERR_NOT_SUPPORTED;
+
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     /*
@@ -927,4 +959,6 @@
 //                            pMemDarwin->pMemDesc = pMemDesc;
                             *ppMem = &pMemDarwin->Core;
+
+                            IPRT_DARWIN_RESTORE_EFL_AC();
                             return VINF_SUCCESS;
                         }
@@ -947,4 +981,6 @@
             rc = VERR_MAP_FAILED;
     }
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return rc;
 }
@@ -959,4 +995,6 @@
     if (uAlignment > PAGE_SIZE)
         return VERR_NOT_SUPPORTED;
+
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     /*
@@ -994,4 +1032,6 @@
                     pMemDarwin->pMemMap = pMemMap;
                     *ppMem = &pMemDarwin->Core;
+
+                    IPRT_DARWIN_RESTORE_EFL_AC();
                     return VINF_SUCCESS;
                 }
@@ -1006,4 +1046,6 @@
             rc = VERR_MAP_FAILED;
     }
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return rc;
 }
@@ -1016,4 +1058,6 @@
     if (!pVmMap)
         return VERR_NOT_SUPPORTED;
+
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     /*
@@ -1077,4 +1121,5 @@
                    Info.shared, Info.reserved, Info.offset, Info.behavior, Info.user_wired_count);
         }
+        IPRT_DARWIN_RESTORE_EFL_AC();
         return RTErrConvertFromDarwinKern(krc);
     }
@@ -1100,4 +1145,5 @@
     }
 
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return VINF_SUCCESS;
 }
Index: trunk/src/VBox/Runtime/r0drv/darwin/memuserkernel-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/memuserkernel-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/memuserkernel-r0drv-darwin.cpp	(revision 57074)
@@ -43,5 +43,7 @@
 {
     RT_ASSERT_INTS_ON();
+    IPRT_DARWIN_SAVE_EFL_AC();
     int rc = copyin((const user_addr_t)R3PtrSrc, pvDst, cb);
+    IPRT_DARWIN_RESTORE_EFL_AC();
     if (RT_LIKELY(rc == 0))
         return VINF_SUCCESS;
@@ -53,5 +55,7 @@
 {
     RT_ASSERT_INTS_ON();
+    IPRT_DARWIN_SAVE_EFL_AC();
     int rc = copyout(pvSrc, R3PtrDst, cb);
+    IPRT_DARWIN_RESTORE_EFL_AC();
     if (RT_LIKELY(rc == 0))
         return VINF_SUCCESS;
Index: trunk/src/VBox/Runtime/r0drv/darwin/mp-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/mp-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/mp-r0drv-darwin.cpp	(revision 57074)
@@ -187,5 +187,7 @@
 {
     PRTMPARGS pArgs = (PRTMPARGS)pvArg;
+    IPRT_DARWIN_SAVE_EFL_AC();
     pArgs->pfnWorker(cpu_number(), pArgs->pvUser1, pArgs->pvUser2);
+    IPRT_DARWIN_RESTORE_EFL_AC();
 }
 
@@ -194,4 +196,5 @@
 {
     RT_ASSERT_INTS_ON();
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     RTMPARGS Args;
@@ -202,4 +205,6 @@
     Args.cHits = 0;
     mp_rendezvous_no_intrs(rtmpOnAllDarwinWrapper, &Args);
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return VINF_SUCCESS;
 }
@@ -217,5 +222,9 @@
     RTCPUID idCpu = cpu_number();
     if (pArgs->idCpu != idCpu)
+    {
+        IPRT_DARWIN_SAVE_EFL_AC();
         pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
+        IPRT_DARWIN_RESTORE_EFL_AC();
+    }
 }
 
@@ -224,4 +233,5 @@
 {
     RT_ASSERT_INTS_ON();
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     RTMPARGS Args;
@@ -232,4 +242,6 @@
     Args.cHits = 0;
     mp_rendezvous_no_intrs(rtmpOnOthersDarwinWrapper, &Args);
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return VINF_SUCCESS;
 }
@@ -248,6 +260,8 @@
     if (pArgs->idCpu == idCpu)
     {
+        IPRT_DARWIN_SAVE_EFL_AC();
         pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
         ASMAtomicIncU32(&pArgs->cHits);
+        IPRT_DARWIN_RESTORE_EFL_AC();
     }
 }
@@ -257,4 +271,5 @@
 {
     RT_ASSERT_INTS_ON();
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     RTMPARGS Args;
@@ -265,4 +280,6 @@
     Args.cHits = 0;
     mp_rendezvous_no_intrs(rtmpOnSpecificDarwinWrapper, &Args);
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return Args.cHits == 1
          ? VINF_SUCCESS
Index: trunk/src/VBox/Runtime/r0drv/darwin/semevent-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/semevent-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/semevent-r0drv-darwin.cpp	(revision 57074)
@@ -308,4 +308,5 @@
                  */
                 ASMAtomicWriteBool(&pThis->fHaveBlockedThreads, true);
+                IPRT_DARWIN_SAVE_EFL_AC();
                 wait_interrupt_t fInterruptible = fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE ? THREAD_ABORTSAFE : THREAD_UNINT;
                 wait_result_t    rcWait;
@@ -319,4 +320,5 @@
                                                      (event_t)&Waiter, fInterruptible, u64AbsTime);
                 }
+                IPRT_DARWIN_RESTORE_EFL_AC();
 
                 /*
Index: trunk/src/VBox/Runtime/r0drv/darwin/semeventmulti-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/semeventmulti-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/semeventmulti-r0drv-darwin.cpp	(revision 57074)
@@ -323,4 +323,5 @@
                  * Do the actual waiting.
                  */
+                IPRT_DARWIN_SAVE_EFL_AC();
                 ASMAtomicWriteBool(&pThis->fHaveBlockedThreads, true);
                 wait_interrupt_t fInterruptible = fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE ? THREAD_ABORTSAFE : THREAD_UNINT;
@@ -335,4 +336,5 @@
                                                      (event_t)pThis, fInterruptible, u64AbsTime);
                 }
+                IPRT_DARWIN_RESTORE_EFL_AC();
 
                 /*
Index: trunk/src/VBox/Runtime/r0drv/darwin/semfastmutex-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/semfastmutex-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/semfastmutex-r0drv-darwin.cpp	(revision 57074)
@@ -111,6 +111,9 @@
     AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
     RT_ASSERT_PREEMPTIBLE();
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     lck_mtx_lock(pThis->pMtx);
+
+    IPRT_DARWIN_RESTORE_EFL_ONLY_AC();
     return VINF_SUCCESS;
 }
@@ -123,6 +126,9 @@
     AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
     RT_ASSERT_PREEMPTIBLE();
+    IPRT_DARWIN_SAVE_EFL_AC();
 
     lck_mtx_unlock(pThis->pMtx);
+
+    IPRT_DARWIN_RESTORE_EFL_ONLY_AC();
     return VINF_SUCCESS;
 }
Index: trunk/src/VBox/Runtime/r0drv/darwin/semmutex-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/semmutex-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/semmutex-r0drv-darwin.cpp	(revision 57074)
@@ -171,4 +171,5 @@
      * Go to sleep, use the address of the mutex instance as sleep/blocking/event id.
      */
+    IPRT_DARWIN_SAVE_EFL_AC();
     wait_result_t rcWait;
     if (cMillies == RT_INDEFINITE_WAIT)
@@ -183,4 +184,6 @@
                                          (event_t)pThis, fInterruptible, u64AbsTime);
     }
+    IPRT_DARWIN_RESTORE_EFL_AC();
+
     /*
      * Translate the rc.
Index: trunk/src/VBox/Runtime/r0drv/darwin/the-darwin-kernel.h
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/the-darwin-kernel.h	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/the-darwin-kernel.h	(revision 57074)
@@ -91,4 +91,14 @@
 # define kIOMemoryMapperNone UINT32_C(0x800)
 #endif
+
+/** @name Macros for preserving EFLAGS.AC (despair / paranoid)
+ * @remarks Unlike linux, we have to restore it unconditionally on darwin.
+ * @{ */
+#include <iprt/asm-amd64-x86.h>
+#include <iprt/x86.h>
+#define IPRT_DARWIN_SAVE_EFL_AC()           RTCCUINTREG fSavedEfl = ASMGetFlags();
+#define IPRT_DARWIN_RESTORE_EFL_AC()        ASMSetFlags(fSavedEfl)
+#define IPRT_DARWIN_RESTORE_EFL_ONLY_AC()   ASMSetFlags((ASMGetFlags() & ~IPRT_X86_EFL_AC) | (fSavedEfl & IPRT_X86_EFL_AC))
+/** @} */
 
 
Index: trunk/src/VBox/Runtime/r0drv/darwin/thread-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/thread-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/thread-r0drv-darwin.cpp	(revision 57074)
@@ -47,7 +47,11 @@
 {
     RT_ASSERT_PREEMPTIBLE();
+    IPRT_DARWIN_SAVE_EFL_AC();
+
     uint64_t u64Deadline;
     clock_interval_to_deadline(cMillies, kMillisecondScale, &u64Deadline);
     clock_delay_until(u64Deadline);
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return VINF_SUCCESS;
 }
@@ -69,5 +73,9 @@
 {
     RT_ASSERT_PREEMPTIBLE();
+    IPRT_DARWIN_SAVE_EFL_AC();
+
     thread_block(THREAD_CONTINUE_NULL);
+
+    IPRT_DARWIN_RESTORE_EFL_AC();
     return true; /* this is fishy */
 }
Index: trunk/src/VBox/Runtime/r0drv/darwin/threadpreempt-r0drv-darwin.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/darwin/threadpreempt-r0drv-darwin.cpp	(revision 57073)
+++ trunk/src/VBox/Runtime/r0drv/darwin/threadpreempt-r0drv-darwin.cpp	(revision 57074)
@@ -174,5 +174,9 @@
             lck_spin_t *pSpinLock = g_aPreemptHacks[idCpu].pSpinLock;
             if (pSpinLock)
+            {
+                IPRT_DARWIN_SAVE_EFL_AC();
                 lck_spin_unlock(pSpinLock);
+                IPRT_DARWIN_RESTORE_EFL_AC();
+            }
             else
                 AssertFailed();
