Skip to content

Commit

Permalink
stack growing works now, iret from handlers with error code fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Duft committed May 18, 2011
1 parent 7accdab commit f6ee0d3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/tachyon.c
Expand Up @@ -32,7 +32,7 @@ void test_thr() {
static int level = 0; static int level = 0;
char test[1024]; char test[1024];
test[0] = 'a' + level++; test[0] = 'a' + level++;
info("hello thread %s\n", test); info("hello thread %d\n", level, test);


test_thr(); test_thr();
} }
Expand Down
7 changes: 3 additions & 4 deletions src/x86/idt.S
Expand Up @@ -50,11 +50,10 @@ _x86_isr\num:
push 0x4(%esp) push 0x4(%esp)
push %esp push %esp
call intr_dispatch call intr_dispatch
.if !\has_err
# ATTENTION: the cpu does _not_ pop an error code, even when it
# pushed one, so remove any code here!
add $0xc, %esp add $0xc, %esp
.else
add $0x8, %esp
.endif
iret iret
.endif .endif
._x86_isr_end\num: ._x86_isr_end\num:
Expand Down
6 changes: 2 additions & 4 deletions src/x86_64/idt.S
Expand Up @@ -76,11 +76,9 @@ _x86_64_isr\num:


# TODO: kernel call return value? # TODO: kernel call return value?


.if !\has_err # ATTENTION: the cpu does _not_ pop an error code, even when it
# pushed one, so remove any code here!
addq $0x18, %rsp addq $0x18, %rsp
.else
addq $0x10, %rsp
.endif
iretq iretq
.endif .endif
._x86_64_isr_end\num: ._x86_64_isr_end\num:
Expand Down
31 changes: 19 additions & 12 deletions src/x86_64/pgflt.c
Expand Up @@ -16,15 +16,15 @@
#define ERRC_INSTR_FETCH 0x10 #define ERRC_INSTR_FETCH 0x10


static void pgflt_install(); static void pgflt_install();
static bool pgflt_handler(interrupt_t* state); bool pgflt_handler(interrupt_t* state);


INSTALL_EXTENSION(EXTP_KINIT, pgflt_install, "page fault handler"); INSTALL_EXTENSION(EXTP_KINIT, pgflt_install, "page fault handler");


static void pgflt_install() { static void pgflt_install() {
intr_add(EX_PAGE_FAULT, pgflt_handler); intr_add(EX_PAGE_FAULT, pgflt_handler);
} }


static bool pgflt_handler(interrupt_t* state) { bool pgflt_handler(interrupt_t* state) {
ksym_t const* sym = ksym_get((void*)state->ip); ksym_t const* sym = ksym_get((void*)state->ip);
info("page-fault at %p <%s> while %s %p\n", info("page-fault at %p <%s> while %s %p\n",
state->ip, sym ? sym->name : "unknown", ((state->code & ERRC_INSTR_FETCH) ? state->ip, sym ? sym->name : "unknown", ((state->code & ERRC_INSTR_FETCH) ?
Expand All @@ -44,21 +44,28 @@ static bool pgflt_handler(interrupt_t* state) {
if(!context->thread) if(!context->thread)
fatal("no thread associated with current execution context!\n"); fatal("no thread associated with current execution context!\n");


if(!context->thread->parent)
fatal("no process associated with current thread!\n");

stack_allocator_t* stka = context->thread->parent->stka;
stack_t* stk = context->thread->stack; stack_t* stk = context->thread->stack;


if(stka_pgflt(stka, stk, context->state.cr2)) { if(context->state.cr2 >= stk->guard && context->state.cr2 <= stk->top) {
info("page fault handled by growing the stack for thread %d in process %d\n", trace("looks like a stack grow request, trying to enlarge stack\n");
context->thread->id, context->thread->parent->id);
if(!context->thread->parent)
fatal("no process associated with current thread!\n");

stack_allocator_t* stka = context->thread->parent->stka;

if(stka_pgflt(stka, stk, context->state.cr2)) {
info("page fault handled by growing the stack for thread %d in process %d\n",
context->thread->id, context->thread->parent->id);


return true; return true;
} else {
warn("growing stack for thread %d in process %d failed; stack is %d bytes large!\n",
context->thread->id, context->thread->parent->id, stk->top - stk->mapped);
}
} }
} }


/* at the moment, we're not "handling" this, but only // no resolution found for the actual problem.
* give some useful information to the developer... */
return false; return false;
} }

0 comments on commit f6ee0d3

Please sign in to comment.