diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-11-13 17:16:28 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-11-13 17:16:28 +0200 |
| commit | 1a0188fac0c0f265c4495b83592389b8b3645462 (patch) | |
| tree | c1687724dd7f7ccf6d9d0d134c2766f14d3e39f5 /common/tcb.c | |
| parent | e6dc962ef7758c438039d7f8ac7e2bf3ebcb5c10 (diff) | |
| download | kmi-1a0188fac0c0f265c4495b83592389b8b3645462.tar.gz kmi-1a0188fac0c0f265c4495b83592389b8b3645462.zip | |
outline rpc stack handling
Diffstat (limited to 'common/tcb.c')
| -rw-r--r-- | common/tcb.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/common/tcb.c b/common/tcb.c index 5121940..afc8442 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -432,7 +432,8 @@ void save_context(struct tcb *t) /** @todo what if user uses their own stack? Or is a dick and * sets the stack pointer to RPC_STACK_TOP or something? It'll * likely only cause a fuckup in the process who did the dumb - * thing, so maybe just consider it user error? */ + * thing, so maybe just consider it user error? Except by + * causing the stack of the next rpc to run out of memory... */ rpc_stack = align_down(get_stack(t), BASE_PAGE_SIZE); @@ -443,8 +444,20 @@ void save_context(struct tcb *t) ctx->regs = t->regs; ctx->rpc_stack = rpc_stack; + /** @todo if we run out of rpc_stack space we should just stop, likely + * return a status? */ rpc_stack -= BASE_PAGE_SIZE; + /** @todo what if each stack is only some number of pages, and if a proc + * goes over the limit is is seen as programming error? Possibly user + * configurable number as well, might actually use the config subsystem + * :D + * In such a case it would probably be smarter to mark all pages + * inaccessible at first, and then mark the first page accessible. If + * the process needs more stack space it'll cause a paging exception, + * we'll handle it separately and if the process isn't going over the + * limit just give it more. + * */ mark_rpc_inaccessible(t, rpc_stack, t->rpc_stack); t->rpc_stack = rpc_stack; t->regs = (vm_t)ctx; @@ -461,3 +474,11 @@ void load_context(struct tcb *t) t->eid = ctx->eid; t->regs = ctx->regs; } + +bool enough_rpc_stack(struct tcb *t) +{ + vm_t top = RPC_STACK_BASE + __call_stack_size; + vm_t rpc_stack = t->rpc_stack + BASE_PAGE_SIZE; + + return top - rpc_stack >= __call_stack_size / 4; +} |
