Permalink
Browse files

stack growing works now, iret from handlers with error code fixed.

  • Loading branch information...
Markus Duft
Markus Duft committed May 18, 2011
1 parent 7accdab commit f6ee0d3f70e0cbb2bc5d7ae7c087752768037d8f
Showing with 25 additions and 21 deletions.
  1. +1 −1 src/tachyon.c
  2. +3 −4 src/x86/idt.S
  3. +2 −4 src/x86_64/idt.S
  4. +19 −12 src/x86_64/pgflt.c
View
@@ -32,7 +32,7 @@ void test_thr() {
static int level = 0;
char test[1024];
test[0] = 'a' + level++;
- info("hello thread %s\n", test);
+ info("hello thread %d\n", level, test);
test_thr();
}
View
@@ -50,11 +50,10 @@ _x86_isr\num:
push 0x4(%esp)
push %esp
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
- .else
- add $0x8, %esp
- .endif
iret
.endif
._x86_isr_end\num:
View
@@ -76,11 +76,9 @@ _x86_64_isr\num:
# 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
- .else
- addq $0x10, %rsp
- .endif
iretq
.endif
._x86_64_isr_end\num:
View
@@ -16,15 +16,15 @@
#define ERRC_INSTR_FETCH 0x10
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");
static void pgflt_install() {
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);
info("page-fault at %p <%s> while %s %p\n",
state->ip, sym ? sym->name : "unknown", ((state->code & ERRC_INSTR_FETCH) ?
@@ -44,21 +44,28 @@ static bool pgflt_handler(interrupt_t* state) {
if(!context->thread)
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;
- 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);
+ if(context->state.cr2 >= stk->guard && context->state.cr2 <= stk->top) {
+ trace("looks like a stack grow request, trying to enlarge stack\n");
+
+ 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
- * give some useful information to the developer... */
+ // no resolution found for the actual problem.
return false;
}

0 comments on commit f6ee0d3

Please sign in to comment.