diff --git a/src/include/kernel/sched.h b/src/include/kernel/sched.h index c8d4e6a..52b8682 100644 --- a/src/include/kernel/sched.h +++ b/src/include/kernel/sched.h @@ -39,6 +39,8 @@ typedef struct Thread { SyscallRequest syscall; // for when the thread is blocked int exitStatus; // for zombie threads + int pages; // memory pages used + struct Thread *next; void *context; // platform-specific (page tables, registers, etc) @@ -59,6 +61,8 @@ typedef struct Process { struct IODescriptor io[MAX_IO_DESCRIPTORS]; int iodCount; + int pages; // memory pages used + size_t threadCount; size_t childrenCount; diff --git a/src/platform/x86_64/sched/context.c b/src/platform/x86_64/sched/context.c index 72e1af6..eff6738 100644 --- a/src/platform/x86_64/sched/context.c +++ b/src/platform/x86_64/sched/context.c @@ -149,6 +149,8 @@ int platformSetContext(Thread *t, uintptr_t entry, uintptr_t highest, const char ctx->regs.rsp = stack; t->highest = stack + PAGE_SIZE; // requisite to sbrk() someday + + t->pages = (t->highest - USER_BASE_ADDRESS + PAGE_SIZE - 1) / PAGE_SIZE; return 0; } diff --git a/src/sched/exec.c b/src/sched/exec.c index 228245c..b6fb2a4 100644 --- a/src/sched/exec.c +++ b/src/sched/exec.c @@ -93,6 +93,8 @@ pid_t execveMemory(const void *ptr, const char **argv, const char **envp) { return 0; } + process->pages = process->threads[0]->pages; + KDEBUG("created new process with pid %d\n", pid); processes++; diff --git a/src/sched/fork.c b/src/sched/fork.c index 58019f1..1479b7e 100644 --- a/src/sched/fork.c +++ b/src/sched/fork.c @@ -58,6 +58,13 @@ pid_t fork(Thread *t) { p->threads[0]->pid = pid; p->threads[0]->tid = pid; p->threads[0]->context = calloc(1, PLATFORM_CONTEXT_SIZE); + p->threads[0]->highest = t->highest; + p->threads[0]->pages = t->pages; + + // NOTE: fork() only clones one thread, which is why we're not cloning the + // entire process memory, but just the calling thread + p->pages = t->pages; + if(!p->threads[0]->context) { free(p->threads[0]); free(p->threads);