feat: heap support and re-worked
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / mm.h
index 43ef96eaa87f71f371042747c0d2bdc9b740c095..218d1d5ce5e39b526bcfb94b02e5881952533e9c 100644 (file)
@@ -8,14 +8,6 @@
 
 #include <usr/sys/mann_flags.h>
 
 
 #include <usr/sys/mann_flags.h>
 
-typedef struct
-{
-    void* start;
-    void* brk;
-    void* max_addr;
-    mutex_t lock;
-} heap_context_t;
-
 /**
  * @brief 私有区域,该区域中的页无法进行任何形式的共享。
  *
 /**
  * @brief 私有区域,该区域中的页无法进行任何形式的共享。
  *
@@ -52,18 +44,50 @@ typedef struct
 #define REGION_TYPE_STACK (4 << 16)
 #define REGION_TYPE_VARS (5 << 16)
 
 #define REGION_TYPE_STACK (4 << 16)
 #define REGION_TYPE_VARS (5 << 16)
 
+struct proc_mm;
+
 struct mm_region
 {
     struct llist_header head; // must be first field!
 struct mm_region
 {
     struct llist_header head; // must be first field!
+    struct proc_mm* proc_vms;
+
+    // file mapped to this region
     struct v_file* mfile;
     struct v_file* mfile;
-    u32_t offset;
+    // mapped file offset
+    off_t foff;
+    // mapped file length
+    u32_t flen;
+
     ptr_t start;
     ptr_t end;
     u32_t attr;
 
     ptr_t start;
     ptr_t end;
     u32_t attr;
 
+    void** index; // fast reference, to accelerate access to this very region.
+
     void* data;
     void* data;
+    // When a page is mapped and required initialize
     int (*init_page)(struct mm_region*, void*, off_t);
     int (*init_page)(struct mm_region*, void*, off_t);
+    // when a region is copied
+    void (*region_copied)(struct mm_region*);
+    // when a region is unmapped
     void (*destruct_region)(struct mm_region*);
 };
 
     void (*destruct_region)(struct mm_region*);
 };
 
+static inline void
+mm_index(void** index, struct mm_region* target)
+{
+    *index = (void*)target;
+    target->index = index;
+}
+
+typedef struct llist_header vm_regions_t;
+
+struct proc_mm
+{
+    vm_regions_t regions;
+    struct mm_region* heap;
+    struct mm_region* stack;
+    pid_t pid;
+};
+
 #endif /* __LUNAIX_MM_H */
 #endif /* __LUNAIX_MM_H */