git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into prog-loader
[lunaix-os.git]
/
lunaix-os
/
kernel
/
mm
/
region.c
diff --git
a/lunaix-os/kernel/mm/region.c
b/lunaix-os/kernel/mm/region.c
index 19355832762035b8e94a34c87d487ac5510e1528..0e0982d7d2d9b0915ed6065c7fb90deb79c000e0 100644
(file)
--- a/
lunaix-os/kernel/mm/region.c
+++ b/
lunaix-os/kernel/mm/region.c
@@
-1,47
+1,71
@@
#include <lunaix/mm/region.h>
#include <lunaix/mm/region.h>
-#include <lunaix/mm/kalloc.h>
-#include <lunaix/process.h>
+#include <lunaix/mm/valloc.h>
-void region_add(struct proc_info* proc,unsigned long start, unsigned long end, unsigned int attr) {
- struct mm_region* region = lxmalloc(sizeof(struct mm_region));
+struct mm_region*
+region_add(struct llist_header* lead,
+ unsigned long start,
+ unsigned long end,
+ unsigned int attr)
+{
+ struct mm_region* region = valloc(sizeof(struct mm_region));
- *region = (struct mm_region) {
- .attr = attr,
- .end = end,
- .start = start
- };
+ *region = (struct mm_region){ .attr = attr, .end = end, .start = start };
- if (
!proc->mm.regions
) {
- llist_
init_head(
®ion->head);
-
proc->mm.regions =
region;
+ if (
llist_empty(lead)
) {
+ llist_
append(lead,
®ion->head);
+
return
region;
}
}
- else {
- llist_append(&proc->mm.regions->head, ®ion->head);
+
+ struct mm_region *pos, *n;
+ llist_for_each(pos, n, lead, head)
+ {
+ if (start >= pos->end && end <= n->start) {
+ break;
+ }
}
}
+
+ llist_insert_after(&pos->head, ®ion->head);
+ return region;
}
}
-void region_release_all(struct proc_info* proc) {
- struct mm_region* head = proc->mm.regions;
+void
+region_release_all(struct llist_header* lead)
+{
struct mm_region *pos, *n;
struct mm_region *pos, *n;
- llist_for_each(pos, n, &head->head, head) {
- lxfree(pos);
+ llist_for_each(pos, n, lead, head)
+ {
+ vfree(pos);
+ }
+}
+
+void
+region_copy(struct llist_header* src, struct llist_header* dest)
+{
+ if (!src) {
+ return;
}
}
- proc->mm.regions = NULL;
+ struct mm_region *pos, *n;
+
+ llist_for_each(pos, n, src, head)
+ {
+ region_add(dest, pos->start, pos->end, pos->attr);
+ }
}
}
-struct mm_region*
region_get(struct proc_info* proc, unsigned long vaddr) {
- struct mm_region* head = proc->mm.regions;
-
- if (
!head
) {
+struct mm_region*
+region_get(struct llist_header* lead, unsigned long vaddr)
+{
+ if (
llist_empty(lead)
) {
return NULL;
}
struct mm_region *pos, *n;
return NULL;
}
struct mm_region *pos, *n;
- llist_for_each(pos, n, &head->head, head) {
- if (vaddr >= pos->start && vaddr < pos->end) {
+ llist_for_each(pos, n, lead, head)
+ {
+ if (pos->start <= vaddr && vaddr < pos->end) {
return pos;
}
}
return pos;
}
}