L4Re - L4 Runtime Environment
rm_impl.h
Go to the documentation of this file.
1 
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/dataspace>
25 
26 #include <l4/sys/cxx/ipc_client>
27 
28 #include <l4/sys/task>
29 #include <l4/sys/err.h>
30 
35 L4_RPC_DEF(L4Re::Rm::get_regions);
36 L4_RPC_DEF(L4Re::Rm::get_areas);
38 
39 namespace L4Re
40 {
41 
42 long
43 Rm::attach(l4_addr_t *start, unsigned long size, unsigned long flags,
45  unsigned char align) const throw()
46 {
47  if (flags & Reserved)
49 
50  long e = attach_t::call(c(), start, size, flags, mem, offs, align, mem.cap().cap());
51  if (e < 0)
52  return e;
53 
54  if (flags & Eager_map)
55  {
56  unsigned long fl = (flags & Read_only)
59  fl |= (flags & Caching) >> Caching_ds_shift;
60  e = mem.cap()->map_region(offs, fl, *start, *start + size);
61  }
62  return e;
63 }
64 
65 int
66 Rm::detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
67  L4::Cap<L4::Task> task, unsigned flags) const throw()
68 {
69  l4_addr_t rstart = 0, rsize = 0;
70  l4_cap_idx_t mem_cap = L4_INVALID_CAP;
71  long e = detach_t::call(c(), start, size, flags, rstart, rsize, mem_cap);
72  if (L4_UNLIKELY(e < 0))
73  return e;
74 
75  if (mem)
76  *mem = L4::Cap<L4Re::Dataspace>(mem_cap);
77 
78  if (!task.is_valid())
79  return e;
80 
81  rsize = l4_round_page(rsize);
82  unsigned order = L4_LOG2_PAGESIZE;
83  unsigned long sz = (1UL << order);
84  for (unsigned long p = rstart; rsize; p += sz, rsize -= sz)
85  {
86  while (sz > rsize)
87  {
88  --order;
89  sz >>= 1;
90  }
91 
92  for (;;)
93  {
94  unsigned long m = sz << 1;
95  if (m > rsize)
96  break;
97 
98  if (p & (m - 1))
99  break;
100 
101  ++order;
102  sz <<= 1;
103  }
104 
105  task->unmap(l4_fpage(p, order, L4_FPAGE_RWX),
107  }
108 
109  return e;
110 }
111 }
Request writable mapping.
Definition: dataspace:71
Capability type for RPC interfaces (see L4::Cap<T>).
Definition: ipc_types:541
long map_region(l4_addr_t offset, unsigned long flags, l4_addr_t min_addr, l4_addr_t max_addr) const
Map a part of a dataspace completely.
long reserve_area(l4_addr_t *start, unsigned long size, unsigned flags=0, unsigned char align=L4_PAGESHIFT) const
Reserve the given area in the region map.
Definition: rm:241
Invalid capability selector.
Definition: consts.h:141
long free_area(l4_addr_t addr)
Free an area from the region map.
l4_msgtag_t unmap(l4_fpage_t const &fpage, l4_umword_t map_mask, l4_utcb_t *utcb=l4_utcb())
Revoke rights from the task.
Definition: task:90
Request read-only mapping.
Definition: dataspace:70
l4_addr_t l4_round_page(l4_addr_t address) L4_NOTHROW
Round address up to the next page.
Definition: consts.h:389
Read-write-execute flex page.
Definition: __l4_fpage.h:114
L4::Cap< T > cap() const
Return the L4::Cap<T> of this Cap.
Definition: ipc_types:601
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
L4Re C++ Interfaces.
Definition: backend:25
Common task related definitions.
Region mapper interface.
Flag to tell the unmap operation to unmap all child mappings including the mapping in the invoked tas...
Definition: consts.h:165
l4_fpage_t l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW
Create a memory flex page.
Definition: __l4_fpage.h:633
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
Definition: consts.h:325
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition: compiler.h:234
int detach(l4_addr_t addr, L4::Cap< Dataspace > *mem, L4::Cap< L4::Task > const &task=This_task) const
Detach a region from the address space.
Definition: rm:591
Error codes.
bool is_valid() const
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition: capability.h:60
int find(l4_addr_t *addr, unsigned long *size, l4_addr_t *offset, unsigned *flags, L4::Cap< Dataspace > *m)
Find a region given an address and size.
Definition: rm:555
#define L4_RPC_DEF(name)
Generate the definition of an RPC stub.
Definition: ipc_client:43
Dataspace interface.
C++ interface for capabilities.
Definition: capability.h:13
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
long attach(l4_addr_t *start, unsigned long size, unsigned long flags, L4::Ipc::Cap< Dataspace > mem, l4_addr_t offs=0, unsigned char align=L4_PAGESHIFT) const
Attach a data space to a region.
Definition: rm_impl.h:43