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/re/c/dataspace.h>
21 
22 #include <l4/re/mem_alloc>
23 #include <l4/re/dataspace>
24 #include <l4/re/env>
25 #include <l4/sys/err.h>
26 
27 
28 int
l4re_ds_map(l4re_ds_t ds,l4re_ds_offset_t offset,l4re_ds_flags_t flags,l4re_ds_map_addr_t local_addr,l4re_ds_map_addr_t min_addr,l4re_ds_map_addr_t max_addr)29 l4re_ds_map(l4re_ds_t ds,
30             l4re_ds_offset_t offset,
31             l4re_ds_flags_t flags,
32             l4re_ds_map_addr_t local_addr,
33             l4re_ds_map_addr_t min_addr,
34             l4re_ds_map_addr_t max_addr) L4_NOTHROW
35 {
36   L4::Cap<L4Re::Dataspace> x(ds);
37   return x->map(offset, L4Re::Dataspace::Flags(flags), local_addr, min_addr, max_addr);
38 }
39 
40 int
l4re_ds_map_region(l4re_ds_t ds,l4re_ds_offset_t offset,l4re_ds_flags_t flags,l4re_ds_map_addr_t min_addr,l4re_ds_map_addr_t max_addr)41 l4re_ds_map_region(l4re_ds_t ds, l4re_ds_offset_t offset,
42                    l4re_ds_flags_t flags,
43                    l4re_ds_map_addr_t min_addr,
44                    l4re_ds_map_addr_t max_addr) L4_NOTHROW
45 {
46   L4::Cap<L4Re::Dataspace> x(ds);
47   return x->map_region(offset, L4Re::Dataspace::Flags(flags), min_addr, max_addr);
48 }
49 
50 long
l4re_ds_clear(l4re_ds_t ds,l4re_ds_offset_t offset,l4re_ds_size_t size)51 l4re_ds_clear(l4re_ds_t ds, l4re_ds_offset_t offset, l4re_ds_size_t size) L4_NOTHROW
52 {
53   L4::Cap<L4Re::Dataspace> x(ds);
54   return x->clear(offset, size);
55 }
56 
57 long
l4re_ds_allocate(l4re_ds_t ds,l4re_ds_offset_t offset,l4re_ds_size_t size)58 l4re_ds_allocate(l4re_ds_t ds,
59                  l4re_ds_offset_t offset, l4re_ds_size_t size) L4_NOTHROW
60 {
61   L4::Cap<L4Re::Dataspace> x(ds);
62   return x->allocate(offset, size);
63 }
64 
65 int
l4re_ds_copy_in(l4re_ds_t ds,l4re_ds_offset_t dst_offs,l4re_ds_t src,l4re_ds_offset_t src_offs,l4re_ds_size_t size)66 l4re_ds_copy_in(l4re_ds_t ds, l4re_ds_offset_t dst_offs,
67                 l4re_ds_t src, l4re_ds_offset_t src_offs,
68                 l4re_ds_size_t size) L4_NOTHROW
69 {
70   L4::Cap<L4Re::Dataspace> x(ds);
71   auto srcds = L4::Ipc::Cap<L4Re::Dataspace>::from_ci(src);
72   return x->copy_in(dst_offs, srcds, src_offs, size);
73 }
74 
75 l4re_ds_size_t
l4re_ds_size(l4re_ds_t ds)76 l4re_ds_size(l4re_ds_t ds) L4_NOTHROW
77 {
78   L4::Cap<L4Re::Dataspace> x(ds);
79   return x->size();
80 }
81 
82 int
l4re_ds_info(l4re_ds_t ds,l4re_ds_stats_t * stats)83 l4re_ds_info(l4re_ds_t ds, l4re_ds_stats_t *stats) L4_NOTHROW
84 {
85   L4::Cap<L4Re::Dataspace> x(ds);
86   return x->info((L4Re::Dataspace::Stats *)stats);
87 }
88 
89 l4re_ds_flags_t
l4re_ds_flags(l4re_ds_t ds)90 l4re_ds_flags(l4re_ds_t ds) L4_NOTHROW
91 {
92   L4::Cap<L4Re::Dataspace> x(ds);
93   return x->flags().raw;
94 }
95