1 | |
---|
2 | /* |
---|
3 | * _calloc_r Implementation |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-2007. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #ifdef RTEMS_NEWLIB |
---|
20 | #include "malloc_p.h" |
---|
21 | |
---|
22 | #include <sys/reent.h> |
---|
23 | #include <stdlib.h> |
---|
24 | |
---|
25 | |
---|
26 | static void rtems_malloc_statistics_initialize( void ) |
---|
27 | { |
---|
28 | /* |
---|
29 | * Zero all the statistics |
---|
30 | */ |
---|
31 | (void) memset(&rtems_malloc_statistics, 0, sizeof(rtems_malloc_statistics)); |
---|
32 | } |
---|
33 | |
---|
34 | static void rtems_malloc_statistics_at_malloc( |
---|
35 | void *pointer |
---|
36 | ) |
---|
37 | { |
---|
38 | uintptr_t actual_size = 0; |
---|
39 | uint32_t current_depth; |
---|
40 | rtems_malloc_statistics_t *s = &rtems_malloc_statistics; |
---|
41 | |
---|
42 | if ( !pointer ) |
---|
43 | return; |
---|
44 | |
---|
45 | _Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &actual_size); |
---|
46 | |
---|
47 | MSBUMP(lifetime_allocated, actual_size); |
---|
48 | |
---|
49 | current_depth = (uint32_t) (s->lifetime_allocated - s->lifetime_freed); |
---|
50 | if (current_depth > s->max_depth) |
---|
51 | s->max_depth = current_depth; |
---|
52 | } |
---|
53 | |
---|
54 | /* |
---|
55 | * If the pointer is not in the heap, then we won't be able to get its |
---|
56 | * size and thus we skip updating the statistics. |
---|
57 | */ |
---|
58 | static void rtems_malloc_statistics_at_free( |
---|
59 | void *pointer |
---|
60 | ) |
---|
61 | { |
---|
62 | uintptr_t size; |
---|
63 | |
---|
64 | if (_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &size) ) { |
---|
65 | MSBUMP(lifetime_freed, size); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | rtems_malloc_statistics_functions_t rtems_malloc_statistics_helpers_table = { |
---|
70 | rtems_malloc_statistics_initialize, |
---|
71 | rtems_malloc_statistics_at_malloc, |
---|
72 | rtems_malloc_statistics_at_free, |
---|
73 | }; |
---|
74 | |
---|
75 | #endif |
---|