Chris Emerson wrote:
> > Next; an instruction is tripping a #PF to the first page in the
> > segment (@ 0xc0000000). BTW, this Linux image is the old style
> > segmentation.
> >
> > This may be intentional.
>
> Sounds like this is the check for whether the WP bit is honoured in
> supervisor mode. (Which fits with my kernel log messages too).
Yes, thanks. I booted it in bochs and saw the WP message.
So I implemented exceptions, and let the #PF happen. Seems
to get through OK. Now working on other virtualization
events that come up. Hope to get further.
BTW, I needed a setjmp/longjmp for exceptions processing.
The ones from <setjmp.h> seem to need linking with libc,
so I implemented my own for use in the monitor. Seems
to work OK so far.
Can someone look at the included code and tell me if I'm overlooking
something, just in case?
-Kevin
#include <stdio.h>
typedef struct {
unsigned eip;
unsigned esp;
unsigned ebp;
} vm_jmp_buf_t;
vm_jmp_buf_t vm_jmp_buf;
void f1(void);
void f2(void);
void f3(void);
#define SetJmp(jmp_buf) \
({ \
unsigned ret; \
asm volatile ( \
"movl $0f, %0 \n\t" \
"movl %%esp, %1 \n\t" \
"movl %%ebp, %2 \n\t" \
"movl $0x0, %%eax \n\t" \
"0: \n" \
: "=m" (jmp_buf.eip), "=m" (jmp_buf.esp), "=m" (jmp_buf.ebp), \
"=eax" (ret) \
: \
: "memory", "ebx", "ecx", "edx", "edi", "esi" \
); \
ret; \
})
#define LongJmp(jmp_buf, ret) \
asm volatile ( \
"movl %%edx, %%ebp \n\t" \
"movl %%ebx, %%esp \n\t" \
"jmpl *%%ecx \n" \
: \
: "ecx" (jmp_buf.eip), "ebx" (jmp_buf.esp), "edx" (jmp_buf.ebp), \
"eax" (ret) \
: "memory" \
);
int
main()
{
unsigned ret = 0;
if ( (ret=SetJmp(vm_jmp_buf)) ) {
printf("setjmp returns %u from longjmp\n", ret);
return 0;
}
printf("setjmp buffer filled\n");
f1();
return 0;
}
void
f1(void)
{
f2();
}
void
f2(void)
{
f3();
}
void
f3(void)
{
printf("f3 calling LongJmp\n");
LongJmp(vm_jmp_buf, 2);
printf("humm... code after LongJmp executed\n");
}