Add a very basic exit function and fix kmalloc.
Exit function does not deallocate task memory except for the data block, and does not are about the exit code except for logging.
This commit is contained in:
parent
5a5fee4d74
commit
3ca8b5a232
22
.gdbinit
22
.gdbinit
@ -1,25 +1,3 @@
|
||||
set pagination off
|
||||
target remote localhost:1234
|
||||
symbol-file kernel/kernel.elf
|
||||
add-symbol-file vfs/vfs
|
||||
b kernel/cpu/i386/tasking.c:132
|
||||
b kernel/cpu/i386/tasking.c:143
|
||||
commands 1 2
|
||||
silent
|
||||
disable breakpoints
|
||||
symbol-file kernel/kernel.elf
|
||||
p task->pid
|
||||
if task->pid==2
|
||||
add-symbol-file vfs/vfs
|
||||
enable breakpoints
|
||||
else
|
||||
enable breakpoints 1
|
||||
c
|
||||
end
|
||||
c
|
||||
end
|
||||
|
||||
b main
|
||||
commands
|
||||
disable breakpoints 1
|
||||
end
|
||||
|
@ -230,6 +230,8 @@ void isr_handler(registers_t r) {
|
||||
tasking_yieldToPID(r.ebx);
|
||||
} else if (r.eax==16) {
|
||||
serial_write_string((char*)r.ebx);
|
||||
} else if (r.eax==17) {
|
||||
tasking_exit((uint8_t)r.ebx);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ void* kmalloc(uint32_t size) {
|
||||
}
|
||||
|
||||
void kfree(void* mem) {
|
||||
uint32_t* info=(uint32_t*)((uint32_t)mem-12);
|
||||
uint32_t* info=(uint32_t*)((uint32_t)mem-8);
|
||||
uint32_t num_4b_grps=info[0];
|
||||
uint32_t bmap_index=info[1];
|
||||
for (uint32_t i=0;i<num_4b_grps;i++) {
|
||||
|
@ -145,6 +145,29 @@ void tasking_yieldToPID(uint32_t pid) {
|
||||
switch_to_task(task);
|
||||
}
|
||||
|
||||
void tasking_exit(uint8_t code) {
|
||||
serial_printf("PID %d is exiting with code %d.\n",currentTask->pid,code);
|
||||
if (currentTask->prev) {
|
||||
currentTask->prev->next=currentTask->next;
|
||||
}
|
||||
if (currentTask->next) {
|
||||
currentTask->next->prev=currentTask->prev;
|
||||
}
|
||||
if (headTask==currentTask) {
|
||||
if (!currentTask->next) {
|
||||
serial_write_string("ERROR! Head task exited with no child tasks! Halting!\n");
|
||||
vga_write_string("ERROR! Head task exited with no child tasks! Halting!\n");
|
||||
halt();
|
||||
}
|
||||
headTask=currentTask->next;
|
||||
}
|
||||
Task* task=currentTask->next;
|
||||
kfree(currentTask);
|
||||
serial_printf("Exit yielding to PID %d.\n",task->pid);
|
||||
load_smap(task->cr3);
|
||||
switch_to_task(task);
|
||||
}
|
||||
|
||||
uint32_t getPID() {
|
||||
return currentTask->pid;
|
||||
}
|
||||
|
@ -11,4 +11,5 @@ Task* tasking_createTask(void* eip);
|
||||
Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg);
|
||||
char isPrivleged(uint32_t pid);
|
||||
uint32_t getPID();
|
||||
void tasking_exit(uint8_t code);
|
||||
#endif
|
||||
|
@ -106,6 +106,7 @@ void kmain(struct multiboot_boot_header_tag* hdr) {
|
||||
memcpy(initrd2,initrd,initrd_sz);
|
||||
initrd2=put_data(cr3,initrd2,initrd_sz);
|
||||
createTaskCr3Param((void*)header.entry,cr3,(uint32_t)initrd2,initrd_sz);
|
||||
exit(1);
|
||||
for(;;) {
|
||||
yield();
|
||||
}
|
||||
|
@ -34,3 +34,10 @@ void yieldToPID(uint32_t pid) {
|
||||
int $80; \
|
||||
"::"b"(pid));
|
||||
}
|
||||
|
||||
void exit(uint8_t code) {
|
||||
asm volatile(" \
|
||||
mov $17, %%eax; \
|
||||
int $80; \
|
||||
"::"b"(code));
|
||||
}
|
||||
|
@ -2,11 +2,14 @@
|
||||
#define STDLIB_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_FAILURE 1
|
||||
|
||||
void* malloc(size_t size);
|
||||
void* realloc(void *mem, size_t new_sz);
|
||||
void free(void* mem);
|
||||
void exit(uint8_t code);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user