|
|
|
@ -180,7 +180,8 @@ void mark_ecall_entry()
|
|
|
|
|
scheduling_interrupted_start = read_time();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
optional_pcbptr find_available_pcb_slot() {
|
|
|
|
|
optional_pcbptr find_available_pcb_slot()
|
|
|
|
|
{
|
|
|
|
|
static int index = 0;
|
|
|
|
|
int start_index = index;
|
|
|
|
|
ProcessControlBlock* pcb = processes + index;
|
|
|
|
@ -200,6 +201,7 @@ optional_pcbptr create_new_process(loaded_binary* bin, int stack_size)
|
|
|
|
|
{
|
|
|
|
|
// try to get a position in the processes list
|
|
|
|
|
optional_pcbptr slot_or_err = find_available_pcb_slot();
|
|
|
|
|
|
|
|
|
|
// if that failed, we cannot creat a new process
|
|
|
|
|
if (has_error(slot_or_err)) {
|
|
|
|
|
dbgln("No more process structs!", 24);
|
|
|
|
@ -208,6 +210,7 @@ optional_pcbptr create_new_process(loaded_binary* bin, int stack_size)
|
|
|
|
|
|
|
|
|
|
// allocate stack for the new process
|
|
|
|
|
optional_voidptr stack_top_or_err = malloc_stack(stack_size); // allocate 4Kib stack
|
|
|
|
|
|
|
|
|
|
// if that failed, we also can't create a new process
|
|
|
|
|
if (has_error(stack_top_or_err)) {
|
|
|
|
|
dbgln("Error while allocating stack for process", 40);
|
|
|
|
@ -242,6 +245,7 @@ optional_pcbptr create_new_thread(ProcessControlBlock* parent, void* entrypoint,
|
|
|
|
|
{
|
|
|
|
|
// try to get a position in the processes list
|
|
|
|
|
optional_pcbptr slot_or_err = find_available_pcb_slot();
|
|
|
|
|
|
|
|
|
|
// if that failed, we cannot creat a new process
|
|
|
|
|
if (has_error(slot_or_err)) {
|
|
|
|
|
dbgln("No more process structs!", 24);
|
|
|
|
@ -250,6 +254,7 @@ optional_pcbptr create_new_thread(ProcessControlBlock* parent, void* entrypoint,
|
|
|
|
|
|
|
|
|
|
// allocate stack for the new process
|
|
|
|
|
optional_voidptr stack_top_or_err = malloc_stack(stack_size); // allocate 4Kib stack
|
|
|
|
|
|
|
|
|
|
// if that failed, we also can't create a new process
|
|
|
|
|
if (has_error(stack_top_or_err)) {
|
|
|
|
|
dbgln("Error while allocating stack for thread", 39);
|
|
|
|
|