]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | /* btalloc() provides a mechanism for allocating via permuted backtraces. */ |
2 | void *btalloc(size_t size, unsigned bits); | |
3 | ||
4 | #define btalloc_n_proto(n) \ | |
5 | void *btalloc_##n(size_t size, unsigned bits); | |
6 | btalloc_n_proto(0) | |
7 | btalloc_n_proto(1) | |
8 | ||
9 | #define btalloc_n_gen(n) \ | |
10 | void * \ | |
11 | btalloc_##n(size_t size, unsigned bits) \ | |
12 | { \ | |
13 | void *p; \ | |
14 | \ | |
15 | if (bits == 0) \ | |
16 | p = mallocx(size, 0); \ | |
17 | else { \ | |
18 | switch (bits & 0x1U) { \ | |
19 | case 0: \ | |
20 | p = (btalloc_0(size, bits >> 1)); \ | |
21 | break; \ | |
22 | case 1: \ | |
23 | p = (btalloc_1(size, bits >> 1)); \ | |
24 | break; \ | |
25 | default: not_reached(); \ | |
26 | } \ | |
27 | } \ | |
28 | /* Intentionally sabotage tail call optimization. */ \ | |
29 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); \ | |
30 | return (p); \ | |
31 | } |