diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-17 16:43:28 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-17 16:43:28 +0200 |
| commit | 3259715b0ed510ededeeb8240cc3bbdcdfc362a3 (patch) | |
| tree | 4dadcb81f7e15c9e6d4d2f0a371734f3341484dc /src/core/scheduler.c | |
| parent | dcadede2d4d6f7b94e38412dfbb924ed8abea709 (diff) | |
Improve task stack management
Diffstat (limited to 'src/core/scheduler.c')
| -rw-r--r-- | src/core/scheduler.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/core/scheduler.c b/src/core/scheduler.c index 224c20d..59f3b9d 100644 --- a/src/core/scheduler.c +++ b/src/core/scheduler.c @@ -80,11 +80,16 @@ void clock(){ schedule(stack); } -void task_create(int *page_dir, void *task, int task_size, int stack_offset){ +void task_create(void *task, int task_size){ if(nproc<=MAX_PROC){ + // Allocate at least 1 page and 1 page for the user stack + int allocated=1+task_size/4096+1; + int* page_dir=paging_allocate(allocated); + // Compute various addresses void *entry_point=PAGING_ENTRY_POINT_VIRT; - void *ustack=(void*)(PAGING_ENTRY_POINT_VIRT+stack_offset); + // User stack start at the end of last allocated page (since addresses are going down) + void *ustack=(void*)(PAGING_ENTRY_POINT_VIRT+allocated*4096); // Load the task into memory memcpy(task,PAGING_ENTRY_POINT_PHY(page_dir), task_size); @@ -119,6 +124,8 @@ void task_create(int *page_dir, void *task, int task_size, int stack_offset){ p->page_dir=page_dir; nproc++; } + else + print("Could not create more task!"); } void scheduler_start(){ |
