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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [libposix/] [mmap.c] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Glue logic between posix mmap/munmap functions
3
 * and their L4 implementation.
4
 *
5
 * Copyright (C) 2007 Bahadir Balban
6
 */
7
#include <errno.h>
8
#include <stdio.h>
9
#include <sys/mman.h>
10
#include <sys/types.h>
11
#include <l4lib/ipcdefs.h>
12
#include <libposix.h>
13
 
14
/* FIXME: Implement the same separation that is in read.c write.c etc. such that
15
 * l4_syscall returns negative value and then the actual posix glue sets the errno
16
 * rather than the l4_syscall sets it itself
17
 */
18
 
19
struct mmap_descriptor {
20
        void *start;
21
        size_t length;
22
        int prot;
23
        int flags;
24
        int fd;
25
        off_t offset;
26
};
27
 
28
static inline void *l4_mmap(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
29
{
30
        /* Not enough MRs for all arguments, therefore we fill in a structure */
31
        struct mmap_descriptor desc = {
32
                .start = start,
33
                .length = length,
34
                .prot = prot,
35
                .flags = flags,
36
                .fd = fd,
37
                .offset = pgoffset,
38
        };
39
        int ret;
40
 
41
        write_mr(L4SYS_ARG0, (unsigned long)&desc);
42
 
43
        /* Call pager with MMAP request. Check ipc error. */
44
        if ((ret = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_MMAP)) < 0) {
45
                print_err("%s: IPC Error: %d.\n", __FUNCTION__, ret);
46
                return PTR_ERR(ret);
47
        }
48
 
49
        if (IS_ERR(ret = l4_get_retval()))
50
                print_err("%s: MMAP Error: %d.\n", __FUNCTION__, ret);
51
 
52
        return (void *)ret;
53
}
54
 
55
void *mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
56
{
57
        void *ret = l4_mmap(start, length, prot, flags, fd, pgoffset);
58
 
59
        if (IS_ERR(ret)) {
60
                errno = -(int)ret;
61
                return MAP_FAILED;
62
        }
63
        return ret;
64
}
65
 
66
 
67
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
68
{
69
        return mmap2(start, length, prot, flags, fd, __pfn(offset));
70
}
71
 
72
int l4_munmap(void *start, size_t length)
73
{
74
        int err;
75
 
76
        write_mr(L4SYS_ARG0, (unsigned long)start);
77
        write_mr(L4SYS_ARG1, length);
78
 
79
        /* Call pager with MMAP request. */
80
        if ((err = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_MUNMAP)) < 0) {
81
                print_err("%s: IPC Error: %d.\n", __FUNCTION__, err);
82
                return err;
83
        }
84
 
85
        /* Check if syscall itself was successful */
86
        if ((err = l4_get_retval()) < 0) {
87
                print_err("%s: MUNMAP Error: %d.\n", __FUNCTION__, err);
88
                return err;
89
        }
90
        return 0;
91
}
92
 
93
int munmap(void *start, size_t length)
94
{
95
        int ret = l4_munmap(start, length);
96
 
97
        /* If error, return positive error code */
98
        if (ret < 0) {
99
                errno = -ret;
100
                return -1;
101
        }
102
        return 0;
103
}
104
 
105
int l4_msync(void *start, size_t length, int flags)
106
{
107
        write_mr(L4SYS_ARG0, (unsigned long)start);
108
        write_mr(L4SYS_ARG1, length);
109
        write_mr(L4SYS_ARG2, flags);
110
 
111
        /* Call pager with MMAP request. */
112
        if ((errno = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_MSYNC)) < 0) {
113
                print_err("%s: IPC Error: %d.\n", __FUNCTION__, errno);
114
                return -1;
115
        }
116
        /* Check if syscall itself was successful */
117
        if ((errno = l4_get_retval()) < 0) {
118
                print_err("%s: MSYNC Error: %d.\n", __FUNCTION__, errno);
119
                return -1;
120
        }
121
        return 0;
122
}
123
 
124
int msync(void *start, size_t length, int flags)
125
{
126
        int ret = l4_msync(start, length, flags);
127
 
128
        if (ret < 0) {
129
                errno = -ret;
130
                return -1;
131
        }
132
        return 0;
133
}
134
 

powered by: WebSVN 2.1.0

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