Merge pull request #242 from tkchia/tkchia/self-host

Add fork, wait, waitpid for all Linux targets, & execl for linux386.
This commit is contained in:
David Given 2022-01-19 22:17:48 +01:00 committed by GitHub
commit 612c47371e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 0 deletions

View file

@ -13,6 +13,7 @@ addheader("ack/fcntl.h")
addheader("ack/signal.h") addheader("ack/signal.h")
addheader("sys/ioctl.h") addheader("sys/ioctl.h")
addheader("sys/types.h") addheader("sys/types.h")
addheader("sys/wait.h")
acklibrary { acklibrary {

View file

@ -0,0 +1,19 @@
#ifndef _SYS_WAIT_H
#define _SYS_WAIT_H
#include <sys/types.h>
extern pid_t wait(int *__wstatus);
extern pid_t waitpid(pid_t __pid, int *__wstatus, int __options);
#define WNOHANG (1 << 0)
#define WUNTRACED (1 << 1)
#define WSTOPPED WUNTRACED
#define WEXITED (1 << 2)
#define WCONTINUED (1 << 3)
#define WNOWAIT (1 << 24)
#define __WNOTHREAD (1 << 29)
#define __WALL (1 << 30)
#define __WCLONE (1 << 31)
#endif

8
plat/linux/libsys/fork.c Normal file
View file

@ -0,0 +1,8 @@
#include <sys/types.h>
#include <unistd.h>
#include "libsys.h"
pid_t fork(void)
{
return (pid_t) _syscall(__NR_fork, 0, 0, 0);
}

7
plat/linux/libsys/wait.c Normal file
View file

@ -0,0 +1,7 @@
#include <sys/wait.h>
#include "libsys.h"
pid_t wait(int *wstatus)
{
return (pid_t) _syscall(__NR_waitpid, -1, (quad) wstatus, 0);
}

View file

@ -0,0 +1,7 @@
#include <sys/wait.h>
#include "libsys.h"
pid_t waitpid(pid_t pid, int *wstatus, int options)
{
return (pid_t) _syscall(__NR_waitpid, pid, (quad) wstatus, options);
}

View file

@ -0,0 +1,29 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
__NR_execve = 11
! Perform a execl by invoking Linux's execve system call.
.define _execl
_execl:
lea eax, 8(esp)
push (_environ) ! envp
push eax ! argv
push -4(eax) ! pathname
push __NR_execve
call __syscall
add esp, 16
ret

View file

@ -7,6 +7,7 @@ acklibrary {
"plat/linux/libsys/close.c", "plat/linux/libsys/close.c",
"plat/linux/libsys/creat.c", "plat/linux/libsys/creat.c",
"plat/linux/libsys/execve.c", "plat/linux/libsys/execve.c",
"plat/linux/libsys/fork.c",
"plat/linux/libsys/getpid.c", "plat/linux/libsys/getpid.c",
"plat/linux/libsys/gettimeofday.c", "plat/linux/libsys/gettimeofday.c",
"plat/linux/libsys/ioctl.c", "plat/linux/libsys/ioctl.c",
@ -19,6 +20,8 @@ acklibrary {
"plat/linux/libsys/signal.c", "plat/linux/libsys/signal.c",
"plat/linux/libsys/sigprocmask.c", "plat/linux/libsys/sigprocmask.c",
"plat/linux/libsys/unlink.c", "plat/linux/libsys/unlink.c",
"plat/linux/libsys/wait.c",
"plat/linux/libsys/waitpid.c",
"plat/linux/libsys/write.c", "plat/linux/libsys/write.c",
}, },
deps = { deps = {

View file

@ -8,6 +8,7 @@ acklibrary {
"plat/linux/libsys/_hol0.s", "plat/linux/libsys/_hol0.s",
"plat/linux/libsys/close.c", "plat/linux/libsys/close.c",
"plat/linux/libsys/creat.c", "plat/linux/libsys/creat.c",
"plat/linux/libsys/fork.c",
"plat/linux/libsys/execve.c", "plat/linux/libsys/execve.c",
"plat/linux/libsys/getpid.c", "plat/linux/libsys/getpid.c",
"plat/linux/libsys/gettimeofday.c", "plat/linux/libsys/gettimeofday.c",
@ -21,6 +22,8 @@ acklibrary {
-- omit signal.c -- omit signal.c
"plat/linux/libsys/sigprocmask.c", "plat/linux/libsys/sigprocmask.c",
"plat/linux/libsys/unlink.c", "plat/linux/libsys/unlink.c",
"plat/linux/libsys/wait.c",
"plat/linux/libsys/waitpid.c",
"plat/linux/libsys/write.c", "plat/linux/libsys/write.c",
}, },
deps = { deps = {