1#include <machine/asm.h> 2 3IMPORT(remaining_invocations) 4IMPORT(origstate) 5IMPORT(newstate) 6 7#define JUNK 0xCC0FFEE0 8 9#define COPY(dest, offset) \ 10 mov $dest, %ebp ; \ 11 mov 4*offset(%esp), %ebx ; \ 12 mov %ebx, 4*offset(%ebp) ; 13 14/* Copy the result of a pusha to dest. */ 15#define COPYA(dest) \ 16 COPY(dest, 0); COPY(dest, 1); COPY(dest, 2); COPY(dest, 3); \ 17 COPY(dest, 4); COPY(dest, 5); COPY(dest, 6); COPY(dest, 7); 18 19/* void check_context_loop() */ 20ENTRY(check_context_loop) 21 /* Save original context so we can restore it. */ 22 pusha 23 24 /* Put some junk in the registers. 25 * We want to junk the state, and junk it differently per reg, 26 * so it's likelier corruption is actually detected. We can't 27 * touch %esp but we can verify that it doesn't change from its 28 * current value. 29 */ 30 mov $JUNK+1, %eax 31 mov $JUNK+2, %ebx 32 mov $JUNK+3, %ecx 33 mov $JUNK+4, %edx 34 mov $JUNK+5, %ebp 35 mov $JUNK+6, %esi 36 mov $JUNK+7, %edi 37 38 /* Save the junked state so we can compare it. */ 39 pusha 40cont: 41 /* Check if we're done. */ 42 cmpl $0, (_C_LABEL(remaining_invocations)) 43 jz done 44 45 /* We're not done. */ 46 47 /* Restart loop. */ 48 jmp cont 49 50done: 51 /* Save the junked, but should be unmodified state 52 * so we can copy it. 53 */ 54 pusha 55 COPYA(_C_LABEL(newstate)); 56 popa 57 58 /* copy and restore junked state */ 59 COPYA(_C_LABEL(origstate)); 60 popa 61 62 /* restore original state and return */ 63 popa 64 ret 65