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 #pragma once
11 
12 #include <l4/sys/types.h>
13 #include <l4/sys/exception>
14 #include <l4/re/dataspace>
15 #include <l4/re/util/region_mapping_svr_2>
16 #include <l4/re/debug>
17 #include "debug.h"
18 #include <stdlib.h>
19 
new(size_t s,cxx::Nothrow const &)20 inline void *operator new (size_t s, cxx::Nothrow const &) throw() { return malloc(s); }
21 
22 class Region_ops;
23 
24 typedef L4Re::Util::Region_handler<L4::Cap<L4Re::Dataspace>, Region_ops> Region_handler;
25 
26 class Region_ops
27 {
28 public:
29   typedef l4_umword_t Map_result;
30   static int map(Region_handler const *h, l4_addr_t addr,
31                  L4Re::Util::Region const &r, bool writable,
32                  l4_umword_t *result);
33 
34   static void free(Region_handler const *h, l4_addr_t start, unsigned long size);
35 };
36 
37 
38 class Region_map
39 : public L4Re::Util::Region_map<Region_handler, cxx::New_allocator>,
40   public L4Re::Util::Rm_server<Region_map, Dbg>
41 {
42 private:
43   typedef L4Re::Util::Region_map<Region_handler, cxx::New_allocator> Base;
44 
45 public:
46   typedef L4::Cap<L4Re::Dataspace> Dataspace;
47   typedef L4::Kobject_3t<void, L4Re::Rm, L4::Exception, L4Re::Debug_obj> Interface;
48   enum { Have_find = true };
server_iface()49   void *server_iface() const { return 0; }
validate_ds(void *,L4::Ipc::Snd_fpage const & ds_cap,L4Re::Rm::Region_flags,L4::Cap<L4Re::Dataspace> * ds)50   static int validate_ds(void *, L4::Ipc::Snd_fpage const &ds_cap,
51                          L4Re::Rm::Region_flags,
52                          L4::Cap<L4Re::Dataspace> *ds)
53   {
54     // if no cap was sent then the region will be reserved
55     if (ds_cap.local_id_received())
56       {
57 	// we received a local capability index, get it with cap.base()
58 	*ds = L4::Cap<L4Re::Dataspace>(ds_cap.base());
59 	return L4_EOK;
60       }
61     return -L4_ENOENT;
62   }
63 
find_res(L4::Cap<void> const & ds)64   static l4_umword_t find_res(L4::Cap<void> const &ds) { return ds.cap(); }
65 
66   Region_map();
~Region_map()67   virtual ~Region_map() {}
68 
69   void init();
70 
71   void debug_dump(unsigned long function) const;
72 
73   int op_exception(L4::Exception::Rights, l4_exc_regs_t &regs,
74                    L4::Ipc::Opt<L4::Ipc::Snd_fpage> &fp);
75   long op_io_page_fault(L4::Io_pager::Rights,
76                         l4_fpage_t io_pfa, l4_umword_t pc,
77                         L4::Ipc::Opt<L4::Ipc::Snd_fpage> &);
op_debug(L4Re::Debug_obj::Rights,unsigned long function)78   long op_debug(L4Re::Debug_obj::Rights, unsigned long function)
79   { debug_dump(function); return 0; }
80 };
81 
82 
83