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

Subversion Repositories c0or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Initialise posix-related structures.
3
 *
4
 * Copyright (C) 2007-2009 Bahadir Balban
5
 */
6
#include <l4lib/kip.h>
7
#include <l4lib/ipcdefs.h>
8
#include <l4/macros.h>
9
#include <stdio.h>
10
#include <shpage.h>
11
#include <sys/types.h>
12
#include <sys/shm.h>
13
#include <shpage.h>
14
#include <libposix.h>
15
#include INC_GLUE(memlayout.h)
16
 
17
#if 0
18
 
19
/*
20
 * Shared page initialisation of posix-like tasks.
21
 *
22
 * POSIX tasks currently use a default shared page for communciation.
23
 * This could have been also done by long ipc calls.
24
 */
25
 
26
/*
27
 * Shared page for this task. Used for passing data among ipc
28
 * parties when message registers are not big enough. Every thread
29
 * has right to own one, and it has an address unique to every
30
 * thread. It must be explicitly mapped by both parties of the ipc
31
 * in order to be useful.
32
 */
33
void *shared_page;
34
 
35
/*
36
 * Obtains a unique address for the task's shared page. Note this
37
 * just returns the address. This address is used as an shm key
38
 * to map it via shmget()/shmat() later on.
39
 */
40
static void *shared_page_address(void)
41
{
42
        void *addr;
43
        int err;
44
 
45
        /* We're asking it for ourself. */
46
        write_mr(L4SYS_ARG0, self_tid());
47
 
48
        /* Call pager with utcb address request. Check ipc error. */
49
        if ((err = l4_sendrecv(pagerid, pagerid,
50
                               L4_IPC_TAG_SHPAGE)) < 0) {
51
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
52
                return PTR_ERR(err);
53
        }
54
 
55
        /* Check if syscall itself was successful */
56
        if (IS_ERR(addr = (void *)l4_get_retval())) {
57
                print_err("%s: Request UTCB Address Error: %d.\n",
58
                       __FUNCTION__, (int)addr);
59
                return addr;
60
        }
61
 
62
        return addr;
63
}
64
 
65
/*
66
 * Initialises a non-pager task's default shared memory page
67
 * using posix semantics. Used during task initialisation
68
 * and by child tasks after a fork.
69
 */
70
int shared_page_init(void)
71
{
72
        int shmid;
73
        void *shmaddr;
74
 
75
        /*
76
         * Initialise shared page only if we're not the pager.
77
         * The pager does it differently for itself.
78
         */
79
        BUG_ON(self_tid() == pagerid);
80
 
81
        /* Obtain our shared page address */
82
        shared_page = shared_page_address();
83
 
84
        //print_err("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__,
85
        //       (unsigned long)shared_page);
86
 
87
        /* Use it as a key to create a shared memory region */
88
        BUG_ON((shmid = shmget((key_t)shared_page,
89
                               PAGE_SIZE, IPC_CREAT)) < 0);
90
 
91
        /* Attach to the region */
92
        BUG_ON((shmaddr = shmat(shmid, shared_page, 0)) < 0);
93
        BUG_ON(shmaddr != shared_page);
94
 
95
        return 0;
96
}
97
 
98
#endif

powered by: WebSVN 2.1.0

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