Changes in the README, changes to fork template.

This commit is contained in:
Bahadir Balban
2008-08-16 13:01:18 +03:00
parent d434ad4b40
commit f436b44e81
7 changed files with 138 additions and 42 deletions

46
tasks/libposix/fork.c Normal file
View File

@@ -0,0 +1,46 @@
/*
* l4/posix glue for fork()
*
* Copyright (C) 2008 Bahadir Balban
*/
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <l4lib/arch/syscalls.h>
#include <l4lib/arch/syslib.h>
#include <l4lib/ipcdefs.h>
#include <l4lib/utcb.h>
#include <l4/macros.h>
#include INC_GLUE(memory.h)
static inline int l4_fork(void)
{
int err;
/* Call pager with open() request. Check ipc error. */
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_FORK)) < 0) {
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
return err;
}
/* Check if syscall itself was successful */
if ((err = l4_get_retval()) < 0) {
printf("%s: OPEN Error: %d.\n", __FUNCTION__, err);
return err;
}
return err;
}
int fork(void)
{
int ret = l4_fork();
/* If error, return positive error code */
if (ret < 0) {
errno = -ret;
return -1;
}
/* else return value */
return ret;
}

View File

@@ -43,5 +43,7 @@ struct sys_shmget_args {
int sys_shmget(key_t key, int size, int shmflg);
int sys_fork(void);
#endif /* __MM0_SYSARGS_H__ */

View File

@@ -100,7 +100,7 @@ void handle_requests(void)
case L4_IPC_TAG_CLOSE:
sys_close(sender, (int)mr[0]);
break;
case L4_IPC_TAG_FSYNC:
sys_fsync(sender, (int)mr[0]);
break;
@@ -120,6 +120,10 @@ void handle_requests(void)
args->flags, args->fd, __pfn(args->offset));
break;
}
case L4_IPC_TAG_MMAP: {
sys_fork(sender);
break;
}
case L4_IPC_TAG_BRK: {
// sys_brk(sender, (void *)mr[0]);
// break;

View File

@@ -3,7 +3,7 @@
*
* Copyright (C) 2008 Bahadir Balban
*/
#include <syscalls.h>
int copy_tcb(struct tcb *p, struct tcb *c)
{
@@ -28,20 +28,33 @@ int do_fork(struct tcb *parent)
{
struct tcb *child;
/* Make all parent shadows read only */
vm_freeze_shadows(parent);
/* Create a new L4 thread with new space */
l4_thread_create(parent);
/* Create a new local tcb */
child = tcb_alloc_init();
/* Make all parent shadows read only */
vm_freeze_shadows(parent);
/* Copy parent tcb to child */
copy_tcb(struct tcb *parent, struct tcb *child);
/* FIXME: Copy parent page tables to child ??? */
/* FIXME: Copy parent register values to child ??? */
/*
* Allocate and copy parent pgd + all pmds to child.
*
* When a write fault occurs on any of the frozen shadows,
* fault handler creates a new shadow on top, if it hasn't,
* and then starts adding writeable pages to the new shadow.
* Every forked task will fault on every page of the frozen shadow,
* until all pages have been made copy-on-write'ed, in which case
* the underlying frozen shadow is collapsed.
*
* Every forked task must have its own copy of pgd + pmds because
* every one of them will have to fault on frozen shadows individually.
*/
/* FIXME: Need to copy parent register values to child ??? */
/* Notify fs0 about forked process */
vfs_send_fork(parent, child);

View File

@@ -10,7 +10,8 @@
#include <l4lib/utcb.h>
#include <l4lib/ipcdefs.h>
#include <tests.h>
#include <unistd.h>
#include <sys/types.h>
void wait_pager(l4id_t partner)
{
@@ -23,23 +24,32 @@ void wait_pager(l4id_t partner)
void main(void)
{
pid_t pid;
printf("\n%s: Started with tid %d.\n", __TASKNAME__, self_tid());
/* Sync with pager */
wait_pager(0);
dirtest();
printf("File IO test 1:\n");
if (fileio() == 0)
printf("-- PASSED --\n");
else
printf("-- FAILED --\n");
printf("File IO test 2:\n");
if (fileio2() == 0)
printf("-- PASSED --\n");
else
printf("-- FAILED --\n");
printf("Forking...\n");
if ((pid = fork()) < 0)
printf("Error forking...\n");
if (pid == 0) {
printf("File IO test 1, done by child:\n");
if (fileio() == 0)
printf("-- PASSED --\n");
else
printf("-- FAILED --\n");
} else {
printf("File IO test 2, done by parent, with child pid %d:\n", pid);
if (fileio2() == 0)
printf("-- PASSED --\n");
else
printf("-- FAILED --\n");
}
while (1)
wait_pager(0);
#if 0