OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [libposix/] [fork.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * l4/posix glue for fork()
3
 *
4
 * Copyright (C) 2008 Bahadir Balban
5
 */
6
#include <errno.h>
7
#include <stdio.h>
8
#include <sys/types.h>
9
#include <l4lib/ipcdefs.h>
10
#include <l4lib/utcb.h>
11
#include <l4/macros.h>
12
#include INC_GLUE(memory.h)
13
#include <shpage.h>
14
#include <libposix.h>
15
 
16
static inline int l4_fork(void)
17
{
18
        int err;
19
 
20
        /* Call pager with open() request. Check ipc error. */
21
        if ((err = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_FORK)) < 0) {
22
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
23
                return err;
24
        }
25
        /* Check if syscall itself was successful */
26
        if ((err = l4_get_retval()) < 0) {
27
                print_err("%s: OPEN Error: %d.\n", __FUNCTION__, err);
28
                return err;
29
        }
30
        return err;
31
}
32
 
33
int fork(void)
34
{
35
        int ret = l4_fork();
36
 
37
        /* If error, return positive error code */
38
        if (ret < 0) {
39
                errno = -ret;
40
                return -1;
41
        }
42
 
43
        return ret;
44
}
45
 
46
extern int arch_clone(l4id_t to, l4id_t from, unsigned int flags);
47
 
48
int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...)
49
{
50
        /* Set up the child stack */
51
        unsigned int *stack = child_stack;
52
        int ret;
53
 
54
        /* First word of new stack is arg */
55
        stack[-1] = (unsigned long)arg;
56
 
57
        /* Second word of new stack is function address */
58
        stack[-2] = (unsigned long)fn;
59
 
60
        /* Write the tag */
61
        l4_set_tag(L4_IPC_TAG_CLONE);
62
 
63
        /* Write the args as in usual ipc */
64
        write_mr(L4SYS_ARG0, (unsigned long)child_stack);
65
        write_mr(L4SYS_ARG1, flags);
66
 
67
        /* Perform an ipc but with different return logic. See implementation. */
68
        if ((ret = arch_clone(pagerid, pagerid, 0)) < 0) {
69
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, ret);
70
                return ret;
71
        }
72
 
73
        if ((ret = l4_get_retval()) < 0) {
74
                print_err("%s: CLONE Error: %d.\n", __FUNCTION__, ret);
75
                return ret;
76
        }
77
        return ret;
78
}
79
 
80
 
81
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.