1 /*
2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
5 *
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
9 *
10 * As a special exception, you may use this file as part of a free software
11 * library without restriction. Specifically, if other files instantiate
12 * templates or use macros or inline functions from this file, or you compile
13 * this file and link it with other files to produce an executable, this
14 * file does not by itself cause the resulting executable to be covered by
15 * the GNU General Public License. This exception does not however
16 * invalidate any other reasons why the executable file might be covered by
17 * the GNU General Public License.
18 */
19
20 #include <l4/sys/err.h>
21 #include <l4/re/rm>
22 #include <l4/re/env>
23 #include <l4/re/dataspace>
24 #include <l4/re/debug>
25
26 #include <l4/re/c/rm.h>
27 #include <l4/re/c/dataspace.h>
28
29 int
l4re_rm_reserve_area_srv(l4_cap_idx_t rm,l4_addr_t * start,unsigned long size,l4re_rm_flags_t flags,unsigned char align)30 l4re_rm_reserve_area_srv(l4_cap_idx_t rm, l4_addr_t *start, unsigned long size,
31 l4re_rm_flags_t flags, unsigned char align) L4_NOTHROW
32 {
33 L4::Cap<L4Re::Rm> x(rm);
34 return x->reserve_area(start, size, L4Re::Rm::Flags(flags), align);
35 }
36
37 int
l4re_rm_free_area_srv(l4_cap_idx_t rm,l4_addr_t addr)38 l4re_rm_free_area_srv(l4_cap_idx_t rm, l4_addr_t addr) L4_NOTHROW
39 {
40 L4::Cap<L4Re::Rm> x(rm);
41 return x->free_area(addr);
42 }
43
44 int
l4re_rm_attach_srv(l4_cap_idx_t rm,void ** start,unsigned long size,l4re_rm_flags_t flags,l4re_ds_t mem,l4re_rm_offset_t offs,unsigned char align)45 l4re_rm_attach_srv(l4_cap_idx_t rm, void **start, unsigned long size,
46 l4re_rm_flags_t flags, l4re_ds_t mem,
47 l4re_rm_offset_t offs,
48 unsigned char align) L4_NOTHROW
49 {
50 L4::Cap<L4Re::Rm> x(rm);
51 auto _mem = L4::Ipc::Cap<L4Re::Dataspace>::from_ci(mem);
52 return x->attach(start, size, L4Re::Rm::Flags(flags), _mem, offs, align);
53 }
54
55
56 int
l4re_rm_detach_srv(l4_cap_idx_t rm,l4_addr_t addr,l4re_ds_t * ds,l4_cap_idx_t task)57 l4re_rm_detach_srv(l4_cap_idx_t rm, l4_addr_t addr, l4re_ds_t *ds,
58 l4_cap_idx_t task) L4_NOTHROW
59 {
60 L4::Cap<L4Re::Rm> x(rm);
61 L4::Cap<L4::Task> t(task);
62 L4::Cap<L4Re::Dataspace> d(L4_INVALID_CAP);
63 int r = x->detach(addr, &d, t);
64 if (ds)
65 *ds = d.cap();
66 return r;
67 }
68
69
70 int
l4re_rm_find_srv(l4_cap_idx_t rm,l4_addr_t * addr,unsigned long * size,l4re_rm_offset_t * offset,l4re_rm_flags_t * flags,l4re_ds_t * m)71 l4re_rm_find_srv(l4_cap_idx_t rm, l4_addr_t *addr,
72 unsigned long *size,
73 l4re_rm_offset_t *offset,
74 l4re_rm_flags_t *flags, l4re_ds_t *m) L4_NOTHROW
75 {
76 L4::Cap<L4Re::Rm> x(rm);
77 L4::Cap<L4Re::Dataspace> mm(L4_INVALID_CAP);
78 L4Re::Rm::Flags f;
79 int r = x->find(addr, size, offset, &f, &mm);
80 *flags = f.raw;
81 *m = mm.cap();
82 return r;
83 }
84
85 void
l4re_rm_show_lists_srv(l4_cap_idx_t rm)86 l4re_rm_show_lists_srv(l4_cap_idx_t rm) L4_NOTHROW
87 {
88 L4::Cap<L4Re::Debug_obj> d(rm);
89 d->debug(0); // XXX: use enum
90 }
91