2020-02-05 21:09:39 +01:00
|
|
|
#include <kernel/process.h>
|
|
|
|
#include <kernel/scheduler.h>
|
|
|
|
#include <kernel/loader.h>
|
2020-02-24 00:05:27 +01:00
|
|
|
#include <kernel/util/atomic.h>
|
2020-03-15 00:56:31 +01:00
|
|
|
#include <kernel/devices/earlyterm.h>
|
2020-02-05 21:09:39 +01:00
|
|
|
|
|
|
|
pid_t sys_fexecve(const char *pathname)
|
|
|
|
{
|
|
|
|
struct process *proc;
|
|
|
|
pid_t child_pid;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
// Start atomic operation
|
|
|
|
atomic_start();
|
|
|
|
|
|
|
|
// Try create new process
|
|
|
|
proc = process_create(pathname);
|
|
|
|
if (proc == NULL)
|
|
|
|
{
|
2020-03-15 00:56:31 +01:00
|
|
|
earlyterm_write("sys_fexecve: alloc error !");
|
2020-02-05 21:09:39 +01:00
|
|
|
DBG_WAIT;
|
|
|
|
atomic_stop();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to load binary into physical memory
|
2020-03-15 00:56:31 +01:00
|
|
|
if (loader(proc, pathname) != 0)
|
2020-02-05 21:09:39 +01:00
|
|
|
{
|
2020-03-15 00:56:31 +01:00
|
|
|
earlyterm_write("sys_fexecve: loader error !");
|
2020-02-05 21:09:39 +01:00
|
|
|
DBG_WAIT;
|
|
|
|
process_free(proc);
|
|
|
|
atomic_stop();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Debug
|
2020-03-15 00:56:31 +01:00
|
|
|
earlyterm_write("New proc loaded !");
|
2020-02-05 21:09:39 +01:00
|
|
|
DBG_WAIT;
|
|
|
|
|
|
|
|
// Add new process into task queue
|
|
|
|
error = sched_add_task(proc);
|
|
|
|
if (error != 0)
|
|
|
|
{
|
2020-03-15 00:56:31 +01:00
|
|
|
earlyterm_write("sys_fexecve: scheduler error !");
|
2020-02-05 21:09:39 +01:00
|
|
|
DBG_WAIT;
|
|
|
|
process_free(proc);
|
|
|
|
atomic_stop();
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get child process PID
|
|
|
|
child_pid = process_get_pid(proc);
|
|
|
|
|
|
|
|
// Debug
|
2020-03-15 00:56:31 +01:00
|
|
|
earlyterm_write("New proc sched added !");
|
|
|
|
earlyterm_write("New proc PID = %#x !", child_pid);
|
2020-02-05 21:09:39 +01:00
|
|
|
DBG_WAIT;
|
|
|
|
|
|
|
|
// Stop atomic operations
|
|
|
|
atomic_stop();
|
|
|
|
return (child_pid);
|
|
|
|
}
|