split up constants.h some
[trinity.git] / shm.c
blob7248b55459dea1b3a8f2e592956843e91ae262ba
1 /*
2 * Shared mapping creation.
3 */
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/mman.h>
9 #include "arch.h"
10 #include "child.h"
11 #include "log.h"
12 #include "params.h"
13 #include "pids.h"
14 #include "random.h"
15 #include "shm.h"
16 #include "utils.h"
18 struct shm_s *shm;
20 #define SHM_PROT_PAGES 30
22 void create_shm(void)
24 void *p;
25 unsigned int shm_pages;
27 /* round up shm to nearest page size */
28 shm_pages = ((sizeof(struct shm_s) + page_size - 1) & ~(page_size - 1)) / page_size;
30 /* Waste some address space to set up some "protection" near the SHM location. */
31 p = alloc_shared((SHM_PROT_PAGES + shm_pages + SHM_PROT_PAGES) * page_size);
33 /* clear whole mapping, including the redzones. */
34 memset(p, 0, shm_pages * page_size);
36 /* set the redzones to PROT_NONE */
37 mprotect(p, SHM_PROT_PAGES * page_size, PROT_NONE);
38 mprotect(p + (SHM_PROT_PAGES + shm_pages) * page_size,
39 SHM_PROT_PAGES * page_size, PROT_NONE);
41 shm = p + SHM_PROT_PAGES * page_size;
44 void create_shm_arrays(void)
46 shm->child_op_count = alloc_shared(max_children * sizeof(unsigned long));
48 shm->pids = alloc_shared(max_children * sizeof(pid_t));
50 shm->tv = alloc_shared(max_children * sizeof(struct timeval));
52 shm->syscall = alloc_shared(max_children * sizeof(struct syscallrecord));
53 shm->previous = alloc_shared(max_children * sizeof(struct syscallrecord));
55 shm->mappings = alloc_shared(max_children * sizeof(struct map *));
56 shm->num_mappings = alloc_shared(max_children * sizeof(unsigned int));
58 shm->seeds = alloc_shared(max_children * sizeof(int));
59 shm->kill_count = alloc_shared(max_children * sizeof(unsigned char));
60 shm->logfiles = alloc_shared(max_children * sizeof(FILE *));
61 shm->scratch = alloc_shared(max_children * sizeof(unsigned long));
64 void init_shm(void)
66 unsigned int i;
68 output(2, "shm is at %p\n", shm);
70 shm->total_syscalls_done = 1;
72 if (user_set_seed == TRUE)
73 shm->seed = init_seed(seed);
74 else
75 shm->seed = new_seed();
76 /* Set seed in parent thread */
77 set_seed(0);
79 for (i = 0; i < max_children; i++) {
81 shm->pids[i] = EMPTY_PIDSLOT;
83 shm->previous[i].nr = shm->syscall[i].nr = -1;
85 shm->previous[i].a1 = shm->syscall[i].a1 = -1;
86 shm->previous[i].a2 = shm->syscall[i].a2 = -1;
87 shm->previous[i].a3 = shm->syscall[i].a3 = -1;
88 shm->previous[i].a4 = shm->syscall[i].a4 = -1;
89 shm->previous[i].a5 = shm->syscall[i].a5 = -1;
90 shm->previous[i].a6 = shm->syscall[i].a6 = -1;