2023-12-31 16:58:02 +01:00
|
|
|
#include "KernelContext.hpp"
|
2023-07-03 13:10:16 +02:00
|
|
|
#include "sys/sysproto.hpp"
|
2025-04-05 21:50:45 +02:00
|
|
|
#include "thread/Process.hpp"
|
2024-01-13 18:57:02 +01:00
|
|
|
#include "thread/ProcessOps.hpp"
|
2023-10-31 19:32:43 +01:00
|
|
|
#include "utils/Logs.hpp"
|
2024-01-04 01:53:58 +01:00
|
|
|
#include <sys/resource.h>
|
2023-12-31 16:58:02 +01:00
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include <unistd.h>
|
2023-07-03 13:10:16 +02:00
|
|
|
|
|
|
|
|
orbis::SysResult orbis::sys_exit(Thread *thread, sint status) {
|
|
|
|
|
if (auto exit = thread->tproc->ops->exit) {
|
|
|
|
|
return exit(thread, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ErrorCode::NOSYS;
|
|
|
|
|
}
|
2023-07-06 18:16:25 +02:00
|
|
|
orbis::SysResult orbis::sys_abort2(Thread *thread, ptr<const char> why,
|
|
|
|
|
sint narg, ptr<ptr<void>> args) {
|
|
|
|
|
return ErrorCode::NOSYS;
|
|
|
|
|
}
|
|
|
|
|
orbis::SysResult orbis::sys_wait4(Thread *thread, sint pid, ptr<sint> status,
|
|
|
|
|
sint options, ptr<struct rusage> rusage) {
|
2023-10-31 19:32:43 +01:00
|
|
|
// TODO
|
|
|
|
|
ORBIS_LOG_ERROR(__FUNCTION__, pid, status, options, rusage);
|
2023-12-31 16:58:02 +01:00
|
|
|
|
|
|
|
|
int hostPid = pid;
|
|
|
|
|
if (pid > 0) {
|
2025-10-10 18:56:11 +02:00
|
|
|
auto process = g_context->findProcessById(pid);
|
2023-12-31 16:58:02 +01:00
|
|
|
if (process == nullptr) {
|
|
|
|
|
return ErrorCode::SRCH;
|
|
|
|
|
}
|
|
|
|
|
hostPid = process->hostPid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::rusage hostUsage;
|
2024-01-04 01:53:58 +01:00
|
|
|
while (true) {
|
|
|
|
|
int stat;
|
|
|
|
|
int result = ::wait4(hostPid, &stat, options, &hostUsage);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
return static_cast<ErrorCode>(errno);
|
|
|
|
|
}
|
2023-12-31 16:58:02 +01:00
|
|
|
|
2024-01-04 01:53:58 +01:00
|
|
|
ORBIS_LOG_ERROR(__FUNCTION__, pid, status, options, rusage, result, stat);
|
2023-12-31 16:58:02 +01:00
|
|
|
|
2025-10-10 18:56:11 +02:00
|
|
|
auto process = g_context->findProcessByHostId(result);
|
2024-01-04 01:53:58 +01:00
|
|
|
if (process == nullptr) {
|
|
|
|
|
ORBIS_LOG_ERROR("host process not found", result);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-12-31 16:58:02 +01:00
|
|
|
|
2024-01-04 01:53:58 +01:00
|
|
|
if (status != nullptr) {
|
|
|
|
|
ORBIS_RET_ON_ERROR(uwrite(status, stat));
|
|
|
|
|
}
|
|
|
|
|
thread->retval[0] = process->pid;
|
|
|
|
|
break;
|
2023-12-31 16:58:02 +01:00
|
|
|
}
|
2024-01-04 01:53:58 +01:00
|
|
|
|
2023-10-31 19:32:43 +01:00
|
|
|
return {};
|
2023-07-06 18:16:25 +02:00
|
|
|
}
|