]> rtime.felk.cvut.cz Git - l4.git/blobdiff - l4/pkg/l4re/util/include/region_mapping
update
[l4.git] / l4 / pkg / l4re / util / include / region_mapping
index 3ccd653a7ae61725283f910f97eafa39c33e8bfe..2076b9e5a04ab143775a53d2637bcb003e061579 100644 (file)
@@ -5,7 +5,11 @@
  * \brief  Region handling
  */
 /*
- * (c) 2008-2009 Technische Universität Dresden
+ * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
+ *               Alexander Warg <warg@os.inf.tu-dresden.de>,
+ *               Björn Döbel <doebel@os.inf.tu-dresden.de>
+ *     economic rights: Technische Universität Dresden (Germany)
+ *
  * This file is part of TUD:OS and distributed under the terms of the
  * GNU General Public License 2.
  * Please see the COPYING-GPL-2 file for details.
@@ -155,8 +159,11 @@ public:
     if (!n)
       return Node();
 
-    if (!n->first.contains(key))
-      return Node();
+    // 'find' should find any region overlapping with the searched one, the
+    // caller should check for further requirements
+    if (0)
+      if (!n->first.contains(key))
+        return Node();
 
     return n;
   }
@@ -169,19 +176,34 @@ public:
       return L4_INVALID_ADDR;
 
 
-    if (flags & Search)
+    Region c;
+
+    if (!(flags & Search))
+      {
+       c = Region(addr, addr + size - 1);
+       Node r = _am.find_node(c);
+       if (r)
+         return L4_INVALID_ADDR;
+      }
+
+    while (flags & Search)
       {
        if (addr < min_addr() || (addr + size - 1) > max_addr())
          addr = min_addr();
        addr = find_free(addr, max_addr(), size, align, flags);
        if (addr == L4_INVALID_ADDR)
          return L4_INVALID_ADDR;
-      }
 
-    Region c(addr, addr + size - 1);
-    Node r = _am.find_node(c);
-    if (r)
-      return L4_INVALID_ADDR;
+       c = Region(addr, addr + size - 1);
+       Node r = _am.find_node(c);
+       if (!r)
+         break;
+
+       if (r->first.end() >= max_addr())
+         return L4_INVALID_ADDR;
+
+       addr = r->first.end() + 1;
+      }
 
     if (_am.insert(c, Hdlr(typename Hdlr::Dataspace(), 0, flags)).second == 0)
       return addr;