Index: /trunk/src/VBox/Devices/PC/DevAPIC.cpp
===================================================================
--- /trunk/src/VBox/Devices/PC/DevAPIC.cpp	(revision 12616)
+++ /trunk/src/VBox/Devices/PC/DevAPIC.cpp	(revision 12617)
@@ -62,11 +62,17 @@
 /** @def IOAPIC_UNLOCK
  * Releases the PDM lock. This is a NOP if locking is disabled. */
-#define APIC_LOCK(pThis, rc) \
-    do { \
+#define APIC_LOCK(pThis, rc)                                            \
+    do {                                                                \
         int rc2 = (pThis)->CTX_SUFF(pApicHlp)->pfnLock((pThis)->CTX_SUFF(pDevIns), rc); \
-        if (rc2 != VINF_SUCCESS) \
-            return rc2; \
+        if (rc2 != VINF_SUCCESS)                                        \
+            return rc2;                                                 \
     } while (0)
-#define APIC_UNLOCK(pThis) \
+#define APIC_LOCK_VOID(pThis, rc)                                       \
+    do {                                                                \
+        int rc2 = (pThis)->CTX_SUFF(pApicHlp)->pfnLock((pThis)->CTX_SUFF(pDevIns), rc); \
+        if (rc2 != VINF_SUCCESS)                                        \
+            return;                                                     \
+    } while (0)
+#define APIC_UNLOCK(pThis)                                              \
     (pThis)->CTX_SUFF(pApicHlp)->pfnUnlock((pThis)->CTX_SUFF(pDevIns))
 #define IOAPIC_LOCK(pThis, rc) \
@@ -447,5 +453,7 @@
     APICState *s = getLapic(dev);
     Log(("cpu_set_apic_base: %016RX64\n", val));
-
+    
+    /** @todo: do we need to lock here ? */
+    /* APIC_LOCK_VOID(dev, VERR_INTERNAL_ERROR); */
     /** @todo If this change is valid immediately, then we should change the MMIO registration! */
     s->apicbase = (val & 0xfffff000) |
@@ -460,4 +468,5 @@
         dev->CTX_SUFF(pApicHlp)->pfnChangeFeature(pDevIns, false);
     }
+    /* APIC_UNLOCK(dev); */
 }
 #endif  /* VBOX */
@@ -648,5 +657,9 @@
         return false;
     APICState *s = getLapic(dev);
-
+    
+    /*
+     * All our callbacks now come from single IOAPIC, thus locking
+     * seems to be excessive now (@todo: check) 
+     */
     irrv = get_highest_priority_int(s->irr);
     if (irrv < 0)
@@ -654,4 +667,5 @@
 
     ppr = apic_get_ppr_zero_tpr(s);
+
     if (ppr && (irrv & 0xf0) <= (ppr & 0xf0))
         return false;
@@ -871,22 +885,21 @@
 }
 
-#ifndef VBOX
-int apic_get_interrupt(CPUState *env)
-{
-    APICState *s = env->apic_state;
-#else /* VBOX */
+
 PDMBOTHCBDECL(int) apicGetInterrupt(PPDMDEVINS pDevIns)
 {
     APICDeviceInfo *dev = PDMINS_2_DATA(pDevIns, APICDeviceInfo *);
-    APICState *s = getLapic(dev);
-#endif /* VBOX */
-    int intno;
-
     /* if the APIC is not installed or enabled, we let the 8259 handle the
        IRQs */
-    if (!s) {
+    if (!dev)
+    {
         Log(("apic_get_interrupt: returns -1 (!s)\n"));
         return -1;
     }
+
+    APIC_LOCK(dev, VERR_INTERNAL_ERROR);
+
+    APICState *s = getLapic(dev);
+    int intno;
+
     if (!(s->spurious_vec & APIC_SV_ENABLE)) {
         Log(("apic_get_interrupt: returns -1 (APIC_SV_ENABLE)\n"));
@@ -908,4 +921,5 @@
     apic_update_irq(dev, s);
     LogFlow(("apic_get_interrupt: returns %d\n", intno));
+    APIC_UNLOCK(dev);
     return intno;
 }
@@ -975,5 +989,6 @@
     APICDeviceInfo *dev = PDMINS_2_DATA(pDevIns, APICDeviceInfo *);
     APICState *s = getLapic(dev);
-    dev->pApicHlpR3->pfnLock(pDevIns, VERR_INTERNAL_ERROR);
+
+    APIC_LOCK_VOID(dev, VERR_INTERNAL_ERROR);
 #endif /* VBOX */
 
@@ -1772,5 +1787,5 @@
     APICState *s = getLapic(dev);
 
-    dev->pApicHlpR3->pfnLock(pDevIns, VERR_INTERNAL_ERROR);
+    APIC_LOCK_VOID(dev, VERR_INTERNAL_ERROR);
 
     TMTimerStop(s->CTX_SUFF(pTimer));
@@ -1794,9 +1809,14 @@
 {
     APICDeviceInfo *dev = PDMINS_2_DATA(pDevIns, APICDeviceInfo *);
-    
+#ifdef VBOX_WITH_SMP_GUESTS
+    LogRel(("[SMP]: relocate apic on %llx\n", offDelta));    
+#endif
     dev->pDevInsRC  = PDMDEVINS_2_RCPTR(pDevIns);
     dev->pApicHlpRC = dev->pApicHlpR3->pfnGetRCHelpers(pDevIns);
-    /** @todo: check if relocated pLapicsRC right */
-    dev->pLapicsRC  = MMHyperR3ToR0(PDMDevHlpGetVM(pDevIns), dev->pLapicsR3);
+    /** @todo: write pLapicsRC relocation right */
+#if 0
+    if (dev->pLapicsRC)
+        dev->pLapicsRC  = MMHyperR3ToR0(PDMDevHlpGetVM(pDevIns), dev->pLapicsR3);
+#endif
     foreach_apic(dev, 0xffffffff,
                  apic->pTimerRC = TMTimerRCPtr(apic->CTX_SUFF(pTimer)));
