kernel: opportunistically map stack space

This commit is contained in:
K. Lange 2021-06-06 15:54:30 +09:00
parent b04164b19d
commit 5ed9033d15
3 changed files with 25 additions and 1 deletions

View File

@ -47,6 +47,7 @@ typedef struct image {
uintptr_t heap;
uintptr_t stack;
uintptr_t shm_heap;
uintptr_t userstack;
spin_lock_t lock;
} image_t;

View File

@ -155,6 +155,22 @@ void irq_uninstall_handler(size_t irq) {
irq_routines[i * IRQ_CHAIN_SIZE + irq] = NULL;
}
static void map_more_stack(uintptr_t fromAddr) {
volatile process_t * volatile proc = this_core->current_process;
if (proc->group != 0) {
proc = process_from_pid(proc->group);
}
spin_lock(proc->image.lock);
for (uintptr_t i = fromAddr; i < proc->image.userstack; i += 0x1000) {
union PML * page = mmu_get_page(i, MMU_GET_MAKE);
mmu_frame_allocate(page, MMU_FLAG_WRITABLE);
mmu_invalidate(i);
}
proc->image.userstack = fromAddr;
spin_unlock(proc->image.lock);
}
struct regs * isr_handler(struct regs * r) {
this_core->interrupt_registers = r;
@ -174,6 +190,10 @@ struct regs * isr_handler(struct regs * r) {
return_from_signal_handler();
break;
}
if (faulting_address < 0x800000000000 && faulting_address > 0x700000000000) {
map_more_stack(faulting_address & 0xFFFFffffFFFFf000);
break;
}
#ifdef DEBUG_FAULTS
arch_fatal();
#else

View File

@ -244,11 +244,14 @@ int elf_exec(const char * path, fs_node_t * file, int argc, const char *const ar
/* Map stack space */
uintptr_t userstack = 0x800000000000;
for (uintptr_t i = userstack - 64 * 0x400; i < userstack; i += 0x1000) {
for (uintptr_t i = userstack - 16 * 0x400; i < userstack; i += 0x1000) {
union PML * page = mmu_get_page(i, MMU_GET_MAKE);
mmu_frame_allocate(page, MMU_FLAG_WRITABLE);
mmu_invalidate(i);
}
this_core->current_process->image.userstack = userstack - 16 * 0x400;
#define PUSH(type,val) do { \
userstack -= sizeof(type); \
while (userstack & (sizeof(type)-1)) userstack--; \