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