move_pages: just use calloc
[trinity.git] / maps-static.c
blob174b094313642aa9c57bdd56c4036e558a265ce6
1 #include <malloc.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "arch.h"
5 #include "log.h"
6 #include "maps.h"
7 #include "random.h"
8 #include "utils.h"
10 /* "static" pages. */
11 char *page_zeros;
12 char *page_0xff;
13 char *page_rand;
14 unsigned long *page_allocs;
15 unsigned long *page_maps;
17 static void * __allocbuf(const char *name)
19 void *ptr;
21 ptr = memalign(page_size, page_size * 2);
22 if (!ptr)
23 exit(EXIT_FAILURE);
24 output(2, "%s @ %p\n", name, ptr);
25 return ptr;
28 void init_shared_pages(void)
30 unsigned int i;
32 // a page of zeros
33 page_zeros = __allocbuf("page_zeros");
34 memset(page_zeros, 0, page_size * 2);
36 // a page of 0xff
37 page_0xff = __allocbuf("page_0xff");
38 memset(page_0xff, 0xff, page_size * 2);
40 // a page of random crap (overwritten below)
41 page_rand = __allocbuf("page_rand");
43 // page containing ptrs to mallocs.
44 page_allocs = __allocbuf("page_allocs");
45 for (i = 0; i < (page_size / sizeof(unsigned long *)); i++)
46 page_allocs[i] = (unsigned long) malloc(page_size);
48 // a page of ptrs to mmaps (set up at child init time).
49 page_maps = __allocbuf("page_maps");
51 // mmaps that get shared across children.
52 setup_shared_mappings();
54 // generate_random_page may end up using shared_mappings, so has to be last.
55 generate_random_page(page_rand);