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

This commit is contained in:
apio 2023-03-11 22:19:58 +01:00
parent 8fa72f3cf0
commit c0a7f6776f
Signed by: apio
GPG Key ID: B8A7D06E42258954
7 changed files with 19 additions and 4 deletions

View File

@ -12,7 +12,7 @@ void bye()
int main()
{
atexit(bye);
printf("Welcome to %s from userspace!\n", "Luna");
printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid());
int fd = open("/etc/motd", 0);
if (fd < 0)

View File

@ -1 +1 @@
G'day mate!
Hello, world!

View File

@ -28,6 +28,7 @@ set(SOURCES
src/sys/usleep.cpp
src/sys/open.cpp
src/sys/file.cpp
src/sys/id.cpp
src/fs/VFS.cpp
src/fs/tmpfs/FileSystem.cpp
src/InitRD.cpp

7
kernel/src/sys/id.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "sys/Syscall.h"
#include "thread/Scheduler.h"
Result<u64> sys_getpid(Registers*, SyscallArgs)
{
return Scheduler::current()->id;
}

View File

@ -15,7 +15,9 @@ extern "C"
#endif
pid_t fork();
pid_t getpid();
/* Returns the current process' process ID. */
pid_t getpid(void);
int execv(const char*, char* const*);
int execve(const char*, char* const*, char* const*);

View File

@ -8,6 +8,11 @@ extern "C" long arch_invoke_syscall(long, uintptr_t, uintptr_t, uintptr_t, uintp
extern "C"
{
pid_t getpid(void)
{
return (pid_t)syscall(SYS_getpid);
}
long syscall(long num, ...)
{
va_list ap;

View File

@ -2,7 +2,7 @@
#define enumerate_syscalls(_e) \
_e(exit) _e(console_write) _e(clock_gettime) _e(allocate_memory) _e(deallocate_memory) _e(usleep) _e(open) \
_e(close) _e(read)
_e(close) _e(read) _e(getpid)
enum Syscalls
{