[kernel] Remove getpid and fork system calls

The getpid and fork system calls were stubbed out previously, this
commit removes them and adds process_koid as a getpid replacement.
This commit is contained in:
2020-07-19 17:15:36 -07:00
parent c3abe035c8
commit 4cf222a5bb
4 changed files with 19 additions and 61 deletions

View File

@@ -5,8 +5,7 @@
#include "j6/errors.h"
extern "C" {
j6_status_t getpid(uint64_t *);
j6_status_t fork(uint64_t *);
j6_status_t get_process_koid(j6_koid_t *koid);
j6_status_t sleep(uint64_t til);
j6_status_t debug();
j6_status_t message(const char *msg);
@@ -20,17 +19,14 @@ main(int argc, const char **argv)
{
uint64_t pid = 0;
uint64_t child = 0;
j6_koid_t process = 0;
j6_status_t result = fork(&child);
j6_status_t result = get_process_koid(&process);
if (result != j6_status_ok)
return result;
message("hello from nulldrv!");
result = getpid(&pid);
if (result != j6_status_ok)
return result;
for (int i = 1; i < 5; ++i)
sleep(i*10);

View File

@@ -6,13 +6,13 @@ extern main
extern exit
section .text
global getpid
getpid:
global get_process_koid
get_process_koid:
push rbp
mov rbp, rsp
; address of out var should already be in rdi
mov rax, 0x13 ; getpid syscall
mov rax, 0x10 ; getpid syscall
syscall ; result is now already in rax, so just return
pop rbp
@@ -34,32 +34,19 @@ sleep:
push rbp
mov rbp, rsp
mov rax, 0x16 ; sleep syscall
mov rax, 0x14 ; sleep syscall
syscall
pop rbp
ret
global fork
fork:
push rbp
mov rbp, rsp
; address of out var should already be in rdi
mov rax, 0x12
syscall ; result left in rax
pop rbp
ret
global message
message:
push rbp
mov rbp, rsp
; message should already be in rdi
mov rax, 0x14
mov rax, 0x12
syscall
pop rbp

View File

@@ -1,9 +1,8 @@
SYSCALL(0x00, object_noop, void)
SYSCALL(0x01, object_wait, j6_handle_t, j6_signal_t, j6_signal_t *)
SYSCALL(0x10, process_koid, j6_koid_t *)
SYSCALL(0x11, process_exit, int64_t)
SYSCALL(0x12, process_fork, uint32_t*)
SYSCALL(0x13, process_getpid, uint32_t*)
SYSCALL(0x14, process_log, const char *)
SYSCALL(0x15, process_pause, void)
SYSCALL(0x16, process_sleep, uint64_t)
SYSCALL(0x12, process_log, const char *)
SYSCALL(0x13, process_pause, void)
SYSCALL(0x14, process_sleep, uint64_t)

View File

@@ -1,6 +1,8 @@
#include "j6/errors.h"
#include "j6/types.h"
#include "objects/process.h"
#include "log.h"
#include "scheduler.h"
@@ -21,43 +23,20 @@ process_exit(int64_t status)
return j6_err_unexpected;
}
/*
j6_status_t
process_fork(pid_t *pid)
process_koid(j6_koid_t *koid)
{
if (pid == nullptr) {
if (koid == nullptr) {
return j6_err_invalid_arg;
}
auto &s = scheduler::get();
auto *p = s.current();
pid_t ppid = p->pid;
log::debug(logs::syscall, "Process %d calling fork(%016llx)", ppid, pid);
*pid = p->fork();
p = s.current();
log::debug(logs::syscall, "Process %d's fork: returning %d from process %d", ppid, *pid, p->pid);
TCB *tcb = scheduler::get().current();
process &p = thread::from_tcb(tcb)->parent();
*koid = p.koid();
return j6_status_ok;
}
j6_status_t
process_getpid(pid_t *pid)
{
if (pid == nullptr) {
return j6_err_invalid_arg;
}
auto &s = scheduler::get();
auto *p = s.current();
*pid = p->pid;
return j6_status_ok;
}
*/
j6_status_t
process_log(const char *message)
{
@@ -72,9 +51,6 @@ process_log(const char *message)
return j6_status_ok;
}
j6_status_t process_fork(uint32_t *pid) { *pid = 5; return process_log("CALLED FORK"); }
j6_status_t process_getpid(uint32_t *pid) { *pid = 0; return process_log("CALLED GETPID"); }
j6_status_t
process_pause()
{