Changeset 14672 in vbox
- Timestamp:
- Nov 27, 2008 12:19:22 AM (16 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR0/VMMR0A.asm
r14505 r14672 30 30 %ifdef RT_ARCH_X86 ; The other architecture(s) use(s) C99 variadict macros. 31 31 extern IMPNAME(RTLogLogger) 32 %endif 33 34 %ifdef RT_OS_DARWIN 35 %define VMM_R0_SWITCH_STACK 32 36 %endif 33 37 … … 71 75 jnz .resume 72 76 77 mov ebx, edx ; pJmpBuf -> ebx (persistent reg) 78 %ifdef VMM_R0_SWITCH_STACK 79 mov esi, [ebx + VMMR0JMPBUF.pvSavedStack] 80 test esi, esi 81 jz .entry_error 82 %ifdef VBOX_STRICT 83 mov edx, esi 84 mov edi, esi 85 mov ecx, 2048 86 mov eax, 0eeeeeeeeh 87 repne stosd 88 %endif 89 lea esi, [esi + 8192 - 32] 90 mov [esi + 1ch], dword 0deadbeefh ; Marker 1. 91 mov [esi + 18h], ebx ; Save pJmpBuf pointer. 92 mov [esi + 14h], dword 00c00ffeeh ; Marker 2. 93 mov [esi + 10h], dword 0f00dbeefh ; Marker 3. 94 mov edx, [esp + 10h] ; pvArg2 95 mov [esi + 04h], edx 96 mov ecx, [esp + 0ch] ; pvArg1 97 mov [esi ], ecx 98 mov eax, [esp + 08h] ; pfn 99 mov esp, esi ; Switch stack! 100 call eax 101 and dword [esi + 1ch], byte 0 ; clear marker. 102 103 %else ; !VMM_R0_SWITCH_STACK 73 104 mov ecx, [esp + 0ch] ; pvArg1 74 105 mov edx, [esp + 10h] ; pvArg2 75 106 mov eax, [esp + 08h] ; pfn 76 sub esp, 1 6; align the stack on a 16-byte boundrary.77 mov [esp ], ecx78 mov [esp +4], edx107 sub esp, 12 ; align the stack on a 16-byte boundrary. 108 mov [esp ], ecx 109 mov [esp + 04h], edx 79 110 call eax 80 add esp, 16 81 mov edx, [esp + 4h] ; pJmpBuf 82 83 ; restore the registers that we're not allowed to modify 84 ; otherwise a resume might restore the wrong values (from the previous run) 111 %endif ; !VMM_R0_SWITCH_STACK 112 mov edx, ebx ; pJmpBuf -> edx (volatile reg) 113 114 ; 115 ; Return like in the long jump. 116 ; (It is vital that we restore all registers since they might've changed 117 ; by a long jump.) 118 ; 119 .proper_return: 120 mov ebx, [edx + VMMR0JMPBUF.ebx] 121 mov esi, [edx + VMMR0JMPBUF.esi] 85 122 mov edi, [edx + VMMR0JMPBUF.edi] 86 mov esi, [edx + VMMR0JMPBUF.esi]87 mov ebx, [edx + VMMR0JMPBUF.ebx]88 123 mov ebp, [edx + VMMR0JMPBUF.ebp] 89 124 mov ecx, [edx + VMMR0JMPBUF.eip] 90 125 and dword [edx + VMMR0JMPBUF.eip], byte 0 ; used for valid check. 91 ret 126 mov esp, [edx + VMMR0JMPBUF.esp] 127 jmp ecx 128 129 .entry_error: 130 mov eax, VERR_INTERNAL_ERROR 131 jmp .proper_return 92 132 93 133 ; … … 95 135 ; 96 136 .resume: 137 %ifdef VMM_R0_SWITCH_STACK 138 ; Switch stack. 139 mov esp, [edx + VMMR0JMPBUF.SpResume] 140 %else ; !VMM_R0_SWITCH_STACK 97 141 ; Sanity checks. 98 142 cmp ecx, [edx + VMMR0JMPBUF.SpCheck] … … 120 164 ; Restore the stack. 121 165 ; 122 mov byte [edx + VMMR0JMPBUF.fInRing3Call], 0123 166 mov ecx, [edx + VMMR0JMPBUF.cbSavedStack] 124 167 shr ecx, 2 … … 127 170 mov esp, edi 128 171 rep movsd 172 %endif ; !VMM_R0_SWITCH_STACK 173 mov byte [edx + VMMR0JMPBUF.fInRing3Call], 0 129 174 130 175 ; 131 176 ; Continue where we left off. 132 177 ; 178 %ifdef VBOX_STRICT 179 pop eax ; magic 180 cmp eax, 0f00dbed0h 181 je .magic_ok 182 mov ecx, 0123h 183 mov [ecx], edx 184 .magic_ok: 185 %endif 133 186 popf 134 187 pop ebx … … 288 341 push ebx 289 342 pushf 343 %ifdef VBOX_STRICT 344 push dword 0f00dbed0h 345 %endif 290 346 291 347 ; … … 302 358 303 359 ; 304 ; Sa ve the stack.360 ; Sanity checks. 305 361 ; 306 362 mov edi, [edx + VMMR0JMPBUF.pvSavedStack] … … 308 364 jz .nok 309 365 mov [edx + VMMR0JMPBUF.SpResume], esp 366 %ifndef VMM_R0_SWITCH_STACK 310 367 mov esi, esp 311 368 mov ecx, [edx + VMMR0JMPBUF.esp] … … 314 371 ; two sanity checks on the size. 315 372 cmp ecx, 8192 ; check max size. 316 jbe .ok 317 .nok: 318 mov eax, VERR_INTERNAL_ERROR 319 popf 320 pop ebx 321 pop esi 322 pop edi 323 leave 324 ret 325 .ok: 373 jnbe .nok 374 375 ; 376 ; Copy the stack. 377 ; 326 378 test ecx, 3 ; check alignment 327 379 jnz .nok … … 329 381 shr ecx, 2 330 382 rep movsd 383 %endif ; !VMM_R0_SWITCH_STACK 331 384 332 385 ; store the last pieces of info. … … 345 398 mov esp, [edx + VMMR0JMPBUF.esp] 346 399 jmp ecx 400 401 ; 402 ; Failure 403 ; 404 .nok: 405 %ifdef VBOX_STRICT 406 pop eax ; magic 407 cmp eax, 0f00dbed0h 408 je .magic_ok 409 mov ecx, 0123h 410 mov [ecx], edx 411 .magic_ok: 412 %endif 413 popf 414 pop ebx 415 pop esi 416 pop edi 417 mov eax, VERR_INTERNAL_ERROR 418 leave 419 ret 347 420 %endif ; RT_ARCH_X86 348 421 -
trunk/src/VBox/VMM/testcase/tstVMMR0CallHost-1.cpp
r13872 r14672 40 40 *******************************************************************************/ 41 41 /** The jump buffer. */ 42 static VMMR0JMPBUF g_Jmp; 42 static VMMR0JMPBUF g_Jmp; 43 /** The number of jumps we've done. */ 44 static unsigned volatile g_cJmps; 43 45 /** The saved stack. */ 44 static uint8_t g_Stack[8192];46 static uint8_t g_Stack[8192]; 45 47 46 48 47 49 int foo(int i, int iZero, int iMinusOne) 48 50 { 49 char *pv = (char *)alloca(i + 32); 50 RTStrPrintf(pv, i + 32, "i=%d%*s\n", i, i+32, ""); 51 /* allocate a buffer which we fill up to the end. */ 52 size_t cb = (i % 5555) + 32; 53 char *pv = (char *)alloca(cb); 54 RTStrPrintf(pv, cb, "i=%d%*s\n", i, cb, ""); 55 56 /* Do long jmps every 7th time */ 51 57 if ((i % 7) == 0) 52 58 { 59 g_cJmps++; 53 60 int rc = vmmR0CallHostLongJmp(&g_Jmp, 42); 54 61 if (!rc) … … 84 91 int tst(int iFrom, int iTo, int iInc) 85 92 { 86 for (int i = iFrom; i < iTo; i += iInc) 93 g_cJmps = 0; 94 for (int i = iFrom; i != iTo; i += iInc) 87 95 { 88 96 int rc = vmmR0CallHostSetJmp(&g_Jmp, (PFNVMMR0SETJMP)tst2, (PVM)i, 0); … … 92 100 return 1; 93 101 } 102 } 103 if (!g_cJmps) 104 { 105 RTPrintf("tstVMMR0CallHost-1: FAILURE - no jumps!\n"); 106 return 1; 94 107 } 95 108 return 0; … … 103 116 */ 104 117 RTR3Init(); 105 RTPrintf("tstVMMR0CallHost-1: Testing...\n");106 118 g_Jmp.pvSavedStack = (RTR0PTR)&g_Stack[0]; 107 119 … … 109 121 * Try about 1000 long jumps with increasing stack size.. 110 122 */ 123 RTPrintf("tstVMMR0CallHost-1: Testing 1\n"); 111 124 int rc = tst(0, 7000, 1); 112 125 if (!rc) 126 { 127 RTPrintf("tstVMMR0CallHost-1: Testing 2\n"); 113 128 rc = tst(7599, 0, -1); 129 } 114 130 115 131 if (!rc)
Note:
See TracChangeset
for help on using the changeset viewer.