2023-06-20 14:01:43 -07:00
|
|
|
#include "syscall/process.h"
|
|
|
|
|
2023-06-20 15:50:49 -07:00
|
|
|
#include "capability/capability.h"
|
2023-06-26 15:01:55 -07:00
|
|
|
#include "debug/debug.h"
|
2023-11-24 15:04:03 -08:00
|
|
|
#include "scheduler/cleanup.h"
|
2023-06-20 14:01:43 -07:00
|
|
|
#include "scheduler/process_manager.h"
|
|
|
|
#include "scheduler/scheduler.h"
|
|
|
|
|
|
|
|
z_err_t ProcessExit(ZProcessExitReq* req) {
|
|
|
|
auto curr_thread = gScheduler->CurrentThread();
|
2023-11-22 12:17:10 -08:00
|
|
|
dbgln("Exit code: {}", static_cast<glcr::ErrorCode>(req->code));
|
2023-12-01 11:36:27 -08:00
|
|
|
curr_thread->process().Exit(req->code);
|
2023-06-20 14:01:43 -07:00
|
|
|
panic("Returned from thread exit");
|
2023-06-21 18:28:54 -07:00
|
|
|
return glcr::UNIMPLEMENTED;
|
2023-06-20 14:01:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
z_err_t ProcessSpawn(ZProcessSpawnReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
|
|
|
auto cap = curr_proc.GetCapability(req->proc_cap);
|
2023-08-01 18:22:41 -07:00
|
|
|
RET_ERR(ValidateCapability<Process>(cap, kZionPerm_SpawnProcess));
|
2023-06-20 14:01:43 -07:00
|
|
|
|
2023-06-21 15:07:40 -07:00
|
|
|
glcr::RefPtr<Process> proc = Process::Create();
|
2023-06-20 14:01:43 -07:00
|
|
|
gProcMan->InsertProcess(proc);
|
|
|
|
|
2023-08-01 18:22:41 -07:00
|
|
|
*req->new_proc_cap = curr_proc.AddNewCapability(proc);
|
|
|
|
*req->new_vmas_cap = curr_proc.AddNewCapability(proc->vmas());
|
2023-06-20 14:01:43 -07:00
|
|
|
|
|
|
|
if (req->bootstrap_cap != 0) {
|
2023-08-01 18:37:17 -07:00
|
|
|
auto cap = curr_proc.GetCapability(req->bootstrap_cap);
|
2023-06-20 14:01:43 -07:00
|
|
|
if (!cap) {
|
2023-06-21 18:28:54 -07:00
|
|
|
return glcr::CAP_NOT_FOUND;
|
2023-06-20 14:01:43 -07:00
|
|
|
}
|
2023-08-01 18:37:17 -07:00
|
|
|
if (!(cap->HasPermissions(kZionPerm_Transmit))) {
|
|
|
|
return glcr::CAP_PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
*req->new_bootstrap_cap = proc->AddExistingCapability(
|
|
|
|
curr_proc.ReleaseCapability(req->bootstrap_cap));
|
2023-06-20 14:01:43 -07:00
|
|
|
}
|
|
|
|
|
2023-06-21 18:28:54 -07:00
|
|
|
return glcr::OK;
|
2023-06-20 14:01:43 -07:00
|
|
|
}
|
2023-12-01 11:36:27 -08:00
|
|
|
|
|
|
|
z_err_t ProcessWait(ZProcessWaitReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
|
|
|
auto cap = curr_proc.GetCapability(req->proc_cap);
|
|
|
|
RET_ERR(ValidateCapability<Process>(cap, kZionPerm_Read));
|
|
|
|
|
|
|
|
auto proc = cap->obj<Process>();
|
|
|
|
if (proc->id() == curr_proc.id()) {
|
|
|
|
return glcr::INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
proc->GetThread(0)->Wait();
|
|
|
|
*req->exit_code = proc->exit_code();
|
|
|
|
return glcr::OK;
|
|
|
|
}
|