mmap #8

Merged
mathieu merged 22 commits from mmap into master 2024-02-11 15:29:59 +01:00
2 changed files with 20 additions and 21 deletions
Showing only changes of commit cca78b269d - Show all commits

View File

@ -18,8 +18,6 @@ uaddr_t loadElfProg(const char *prog, struct process * proc)
int i; int i;
uaddr_t lastUserAddr = 0; uaddr_t lastUserAddr = 0;
/* e_ident value */ /* e_ident value */
#define ELFMAG0 0x7f #define ELFMAG0 0x7f
#define ELFMAG1 'E' #define ELFMAG1 'E'

View File

@ -84,7 +84,9 @@ void loadUserSpace()
return; return;
} }
{
struct process *proc = processCreate("init"); struct process *proc = processCreate("init");
struct uAddrSpace *as = processGetAddrSpace(proc);
threadChangeCurrentContext(processGetMMUContext(proc)); threadChangeCurrentContext(processGetMMUContext(proc));
uaddr_t prog = loadElfProg(buf + FILE_HEADER_SIZE, proc); uaddr_t prog = loadElfProg(buf + FILE_HEADER_SIZE, proc);
@ -94,16 +96,15 @@ void loadUserSpace()
} }
// Alloc user stack // Alloc user stack
uaddr_t stackTop = 0xfffffffc; size_t stackSize = PAGE_SIZE * 2;
uaddr_t stackBottom = ALIGN_DOWN(stackTop, PAGE_SIZE); uaddr_t stack = PAGING_TOP_USER_ADDRESS - stackSize + 1;
paddr_t stackPhy = allocPhyPage(1); zeroMmap(as, &stack, stackSize, PAGING_MEM_USER | PAGING_MEM_WRITE | PAGING_MEM_READ,
assert(pageMap(stackBottom, stackPhy, 0);
PAGING_MEM_USER | PAGING_MEM_WRITE | PAGING_MEM_READ) == 0);
unrefPhyPage(stackPhy);
threadCreateUser("init", proc, prog, 0, 0, stackTop); threadCreateUser("init", proc, prog, 0, 0, stack + stackSize - 4);
processUnref(proc); processUnref(proc);
threadChangeCurrentContext(NULL); threadChangeCurrentContext(NULL);
}
free(buf); free(buf);
} }