LibC: add wait and waitpid

Note that wait() doesn't work since only waiting for specified
pid is supported. wait() will just return -1 and set errno to
ECHILD.
This commit is contained in:
Bananymous 2023-06-04 17:59:13 +03:00
parent b68d5a5833
commit cbb9f47ee5
5 changed files with 26 additions and 2 deletions

View File

@ -10,6 +10,7 @@ set(LIBC_SOURCES
stdio.cpp stdio.cpp
stdlib.cpp stdlib.cpp
string.cpp string.cpp
sys/wait.cpp
termios.cpp termios.cpp
unistd.cpp unistd.cpp
math.S math.S

View File

@ -21,6 +21,7 @@ __BEGIN_DECLS
#define SYS_SLEEP 14 #define SYS_SLEEP 14
#define SYS_EXEC 15 #define SYS_EXEC 15
#define SYS_REALLOC 16 #define SYS_REALLOC 16
#define SYS_WAIT 17
__END_DECLS __END_DECLS

View File

@ -20,11 +20,12 @@ __BEGIN_DECLS
#define WNOWAIT 0x10 #define WNOWAIT 0x10
#define WSTOPPED 0x20 #define WSTOPPED 0x20
#define WEXITSTATUS(status) (status & 0xFF)
#define WIFEXITED(status) (WEXITSTATUS(status) != 0)
// FIXME // FIXME
#if 0 #if 0
#define WEXITSTATUS
#define WIFCONTINUED #define WIFCONTINUED
#define WIFEXITED
#define WIFSIGNALED #define WIFSIGNALED
#define WIFSTOPPED #define WIFSTOPPED
#define WSTOPSIG #define WSTOPSIG

13
libc/sys/wait.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
pid_t wait(int* stat_loc)
{
return waitpid(-1, stat_loc, 0);
}
pid_t waitpid(pid_t pid, int* stat_loc, int options)
{
return (pid_t)syscall(SYS_WAIT, pid, stat_loc, options);
}

View File

@ -137,6 +137,14 @@ long syscall(long syscall, ...)
ret = Kernel::syscall(SYS_REALLOC, (uintptr_t)ptr, size); ret = Kernel::syscall(SYS_REALLOC, (uintptr_t)ptr, size);
break; break;
} }
case SYS_WAIT:
{
pid_t pid = va_arg(args, pid_t);
int* stat_loc = va_arg(args, int*);
int options = va_arg(args, int);
ret = Kernel::syscall(SYS_WAIT, pid, (uintptr_t)stat_loc, options);
break;
}
default: default:
puts("LibC: Unhandeled syscall"); puts("LibC: Unhandeled syscall");
ret = -ENOSYS; ret = -ENOSYS;