Support to multi-threading and pthread interface (POSIX.1-2008) (#23)
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / region.h
index 99e9990a3e306c51e727ffd019c5c238e700954d..d030f6d2fb6adfad5e6a7ff5a16f3098b4bb66a5 100644 (file)
@@ -2,6 +2,35 @@
 #define __LUNAIX_REGION_H
 
 #include <lunaix/mm/mm.h>
 #define __LUNAIX_REGION_H
 
 #include <lunaix/mm/mm.h>
+#include <lunaix/mm/page.h>
+#include <lunaix/mm/procvm.h>
+
+#define prev_region(vmr) list_prev(vmr, struct mm_region, head)
+#define next_region(vmr) list_next(vmr, struct mm_region, head)
+#define get_region(vmr_el) list_entry(vmr_el, struct mm_region, head)
+
+static inline int
+stack_region(struct mm_region* region) {
+    return region->attr & REGION_TYPE_STACK;
+}
+
+static inline int
+same_region(struct mm_region* a, struct mm_region* b) {
+    return a->start == b->start \
+            && a->end == b->end \
+            && a->attr == b->attr;
+}
+
+static inline bool
+region_contains(struct mm_region* mm, ptr_t va) {
+    return mm->start <= va && va < mm->end;
+}
+
+static inline size_t
+region_size(struct mm_region* mm) {
+    return mm->end - mm->start;
+}
+
 
 struct mm_region*
 region_create(ptr_t start, ptr_t end, u32_t attr);
 
 struct mm_region*
 region_create(ptr_t start, ptr_t end, u32_t attr);
@@ -22,6 +51,22 @@ struct mm_region*
 region_get(vm_regions_t* lead, unsigned long vaddr);
 
 void
 region_get(vm_regions_t* lead, unsigned long vaddr);
 
 void
-region_copy(struct proc_mm* src, struct proc_mm* dest);
+region_copy_mm(struct proc_mm* src, struct proc_mm* dest);
+
+struct mm_region*
+region_dup(struct mm_region* origin);
+
+static u32_t
+region_ptattr(struct mm_region* vmr)
+{
+    u32_t vmr_attr = vmr->attr;
+    u32_t ptattr = PG_PRESENT | PG_ALLOW_USER;
+
+    if ((vmr_attr & PROT_WRITE)) {
+        ptattr |= PG_WRITE;
+    }
+
+    return ptattr & 0xfff;
+}
 
 #endif /* __LUNAIX_REGION_H */
 
 #endif /* __LUNAIX_REGION_H */