12 #include "trinity.h" // page_size
14 /* Walk the list, get the j'th element */
15 static struct map
* __get_map(struct list_head
*head
, unsigned int max
)
17 struct list_head
*node
;
19 unsigned int i
, j
= 0;
23 list_for_each(node
, head
) {
26 m
= (struct map
*) node
;
35 struct map
* get_map(void)
40 /* If we're not running in child context, just do shared mappings. */
42 return __get_map(&shared_mappings
->list
, num_shared_mappings
);
44 /* Only toss the dice if we actually have local mappings. */
45 if (shm
->num_mappings
[this_child
] > 0)
49 map
= __get_map(&shm
->mappings
[this_child
]->list
, shm
->num_mappings
[this_child
]);
51 map
= __get_map(&shared_mappings
->list
, num_shared_mappings
);
56 static void delete_local_mapping(int childno
, struct map
*map
)
59 shm
->num_mappings
[childno
]--;
62 void delete_mapping(int childno
, struct map
*map
)
64 if (map
->type
== MAP_LOCAL
)
65 delete_local_mapping(childno
, map
);
67 /* Right now, we don't want to delete MAP_GLOBAL mappings */
70 struct map
* common_set_mmap_ptr_len(int childno
)
74 map
= (struct map
*) shm
->a1
[childno
];
75 shm
->scratch
[childno
] = (unsigned long) map
; /* Save this for ->post */
82 shm
->a1
[childno
] = (unsigned long) map
->ptr
;
83 shm
->a2
[childno
] = map
->size
; //TODO: Munge this.
88 void dirty_mapping(struct map
*map
)
92 unsigned int num_pages
= map
->size
/ page_size
;
94 /* Check mapping is writable. */
95 if (!(map
->prot
& PROT_WRITE
))
100 /* Just fault in one page. */
101 p
[rand() % map
->size
] = rand();
105 /* fault in the whole mapping. */
106 for (i
= 0; i
< map
->size
; i
+= page_size
)
111 /* every other page. */
112 for (i
= 0; i
< map
->size
; i
+= (page_size
* 2))
117 /* whole mapping in reverse */
118 for (i
= map
->size
; i
> 0; i
-= page_size
)
123 /* fault in map->size pages. (some may be faulted >once) */
124 for (i
= 0; i
< num_pages
; i
++);
125 p
[rand() % (num_pages
+ 1)] = rand();
129 /* fault in the last page in a mapping
130 * Fill it with ascii, in the hope we do something like
131 * a strlen and go off the end. */
132 memset((void *) p
+ (map
->size
- page_size
), 'A', page_size
);