split up constants.h some
[trinity.git] / syscalls / munmap.c
blob2ed4b90ec1951cf93ed4b4f773e4361ec0e07543
1 /*
2 * SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
3 */
4 #include <stdlib.h>
5 #include "arch.h"
6 #include "maps.h"
7 #include "random.h"
8 #include "sanitise.h"
9 #include "shm.h"
11 #define WHOLE 1
12 static int action;
14 static void sanitise_munmap(int childno)
16 struct map *map;
17 unsigned long len;
18 unsigned long nr_pages;
19 unsigned long offset, offsetpagenr;
21 map = common_set_mmap_ptr_len(childno);
23 action = 0;
25 switch (rand() % 20) {
26 case 0:
27 /* delete the whole mapping. */
28 action = WHOLE;
29 return;
31 case 1 ... 10:
32 /* unmap a range of the mapping. */
33 nr_pages = map->size / page_size;
34 offsetpagenr = (rand() % nr_pages);
35 offset = offsetpagenr * page_size;
36 shm->syscall[childno].a1 = (unsigned long) map->ptr + offset;
38 len = (rand() % (nr_pages - offsetpagenr)) + 1;
39 len *= page_size;
40 shm->syscall[childno].a2 = len;
41 return;
43 case 11 ... 19:
44 /* just unmap 1 page of the mapping. */
45 shm->syscall[childno].a1 = (unsigned long) map->ptr;
46 shm->syscall[childno].a1 += (rand() % map->size) & PAGE_MASK;
47 shm->syscall[childno].a2 = page_size;
48 return;
50 default:
51 break;
55 static void post_munmap(int childno)
57 struct map *map = (struct map *) shm->scratch[childno];
59 if (shm->syscall[childno].retval != 0)
60 return;
62 if (action == WHOLE)
63 delete_mapping(childno, map);
65 shm->scratch[childno] = 0;
68 struct syscallentry syscall_munmap = {
69 .name = "munmap",
70 .num_args = 2,
71 .arg1name = "addr",
72 .arg1type = ARG_MMAP,
73 .arg2name = "len",
74 .group = GROUP_VM,
75 .sanitise = sanitise_munmap,
76 .post = post_munmap,