From e033569910aecb4d8fb437a622e542b8803834ec Mon Sep 17 00:00:00 2001 From: Kimplul Date: Tue, 24 May 2022 21:18:55 +0300 Subject: initial musings about exec --- common/vmem.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'common/vmem.c') 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); } -- cgit v1.3