13 /* Walk a list, get a random element */
14 static struct map
* __get_map(struct list_head
*head
, unsigned int max
)
16 struct list_head
*node
;
18 unsigned int i
, j
= 0;
22 list_for_each(node
, head
) {
25 m
= (struct map
*) node
;
34 /* Return a pointer a previous mmap() that we did, either during startup,
35 * or from a fuzz result. */
36 struct map
* get_map(void)
41 /* We can get called by child processes, and also during startup by
42 * the main process when it constructs page_rand etc.
43 * If we're not running in child context, just do shared mappings.
44 * because main doesn't have any 'local' mappings.
46 if (this_child
!= 0) {
47 if (shm
->num_mappings
[this_child
] > 0)
52 map
= __get_map(&shm
->mappings
[this_child
]->list
, shm
->num_mappings
[this_child
]);
54 map
= __get_map(&shared_mappings
->list
, num_shared_mappings
);
59 static void delete_local_mapping(int childno
, struct map
*map
)
62 shm
->num_mappings
[childno
]--;
65 /* Called from munmap()'s ->post routine. */
66 void delete_mapping(int childno
, struct map
*map
)
68 if (map
->type
== MAP_LOCAL
)
69 delete_local_mapping(childno
, map
);
71 /* Right now, we don't want to delete MAP_GLOBAL mappings */
74 /* used in several sanitise_* functions. */
75 struct map
* common_set_mmap_ptr_len(int childno
)
79 map
= (struct map
*) shm
->syscall
[childno
].a1
;
80 shm
->scratch
[childno
] = (unsigned long) map
; /* Save this for ->post */
82 shm
->syscall
[childno
].a1
= 0;
83 shm
->syscall
[childno
].a2
= 0;
87 shm
->syscall
[childno
].a1
= (unsigned long) map
->ptr
;
88 shm
->syscall
[childno
].a2
= map
->size
; //TODO: Munge this.