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:
parent
b68d5a5833
commit
cbb9f47ee5
|
@ -10,6 +10,7 @@ set(LIBC_SOURCES
|
|||
stdio.cpp
|
||||
stdlib.cpp
|
||||
string.cpp
|
||||
sys/wait.cpp
|
||||
termios.cpp
|
||||
unistd.cpp
|
||||
math.S
|
||||
|
|
|
@ -21,6 +21,7 @@ __BEGIN_DECLS
|
|||
#define SYS_SLEEP 14
|
||||
#define SYS_EXEC 15
|
||||
#define SYS_REALLOC 16
|
||||
#define SYS_WAIT 17
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -20,11 +20,12 @@ __BEGIN_DECLS
|
|||
#define WNOWAIT 0x10
|
||||
#define WSTOPPED 0x20
|
||||
|
||||
#define WEXITSTATUS(status) (status & 0xFF)
|
||||
#define WIFEXITED(status) (WEXITSTATUS(status) != 0)
|
||||
|
||||
// FIXME
|
||||
#if 0
|
||||
#define WEXITSTATUS
|
||||
#define WIFCONTINUED
|
||||
#define WIFEXITED
|
||||
#define WIFSIGNALED
|
||||
#define WIFSTOPPED
|
||||
#define WSTOPSIG
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -137,6 +137,14 @@ long syscall(long syscall, ...)
|
|||
ret = Kernel::syscall(SYS_REALLOC, (uintptr_t)ptr, size);
|
||||
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:
|
||||
puts("LibC: Unhandeled syscall");
|
||||
ret = -ENOSYS;
|
||||
|
|
Loading…
Reference in New Issue