Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE]TEST MUNMAP #582

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 55 additions & 24 deletions vm/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,22 @@

int _vm_munmap(vm_map_t *map, void *vaddr, size_t size)
{
ptr_t pvaddr;

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-qemu)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zedboard)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zturn)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m4-stm32l4x6-nucleo)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt105x-evk)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-spike)

unused variable 'pvaddr' [-Wunused-variable]

Check warning on line 375 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon3-gr716-mini)

unused variable 'pvaddr' [-Wunused-variable]
long offs;
map_entry_t *e, *s;
map_entry_t t;
process_t *proc = proc_current()->process;
size_t overlapEOffset;

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-qemu)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zedboard)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zturn)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m4-stm32l4x6-nucleo)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt105x-evk)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-spike)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]

Check warning on line 380 in vm/map.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon3-gr716-mini)

variable 'overlapEOffset' set but not used [-Wunused-but-set-variable]
size_t overlapSize;
ptr_t overlapStart, overlapEnd;
int putEntry;

t.vaddr = vaddr;
t.size = size;

/* Region to unmap can span across multiple entries. */
/* rbFind finds any entry having an overlap with the region in an unspecified order. */
for (;;) {
for (int i = 0;; i++) {
e = lib_treeof(map_entry_t, linkage, lib_rbFind(&map->tree, &t.linkage));
if (e == NULL) {
break;
Expand All @@ -392,47 +397,51 @@
proc = e->process;
#endif

/* Note: what if NEEDS_COPY? */
amap_putanons(e->amap, (e->aoffs + vaddr) - e->vaddr, size);
overlapStart = max((ptr_t)e->vaddr, (ptr_t)vaddr);
overlapEnd = min((ptr_t)e->vaddr + e->size, (ptr_t)vaddr + size);
overlapSize = (size_t)(overlapEnd - overlapStart);
overlapEOffset = (size_t)(overlapStart - (ptr_t)e->vaddr);

for (offs = (vaddr - e->vaddr); offs < ((vaddr + size) - e->vaddr); offs += SIZE_PAGE) {
pmap_remove(&map->pmap, e->vaddr + offs);
}
putEntry = 0;

if (e->vaddr == vaddr) {
if (e->size == size) {
_entry_put(map, e);
LIB_ASSERT_ALWAYS(!i, "i, MUNMAP %zx %zx %zx %zx\n", overlapStart, vaddr, overlapSize, size);
LIB_ASSERT_ALWAYS(overlapStart == (ptr_t)vaddr && overlapSize == size, "sizes, MUNMAP %zx %zx %zx %zx\n", overlapStart, vaddr, overlapSize, size);
LIB_ASSERT_ALWAYS((size & (SIZE_PAGE - 1)) == 0, "align, MUNMAP %zx %zx %zx %zx\n", overlapStart, vaddr, overlapSize, size);

if ((ptr_t)e->vaddr == overlapStart) {
if (e->size == overlapSize) {
putEntry = 1;
}
else {
e->aoffs += size;
e->vaddr += size;
e->size -= size;
e->lmaxgap += size;
e->aoffs += overlapSize;
e->vaddr += overlapSize;
e->size -= overlapSize;
e->lmaxgap += overlapSize;

s = lib_treeof(map_entry_t, linkage, lib_rbPrev(&e->linkage));
if (s != NULL) {
s->rmaxgap += size;
s->rmaxgap += overlapSize;
map_augment(&s->linkage);
}

map_augment(&e->linkage);
}
}
else if ((e->vaddr + e->size) == (vaddr + size)) {
e->size -= size;
e->rmaxgap += size;
else if ((ptr_t)(e->vaddr + e->size) == overlapEnd) {
e->size -= overlapSize;
e->rmaxgap += overlapSize;

s = lib_treeof(map_entry_t, linkage, lib_rbNext(&e->linkage));
if (s != NULL) {
s->lmaxgap += size;
s->lmaxgap += overlapSize;
map_augment(&s->linkage);
}

map_augment(&e->linkage);
}
else {
s = map_alloc();
/* This case if only possible if unmapped region if in the middle of single entry,
/* This case if only possible if an unmapped region is in the middle of a single entry,
* so there is no possibility of partially unmapping. */
if (s == NULL) {
return -ENOMEM;
Expand All @@ -442,19 +451,41 @@
s->prot = e->prot;
s->protOrig = e->protOrig;
s->object = vm_objectRef(e->object);
s->offs = (e->offs == -1) ? -1 : (e->offs + ((vaddr + size) - e->vaddr));
s->vaddr = vaddr + size;
// s->offs = (e->offs == -1) ? -1 : (e->offs + overlapEOffset + overlapSize);
s->offs = (e->offs == -1) ? -1 : (e->offs + (overlapEnd - (ptr_t)e->vaddr));
s->vaddr = (void *)overlapEnd;
// s->size = e->size - (overlapEOffset + overlapSize);
s->size = (size_t)((e->vaddr + e->size) - s->vaddr);
s->aoffs = e->aoffs + ((vaddr + size) - e->vaddr);
s->aoffs = e->aoffs + (overlapEnd - (ptr_t)e->vaddr);

s->amap = amap_ref(e->amap);

e->size = (size_t)(vaddr - e->vaddr);
e->rmaxgap = size;
// e->size = overlapEOffset;
e->size = (size_t)(overlapStart - (ptr_t)e->vaddr);
e->rmaxgap = overlapSize;

map_augment(&e->linkage);
_map_add(proc, map, s);
}

/* Perform amap and pmap changes only when we are sure we have enough space to perform corresponding map changes. */

/* Note: what if NEEDS_COPY? */
// amap_putanons(e->amap, e->aoffs + overlapEOffset, overlapSize);

// for (pvaddr = overlapStart; pvaddr < overlapEnd; pvaddr += SIZE_PAGE) {
// pmap_remove(&map->pmap, (void *)pvaddr);
// }

amap_putanons(e->amap, (e->aoffs + overlapStart) - (ptr_t)e->vaddr, overlapSize);

for (offs = (overlapStart - (ptr_t)e->vaddr); offs < (overlapEnd - (ptr_t)e->vaddr); offs += SIZE_PAGE) {
pmap_remove(&map->pmap, e->vaddr + offs);
}

if (putEntry != 0) {
_entry_put(map, e);
}
}

return EOK;
Expand Down
Loading