aboutsummaryrefslogtreecommitdiff
path: root/common/vmem.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-05-24 21:18:55 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-05-24 21:18:55 +0300
commite033569910aecb4d8fb437a622e542b8803834ec (patch)
treeb7e31d1b266dfbd3b1aa79ae4db47d584541c8bc /common/vmem.c
parent12be40e22aae582cca9abbd151031edaab800cae (diff)
downloadkmi-e033569910aecb4d8fb437a622e542b8803834ec.tar.gz
kmi-e033569910aecb4d8fb437a622e542b8803834ec.zip
initial musings about exec
Diffstat (limited to 'common/vmem.c')
-rw-r--r--common/vmem.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/common/vmem.c b/common/vmem.c
index ae40748..3ea9ed7 100644
--- a/common/vmem.c
+++ b/common/vmem.c
@@ -25,15 +25,26 @@ static stat_t __free_mapped_region(struct tcb *t, struct mem_region *m)
return status;
}
-stat_t destroy_uvmem(struct tcb *t)
+stat_t clear_uvmem(struct tcb *t, bool force)
{
struct mem_region *m = find_first_region(&t->sp_r);
while (m) {
- /* free all memory associated with used regions */
- if (is_region_used(m))
+ /* if force is not set, free only regions that are not marked to
+ * be kept and are owned.
+ *
+ * if force is set, free all owned regions.
+ */
+ if (is_region_owned(m) && (force || !is_region_kept(m)))
__free_mapped_region(t, m);
}
+ return OK;
+}
+
+stat_t destroy_uvmem(struct tcb *t)
+{
+ /* force clear all regions */
+ clear_uvmem(t, true);
/* destroy region tree itself */
return destroy_region(&t->sp_r);
}