merge clone variants
[trinity.git] / syscalls / mremap.c
bloba62c480f5abd1d66dd697b0de5a4c3e2db81041b
1 /*
2 * asmlinkage unsigned long sys_mremap(unsigned long addr,
3 * unsigned long old_len, unsigned long new_len,
4 * unsigned long flags, unsigned long new_addr)
5 */
7 #include <stdlib.h>
8 #include <sys/mman.h>
9 #include "utils.h" // page_size
10 #include "arch.h"
11 #include "maps.h"
12 #include "random.h"
13 #include "sanitise.h"
14 #include "shm.h"
15 #include "utils.h"
17 static unsigned long rand_size(void)
19 const unsigned long sizes[] = { 1 * MB, 2 * MB, 4 * MB, 10 * MB, 1 * GB, 2 * GB };
21 return sizes[rand() % ARRAY_SIZE(sizes)];
24 static void sanitise_mremap(int childno)
26 struct map *map;
28 map = common_set_mmap_ptr_len(childno);
30 shm->a3[childno] = map->size; //TODO: Munge this.
32 if (shm->a4[childno] & MREMAP_FIXED) {
33 shm->a5[childno] = rand_size();
34 } else {
35 shm->a5[childno] = 0;
38 /* Sometimes dirty the mapping first. */
39 if (!(map->prot & PROT_WRITE))
40 return;
42 if (rand_bool())
43 dirty_mapping(map);
47 * If we successfully remapped a range, we need to update our record of it
48 * so we don't re-use the old address.
50 static void post_mremap(int childno)
52 struct map *map = (struct map *) shm->scratch[childno];
53 void *ptr = (void *) shm->retval[childno];
55 if (ptr != MAP_FAILED)
56 map->ptr = ptr;
58 shm->scratch[childno] = 0;
61 struct syscallentry syscall_mremap = {
62 .name = "mremap",
63 .num_args = 5,
64 .sanitise = sanitise_mremap,
65 .arg1name = "addr",
66 .arg1type = ARG_MMAP,
67 .arg2name = "old_len",
68 .arg3name = "new_len",
69 .arg4name = "flags",
70 .arg4type = ARG_LIST,
71 .arg4list = {
72 .num = 2,
73 .values = { MREMAP_MAYMOVE, MREMAP_FIXED },
75 .arg5name = "new_addr",
76 .arg5type = ARG_ADDRESS,
77 .group = GROUP_VM,
78 .post = post_mremap,