mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
The getpid and fork system calls were stubbed out previously, this commit removes them and adds process_koid as a getpid replacement.
79 lines
1.5 KiB
C++
79 lines
1.5 KiB
C++
#include "j6/errors.h"
|
|
#include "j6/types.h"
|
|
|
|
#include "objects/process.h"
|
|
|
|
#include "log.h"
|
|
#include "scheduler.h"
|
|
|
|
namespace syscalls {
|
|
|
|
j6_status_t
|
|
process_exit(int64_t status)
|
|
{
|
|
auto &s = scheduler::get();
|
|
TCB *tcb = s.current();
|
|
thread *th = thread::from_tcb(tcb);
|
|
log::debug(logs::syscall, "Thread %llx exiting with code %d", th->koid(), status);
|
|
|
|
th->exit(status);
|
|
s.schedule();
|
|
|
|
log::error(logs::syscall, "returned to exit syscall");
|
|
return j6_err_unexpected;
|
|
}
|
|
|
|
j6_status_t
|
|
process_koid(j6_koid_t *koid)
|
|
{
|
|
if (koid == nullptr) {
|
|
return j6_err_invalid_arg;
|
|
}
|
|
|
|
TCB *tcb = scheduler::get().current();
|
|
process &p = thread::from_tcb(tcb)->parent();
|
|
|
|
*koid = p.koid();
|
|
return j6_status_ok;
|
|
}
|
|
|
|
j6_status_t
|
|
process_log(const char *message)
|
|
{
|
|
if (message == nullptr) {
|
|
return j6_err_invalid_arg;
|
|
}
|
|
|
|
auto &s = scheduler::get();
|
|
TCB *tcb = s.current();
|
|
thread *th = thread::from_tcb(tcb);
|
|
log::info(logs::syscall, "Message[%llx]: %s", th->koid(), message);
|
|
return j6_status_ok;
|
|
}
|
|
|
|
j6_status_t
|
|
process_pause()
|
|
{
|
|
auto &s = scheduler::get();
|
|
TCB *tcb = s.current();
|
|
thread *th = thread::from_tcb(tcb);
|
|
th->wait_on_signals(th, -1ull);
|
|
s.schedule();
|
|
return j6_status_ok;
|
|
}
|
|
|
|
j6_status_t
|
|
process_sleep(uint64_t til)
|
|
{
|
|
auto &s = scheduler::get();
|
|
TCB *tcb = s.current();
|
|
thread *th = thread::from_tcb(tcb);
|
|
log::debug(logs::syscall, "Thread %llx sleeping until %llu", th->koid(), til);
|
|
|
|
th->wait_on_time(til);
|
|
s.schedule();
|
|
return j6_status_ok;
|
|
}
|
|
|
|
} // namespace syscalls
|