2020-02-05 21:09:39 +01:00
|
|
|
#include <kernel/scheduler.h>
|
2020-03-23 15:58:48 +01:00
|
|
|
#include <kernel/util/atomic.h>
|
2020-03-15 00:56:31 +01:00
|
|
|
#include <kernel/devices/earlyterm.h>
|
2020-03-23 15:58:48 +01:00
|
|
|
#include <kernel/memory.h>
|
|
|
|
// TODO: remove / move me ?
|
2020-04-19 14:16:29 +02:00
|
|
|
#include <sys/wait.h>
|
2020-02-05 21:09:39 +01:00
|
|
|
|
|
|
|
void sys_exit(int status)
|
|
|
|
{
|
2020-03-23 15:58:48 +01:00
|
|
|
extern struct process *process_current;
|
2020-03-15 00:56:31 +01:00
|
|
|
|
|
|
|
// Fow now, just wait manual reset...
|
2020-03-23 15:58:48 +01:00
|
|
|
//earlyterm_clear();
|
|
|
|
//earlyterm_write("PROCESS EXIT SYSCALL !!!!\n");
|
|
|
|
//earlyterm_write("Wait manual reset...");
|
|
|
|
|
|
|
|
// Start atomic operation
|
|
|
|
atomic_start();
|
|
|
|
|
|
|
|
// Generate stat_loc
|
2020-03-28 19:52:59 +01:00
|
|
|
// TODO: signal
|
2020-03-23 15:58:48 +01:00
|
|
|
process_current->__stat_loc = __W_EXITCODE(status, 0);
|
|
|
|
|
|
|
|
// Frre'd all allocated space
|
2020-03-28 19:52:59 +01:00
|
|
|
pm_pages_free(process_current->memory.stack.user);
|
|
|
|
pm_pages_free(process_current->memory.stack.kernel);
|
|
|
|
pm_pages_free(process_current->memory.program.start);
|
|
|
|
pm_pages_free(process_current->memory.exit.start);
|
2020-03-23 15:58:48 +01:00
|
|
|
|
|
|
|
// Change process state
|
|
|
|
process_current->status = PROC_ZOMBIE;
|
|
|
|
|
|
|
|
// Stop atomic operation
|
|
|
|
atomic_stop();
|
2020-02-05 21:09:39 +01:00
|
|
|
while (1);
|
|
|
|
}
|