From d9455d531e9132b0325a49003ce18d6af05ac71d Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 6 Dec 2013 11:21:39 -0500 Subject: [PATCH] update the mapping pointers on successful mremaps --- include/shm.h | 2 ++ syscalls/mremap.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/shm.h b/include/shm.h index 7b75c53..33dc4bd 100644 --- a/include/shm.h +++ b/include/shm.h @@ -72,6 +72,8 @@ struct shm_s { unsigned long retval[MAX_NR_CHILDREN]; + unsigned long scratch[MAX_NR_CHILDREN]; + int current_fd; unsigned int fd_lifetime; diff --git a/syscalls/mremap.c b/syscalls/mremap.c index 9be6a51..0f156a4 100644 --- a/syscalls/mremap.c +++ b/syscalls/mremap.c @@ -5,6 +5,7 @@ */ #include #include +#include #include "trinity.h" // page_size #include "arch.h" #include "maps.h" @@ -31,6 +32,7 @@ static void sanitise_mremap(int childno) shm->a1[childno] &= PAGE_MASK; map = get_map(); + shm->scratch[childno] = (unsigned long) map; /* Save this for ->post */ shm->a1[childno] = (unsigned long) map->ptr; shm->a2[childno] = map->size; @@ -51,9 +53,18 @@ static void sanitise_mremap(int childno) p[i] = 1; } -static void post_mremap(__unused__ int childno) + +/* + * If we successfully remapped a range, we need to update our record of it + * so we don't re-use the old address. + */ +static void post_mremap(int childno) { - //FIXME: Need to stash a ptr to the map struct, and update it on success. + struct map *map = (struct map *) shm->scratch[childno]; + void *ptr = (void *) shm->retval[childno]; + + if (ptr != MAP_FAILED) + map->ptr = ptr; } struct syscall syscall_mremap = { -- 2.11.4.GIT