add support of the system call "fork" in libgloss

This commit is contained in:
Stefan Lankes 2011-02-18 10:00:09 +01:00
parent 520924b5d9
commit 5f99201f9e
9 changed files with 40 additions and 5 deletions

View file

@ -38,6 +38,7 @@ extern "C" {
#define __NR_kill 9
#define __NR_fstat 10
#define __NR_sbrk 11
#define __NR_fork 12
#ifdef __cplusplus
}

View file

@ -21,6 +21,7 @@
#include <metalsvm/stdio.h>
#include <metalsvm/syscall.h>
#include <metalsvm/tasks.h>
#include <metalsvm/errno.h>
static int sys_write(int fildes, const char *buf, size_t len)
{
@ -38,7 +39,7 @@ static int sys_write(int fildes, const char *buf, size_t len)
int syscall_handler(uint32_t sys_nr, ...)
{
int ret = -1;
int ret = -EINVAL;
va_list vl;
va_start(vl, sys_nr);
@ -66,10 +67,11 @@ int syscall_handler(uint32_t sys_nr, ...)
case __NR_getpid:
ret = per_core(current_task)->id;
break;
case __NR_fork:
case __NR_fstat:
default:
kputs("invalid system call\n");
ret = -1;
ret = -EINVAL;
break;
};

View file

@ -21,13 +21,19 @@
#include "syscall.h"
#include <_ansi.h>
#include <_syslist.h>
#undef errno
extern int errno;
_VOID
_DEFUN (_exit, (rc),
int rc)
{
int ret;
/* task exit */
SYSCALL1(__NR_exit, rc);
ret = SYSCALL1(__NR_exit, rc);
if (ret < 0)
errno = -ret;
/* Convince GCC that this function never returns. */
for (;;)

View file

@ -33,6 +33,10 @@ _DEFUN (close, (fildes),
int ret;
ret = SYSCALL1(__NR_close, fildes);
if (ret < 0) {
errno = -ret;
ret = -1;
}
return ret;
}

View file

@ -24,11 +24,20 @@
#undef errno
extern int errno;
#include "warning.h"
#include "syscall.h"
int
_DEFUN (_fork, (),
_NOARGS)
{
errno = EAGAIN;
return -1;
int ret;
/* create a child process */
ret = SYSCALL0(__NR_fork);
if (ret < 0) {
errno = -ret;
ret = -1;
}
return ret;
}

View file

@ -33,6 +33,10 @@ _DEFUN (_getpid, (),
int ret;
ret = SYSCALL0(__NR_getpid);
if (ret < 0) {
errno = -ret;
ret = -1;
}
return ret;
}

View file

@ -35,6 +35,10 @@ _DEFUN (_open, (file, flags, mode),
int ret;
ret = SYSCALL2(__NR_open, flags, mode);
if (ret < 0) {
errno = -ret;
ret = -1;
}
return ret;
}

View file

@ -35,6 +35,7 @@ extern "C" {
#define __NR_kill 9
#define __NR_fstat 10
#define __NR_sbrk 11
#define __NR_fork 12
#define _STR(token) #token
#define _SYSCALLSTR(x) "int $" _STR(x) " "

View file

@ -35,6 +35,10 @@ _DEFUN (write, (file, ptr, len),
int ret;
ret = SYSCALL3(__NR_write, file, ptr, len);
if (ret < 0) {
errno = -ret;
ret = -1;
}
return ret;
}