+ *region = (struct mm_region){ .attr = attr,
+ .start = start,
+ .end = start + length - 1 };
+ return region;
+}
+
+void
+region_add(vm_regions_t* lead, struct mm_region* vmregion)
+{
+ if (llist_empty(lead)) {
+ llist_append(lead, &vmregion->head);
+ return;
+ }
+
+ ptr_t cur_end = 0;
+ struct mm_region *pos = (struct mm_region*)lead,
+ *n = list_entry(lead->next, struct mm_region, head);
+ do {
+ if (vmregion->start >= cur_end && vmregion->end <= n->start) {
+ break;
+ }
+ cur_end = n->end;
+ pos = n;
+ n = list_entry(n->head.next, struct mm_region, head);
+ } while ((ptr_t)&pos->head != (ptr_t)lead);
+
+ // XXX caution. require mm_region::head to be the lead of struct
+ llist_insert_after(&pos->head, &vmregion->head);
+}