]>
Commit | Line | Data |
---|---|---|
1 | /********************************************************************* | |
2 | * free_all() | |
3 | * | |
4 | * Empties all memory regions so that their entire buffer space is | |
5 | * considered unused. This allows the client to restart without | |
6 | * having to reallocate memory for the allocator regions, which helps | |
7 | * performance when this package gets used serially. | |
8 | *********************************************************************/ | |
9 | __private_extern__ | |
10 | void free_all(void) { | |
11 | malloc_region * cur_region; | |
12 | ||
13 | queue_iterate(&malloc_region_list, cur_region, malloc_region *, links) { | |
14 | ||
15 | queue_init(&cur_region->block_list); | |
16 | cur_region->free_size = cur_region->region_size - sizeof(malloc_region); | |
17 | cur_region->free_address = &cur_region->buffer; | |
18 | ||
19 | } | |
20 | ||
21 | queue_init(&sorted_free_block_list); | |
22 | ||
23 | #ifdef CLIENT_DEBUG | |
24 | current_block_total = 0; | |
25 | #endif /* CLIENT_DEBUG */ | |
26 | ||
27 | return; | |
28 | ||
29 | } /* free_all() */ | |
30 | ||
31 | ||
32 | /********************************************************************* | |
33 | * malloc_size() | |
34 | * | |
35 | *********************************************************************/ | |
36 | __private_extern__ | |
37 | size_t malloc_size(void * address) { | |
38 | malloc_region * found_region = NULL; | |
39 | malloc_block * found_block = NULL; | |
40 | ||
41 | malloc_find_block(address, &found_block, &found_region); | |
42 | ||
43 | ||
44 | /* If we couldn't find the requested block, | |
45 | * the caller is in error so return 0. | |
46 | */ | |
47 | if (found_block == NULL) { | |
48 | return 0; | |
49 | // FIXME: panic? | |
50 | } | |
51 | ||
52 | return (found_block->block_size - sizeof(malloc_block)); | |
53 | ||
54 | } /* malloc_size() */ | |
55 | ||
56 | ||
57 | /********************************************************************* | |
58 | * malloc_is_valid() | |
59 | * | |
60 | *********************************************************************/ | |
61 | __private_extern__ | |
62 | int malloc_is_valid(void * address){ | |
63 | malloc_region * found_region = NULL; | |
64 | malloc_block * found_block = NULL; | |
65 | ||
66 | malloc_find_block(address, &found_block, &found_region); | |
67 | ||
68 | if (found_block != NULL) { | |
69 | return 1; | |
70 | } else { | |
71 | return 0; | |
72 | } | |
73 | ||
74 | } /* malloc_is_valid() */ | |
75 | ||
76 |