7 #include "trinity.h" // page_size
8 #include "arch.h" // KERNEL_ADDR etc
17 static bool within_page(void *addr, void *check)
21 if ((addr > check) && (addr < (check + page_size)))
26 bool validate_address(void *addr)
28 if (within_page(addr, shm) == TRUE)
30 if (within_page(addr, page_rand) == TRUE)
32 if (within_page(addr, page_zeros) == TRUE)
34 if (within_page(addr, page_0xff) == TRUE)
36 if (within_page(addr, page_allocs) == TRUE)
43 static void * _get_address(unsigned char null_allowed
)
49 if (null_allowed
== TRUE
)
58 case 1: addr
= (void *) KERNEL_ADDR
;
60 case 2: addr
= page_zeros
;
62 case 3: addr
= page_0xff
;
64 case 4: addr
= page_rand
;
66 case 5: addr
= page_allocs
;
68 case 6: addr
= (void *)(unsigned long)rand64();
70 case 7: map
= get_map();
73 case 8: addr
= malloc(page_size
* 2);
74 // FIXME: We leak this. This is the address we need to store for later
75 // freeing, not the potentially munged version below.
76 // tricky. We want to hand the munged version out too, so we might end up
77 // having to split this into alloc_address / get_address.
80 BUG("unreachable!\n");
85 * Most of the time, we just return the address we got above unmunged.
86 * But sometimes, we return an address just before the end of the page.
87 * The idea here is that we might see some bugs that are caused by page boundary failures.
91 case 0: addr
+= (page_size
- sizeof(char));
93 case 1: addr
+= (page_size
- sizeof(int));
95 case 2: addr
+= (page_size
- sizeof(long));
97 case 3: addr
+= (page_size
/ 2);
106 void * get_address(void)
108 return _get_address(TRUE
);
111 void * get_non_null_address(void)
113 return _get_address(FALSE
);
117 unsigned long find_previous_arg_address(unsigned int argnum
, unsigned int call
, int childno
)
119 unsigned long addr
= 0;
122 if ((syscalls
[call
].entry
->arg1type
== ARG_ADDRESS
) ||
123 (syscalls
[call
].entry
->arg1type
== ARG_NON_NULL_ADDRESS
))
124 addr
= shm
->a1
[childno
];
127 if ((syscalls
[call
].entry
->arg2type
== ARG_ADDRESS
) ||
128 (syscalls
[call
].entry
->arg2type
== ARG_NON_NULL_ADDRESS
))
129 addr
= shm
->a2
[childno
];
132 if ((syscalls
[call
].entry
->arg3type
== ARG_ADDRESS
) ||
133 (syscalls
[call
].entry
->arg3type
== ARG_NON_NULL_ADDRESS
))
134 addr
= shm
->a3
[childno
];
137 if ((syscalls
[call
].entry
->arg4type
== ARG_ADDRESS
) ||
138 (syscalls
[call
].entry
->arg4type
== ARG_NON_NULL_ADDRESS
))
139 addr
= shm
->a4
[childno
];
142 if ((syscalls
[call
].entry
->arg5type
== ARG_ADDRESS
) ||
143 (syscalls
[call
].entry
->arg5type
== ARG_NON_NULL_ADDRESS
))
144 addr
= shm
->a5
[childno
];
151 * iovec's are just special cases of the ARG_ADDRESS's
153 struct iovec
* alloc_iovec(unsigned int num
)
158 iov
= malloc(num
* sizeof(struct iovec
));
160 for (i
= 0; i
< num
; i
++) {
161 iov
[i
].iov_base
= malloc(page_size
);
162 iov
[i
].iov_len
= page_size
;