kernel+libc+init: Add getppid() and wait()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-24 17:39:55 +01:00
parent 7efcc06090
commit e76ccd6c4c
Signed by: apio
GPG Key ID: B8A7D06E42258954
7 changed files with 23 additions and 2 deletions

View File

@ -47,5 +47,5 @@ int main()
return 1;
}
while (1) { waitpid(-1, NULL, 0); }
while (1) wait(NULL);
}

View File

@ -5,3 +5,8 @@ Result<u64> sys_getpid(Registers*, SyscallArgs)
{
return Scheduler::current()->id;
}
Result<u64> sys_getppid(Registers*, SyscallArgs)
{
return Scheduler::current()->parent_id;
}

View File

@ -14,6 +14,9 @@ extern "C"
/* Wait for a child process to exit. */
pid_t waitpid(pid_t pid, int* status, int options);
/* Wait for any child process to exit. */
pid_t wait(int* status);
#ifdef __cplusplus
}
#endif

View File

@ -25,6 +25,9 @@ extern "C"
/* Return the current process' process ID. */
pid_t getpid(void);
/* Return the current process' parent process ID. */
pid_t getppid(void);
/* Replace the current process with another one. On success, does not return. */
int execv(const char* path, char* const* argv);

View File

@ -10,4 +10,9 @@ extern "C"
long rc = syscall(SYS_waitpid, pid, status, options);
__errno_return(rc, pid_t);
}
pid_t wait(int* status)
{
return waitpid(-1, status, 0);
}
}

View File

@ -19,6 +19,11 @@ extern "C"
return (pid_t)syscall(SYS_getpid);
}
pid_t getppid(void)
{
return (pid_t)syscall(SYS_getppid);
}
int execv(const char* path, char* const* argv)
{
long rc = syscall(SYS_exec, path, argv);

View File

@ -2,7 +2,7 @@
#define enumerate_syscalls(_e) \
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \
_e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid)
_e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid) _e(getppid)
enum Syscalls
{