kernel+libc: Add getpid()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8fa72f3cf0
commit
c0a7f6776f
@ -12,7 +12,7 @@ void bye()
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
atexit(bye);
|
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);
|
int fd = open("/etc/motd", 0);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -1 +1 @@
|
|||||||
G'day mate!
|
Hello, world!
|
||||||
|
@ -28,6 +28,7 @@ set(SOURCES
|
|||||||
src/sys/usleep.cpp
|
src/sys/usleep.cpp
|
||||||
src/sys/open.cpp
|
src/sys/open.cpp
|
||||||
src/sys/file.cpp
|
src/sys/file.cpp
|
||||||
|
src/sys/id.cpp
|
||||||
src/fs/VFS.cpp
|
src/fs/VFS.cpp
|
||||||
src/fs/tmpfs/FileSystem.cpp
|
src/fs/tmpfs/FileSystem.cpp
|
||||||
src/InitRD.cpp
|
src/InitRD.cpp
|
||||||
|
7
kernel/src/sys/id.cpp
Normal file
7
kernel/src/sys/id.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "sys/Syscall.h"
|
||||||
|
#include "thread/Scheduler.h"
|
||||||
|
|
||||||
|
Result<u64> sys_getpid(Registers*, SyscallArgs)
|
||||||
|
{
|
||||||
|
return Scheduler::current()->id;
|
||||||
|
}
|
@ -15,7 +15,9 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
pid_t fork();
|
pid_t fork();
|
||||||
pid_t getpid();
|
|
||||||
|
/* Returns the current process' process ID. */
|
||||||
|
pid_t getpid(void);
|
||||||
|
|
||||||
int execv(const char*, char* const*);
|
int execv(const char*, char* const*);
|
||||||
int execve(const char*, char* const*, char* const*);
|
int execve(const char*, char* const*, char* const*);
|
||||||
|
@ -8,6 +8,11 @@ extern "C" long arch_invoke_syscall(long, uintptr_t, uintptr_t, uintptr_t, uintp
|
|||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
pid_t getpid(void)
|
||||||
|
{
|
||||||
|
return (pid_t)syscall(SYS_getpid);
|
||||||
|
}
|
||||||
|
|
||||||
long syscall(long num, ...)
|
long syscall(long num, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#define enumerate_syscalls(_e) \
|
#define enumerate_syscalls(_e) \
|
||||||
_e(exit) _e(console_write) _e(clock_gettime) _e(allocate_memory) _e(deallocate_memory) _e(usleep) _e(open) \
|
_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
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user