]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/include/impl/rm_impl.h
Inital import
[l4.git] / l4 / pkg / l4re / include / impl / rm_impl.h
1 /**
2  * \file
3  * \brief  Region map client stub implementation
4  */
5 /*
6  * (c) 2008-2009 Technische Universität Dresden
7  * This file is part of TUD:OS and distributed under the terms of the
8  * GNU General Public License 2.
9  * Please see the COPYING-GPL-2 file for details.
10  *
11  * As a special exception, you may use this file as part of a free software
12  * library without restriction.  Specifically, if other files instantiate
13  * templates or use macros or inline functions from this file, or you compile
14  * this file and link it with other files to produce an executable, this
15  * file does not by itself cause the resulting executable to be covered by
16  * the GNU General Public License.  This exception does not however
17  * invalidate any other reasons why the executable file might be covered by
18  * the GNU General Public License.
19  */
20 #include <l4/re/rm>
21 #include <l4/re/rm-sys.h>
22 #include <l4/re/dataspace>
23 #include <l4/re/protocols>
24
25 #include <l4/cxx/ipc_helper>
26 #include <l4/cxx/ipc_stream>
27
28 #include <l4/sys/task>
29 #include <l4/sys/err.h>
30
31
32 namespace L4Re
33 {
34
35 using L4::Opcode;
36
37 long
38 Rm::reserve_area(l4_addr_t *start, unsigned long size, unsigned flags,
39                  unsigned char align) const throw()
40 {
41   L4::Ipc_iostream io(l4_utcb());
42   io << Opcode(Rm_::Attach_area) << *start << size << flags << align;
43   long err = l4_error(io.call(cap(), L4Re::Protocol::Rm));
44   if (EXPECT_FALSE(err < 0))
45     return err;
46
47   io >> *start;
48   return err;
49 }
50
51 long
52 Rm::free_area(l4_addr_t addr) const throw()
53 {
54   L4::Ipc_iostream io(l4_utcb());
55   io << Opcode(Rm_::Detach_area) << addr;
56   return l4_error(io.call(cap(), L4Re::Protocol::Rm));
57 }
58
59 long
60 Rm::attach(l4_addr_t *start, unsigned long size, unsigned long flags,
61            L4::Cap<Dataspace> mem, l4_addr_t offs,
62            unsigned char align) const throw()
63 {
64   L4::Ipc_iostream io(l4_utcb());
65   io << Opcode(Rm_::Attach) << l4_addr_t(*start) << size << flags
66      << offs << align;
67
68   if (!(flags & Reserved))
69     io << mem.cap() << mem;
70
71   long err = l4_error(io.call(cap(), L4Re::Protocol::Rm));
72   if (EXPECT_FALSE(err < 0))
73     return err;
74
75   io >> *reinterpret_cast<l4_addr_t*>(start);
76
77   if (flags & Eager_map)
78     {
79       unsigned long fl = (flags & Read_only)
80         ? Dataspace::Map_ro
81         : Dataspace::Map_rw;
82       err = mem->map_region(offs, fl, *start, *start + size);
83     }
84   return err;
85 }
86
87 int
88 Rm::_detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
89             L4::Cap<L4::Task> task, unsigned flags) const throw()
90 {
91   L4::Ipc_iostream io(l4_utcb());
92   io << Opcode(Rm_::Detach) << addr << size << flags;
93   long err = l4_error(io.call(cap(), L4Re::Protocol::Rm));
94   if (EXPECT_FALSE(err < 0))
95     return err;
96
97   l4_addr_t start;
98   unsigned long rsize;
99   io >> start >> rsize;
100
101   if (mem)
102     io >> *reinterpret_cast<l4_cap_idx_t*>(mem);
103
104   if (!task.is_valid())
105     return err;
106
107   for (unsigned long p = 0; p < rsize; p += L4_PAGESIZE)
108     {
109       task->unmap(l4_fpage(start + p, L4_LOG2_PAGESIZE, L4_FPAGE_RWX),
110                   L4_FP_ALL_SPACES);
111     }
112
113   return err;
114 }
115
116
117 int
118 Rm::find(l4_addr_t *addr, unsigned long *size, unsigned long *offset,
119          unsigned *flags, L4::Cap<Dataspace> *m) throw()
120 {
121   L4::Ipc_iostream io(l4_utcb());
122   io << Opcode(Rm_::Find) << *addr << *size;
123   long err = l4_error(io.call(cap(), L4Re::Protocol::Rm));
124   if (EXPECT_FALSE(err < 0))
125     return err;
126
127   l4_cap_idx_t c;
128   io >> *addr >> *size >> *flags >> *offset >> c;
129   *m = L4::Cap<Dataspace>(c);
130
131   return err;
132 }
133
134
135 }