[4d3017a] | 1 | /** |
---|
[3cf4031] | 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Standard C Library Support |
---|
| 5 | * |
---|
[21242c2] | 6 | * This include file contains the information regarding the |
---|
| 7 | * RTEMS specific support for the standard C library. |
---|
[4d3017a] | 8 | */ |
---|
| 9 | |
---|
[21242c2] | 10 | /* |
---|
| 11 | * COPYRIGHT (c) 1989-2011. |
---|
[ac7d5ef0] | 12 | * On-Line Applications Research Corporation (OAR). |
---|
| 13 | * |
---|
[98e4ebf5] | 14 | * The license and distribution terms for this file may be |
---|
| 15 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 16 | * http://www.rtems.org/license/LICENSE. |
---|
[ac7d5ef0] | 17 | */ |
---|
| 18 | |
---|
[7945944] | 19 | #ifndef _RTEMS_RTEMS_LIBCSUPPORT_H |
---|
| 20 | #define _RTEMS_RTEMS_LIBCSUPPORT_H |
---|
[ac7d5ef0] | 21 | |
---|
[e717495] | 22 | #include <sys/types.h> |
---|
| 23 | #include <stdint.h> |
---|
| 24 | |
---|
[253dde0] | 25 | #include <rtems/score/heap.h> |
---|
| 26 | #include <rtems/rtems/tasks.h> |
---|
| 27 | |
---|
[ac7d5ef0] | 28 | #ifdef __cplusplus |
---|
| 29 | extern "C" { |
---|
| 30 | #endif |
---|
| 31 | |
---|
[bcd0ea64] | 32 | /** |
---|
[4027e63] | 33 | * @defgroup libcsupport Standard C Library Support |
---|
[bcd0ea64] | 34 | * |
---|
[4027e63] | 35 | * @brief RTEMS Specific Support for the Standard C Library |
---|
| 36 | * |
---|
[bcd0ea64] | 37 | */ |
---|
[b697bc6] | 38 | /**@{**/ |
---|
[bcd0ea64] | 39 | |
---|
[c64e4ed4] | 40 | extern void malloc_dump(void); |
---|
[bcd0ea64] | 41 | |
---|
| 42 | /** |
---|
[4027e63] | 43 | * @brief Malloc walk. |
---|
[bcd0ea64] | 44 | */ |
---|
[50262970] | 45 | extern bool malloc_walk(int source, bool printf_enabled); |
---|
[c9bb60a] | 46 | |
---|
| 47 | /** |
---|
[4027e63] | 48 | * @brief Set malloc heap pointer. |
---|
[c9bb60a] | 49 | * |
---|
[4027e63] | 50 | * This routine is primarily used for debugging. |
---|
[c9bb60a] | 51 | */ |
---|
[bad5593] | 52 | void malloc_set_heap_pointer(Heap_Control *new_heap); |
---|
[3750995] | 53 | |
---|
| 54 | /** |
---|
[4027e63] | 55 | * @brief Get malloc heap pointer. |
---|
[3750995] | 56 | * |
---|
[4027e63] | 57 | * This routine is primarily used for debugging. |
---|
[3750995] | 58 | */ |
---|
[bad5593] | 59 | Heap_Control *malloc_get_heap_pointer( void ); |
---|
[8b08935] | 60 | extern void libc_init(void); |
---|
[c64e4ed4] | 61 | extern int host_errno(void); |
---|
| 62 | extern void fix_syscall_errno(void); |
---|
[cefc9aea] | 63 | |
---|
| 64 | /** |
---|
[4027e63] | 65 | * @brief Get free malloc information. |
---|
[cefc9aea] | 66 | * |
---|
[4027e63] | 67 | * Find amount of free heap remaining |
---|
[cefc9aea] | 68 | */ |
---|
[df3021ad] | 69 | extern size_t malloc_free_space(void); |
---|
[ac7d5ef0] | 70 | |
---|
[3750995] | 71 | /** |
---|
[4027e63] | 72 | * @brief Get malloc status information. |
---|
[3750995] | 73 | * |
---|
[4027e63] | 74 | * Find amount of free heap remaining. |
---|
[3750995] | 75 | */ |
---|
[7f46921e] | 76 | extern int malloc_info(Heap_Information_block *the_info); |
---|
| 77 | |
---|
[c3db01d0] | 78 | /* |
---|
| 79 | * Prototypes required to install newlib reentrancy user extension |
---|
| 80 | */ |
---|
[d40da79b] | 81 | bool newlib_create_hook( |
---|
[c3db01d0] | 82 | rtems_tcb *current_task, |
---|
| 83 | rtems_tcb *creating_task |
---|
| 84 | ); |
---|
| 85 | |
---|
[e717495] | 86 | #define __RTEMS_NEWLIB_BEGIN 0 |
---|
[c3db01d0] | 87 | |
---|
[1b1be254] | 88 | void newlib_terminate_hook( |
---|
| 89 | rtems_tcb *current_task |
---|
| 90 | ); |
---|
| 91 | |
---|
[c3db01d0] | 92 | #define RTEMS_NEWLIB_EXTENSION \ |
---|
| 93 | { \ |
---|
[d40da79b] | 94 | newlib_create_hook, /* rtems_task_create */ \ |
---|
| 95 | 0, /* rtems_task_start */ \ |
---|
| 96 | 0, /* rtems_task_restart */ \ |
---|
[69aa3349] | 97 | 0, /* rtems_task_delete */ \ |
---|
[d40da79b] | 98 | 0, /* task_switch */ \ |
---|
| 99 | __RTEMS_NEWLIB_BEGIN, /* task_begin */ \ |
---|
| 100 | 0, /* task_exitted */ \ |
---|
[1b1be254] | 101 | 0, /* fatal */ \ |
---|
| 102 | newlib_terminate_hook /* thread terminate */ \ |
---|
[c3db01d0] | 103 | } |
---|
| 104 | |
---|
[c5d2760] | 105 | typedef struct { |
---|
| 106 | uint32_t active_barriers; |
---|
| 107 | uint32_t active_extensions; |
---|
| 108 | uint32_t active_message_queues; |
---|
| 109 | uint32_t active_partitions; |
---|
| 110 | uint32_t active_periods; |
---|
| 111 | uint32_t active_ports; |
---|
| 112 | uint32_t active_regions; |
---|
| 113 | uint32_t active_semaphores; |
---|
| 114 | uint32_t active_tasks; |
---|
| 115 | uint32_t active_timers; |
---|
| 116 | } rtems_resource_rtems_api; |
---|
| 117 | |
---|
| 118 | typedef struct { |
---|
| 119 | uint32_t active_barriers; |
---|
| 120 | uint32_t active_condition_variables; |
---|
| 121 | uint32_t active_keys; |
---|
| 122 | uint32_t active_message_queues; |
---|
| 123 | uint32_t active_message_queue_descriptors; |
---|
| 124 | uint32_t active_mutexes; |
---|
| 125 | uint32_t active_rwlocks; |
---|
| 126 | uint32_t active_semaphores; |
---|
| 127 | uint32_t active_spinlocks; |
---|
| 128 | uint32_t active_threads; |
---|
| 129 | uint32_t active_timers; |
---|
| 130 | } rtems_resource_posix_api; |
---|
| 131 | |
---|
| 132 | typedef struct { |
---|
| 133 | Heap_Information_block workspace_info; |
---|
| 134 | Heap_Information_block heap_info; |
---|
| 135 | rtems_resource_rtems_api rtems_api; |
---|
| 136 | rtems_resource_posix_api posix_api; |
---|
| 137 | int open_files; |
---|
| 138 | } rtems_resource_snapshot; |
---|
| 139 | |
---|
| 140 | /** |
---|
| 141 | * @brief Tasks a snapshot of the resource usage of the system. |
---|
| 142 | * |
---|
[25ba0cd] | 143 | * @param[out] snapshot The snapshot of used resources. |
---|
[c5d2760] | 144 | * |
---|
| 145 | * @see rtems_resource_snapshot_equal() and rtems_resource_snapshot_check(). |
---|
| 146 | * |
---|
| 147 | * @code |
---|
| 148 | * #include <assert.h> |
---|
| 149 | * |
---|
| 150 | * #include <rtems/libcsupport.h> |
---|
| 151 | * |
---|
| 152 | * void example(void) |
---|
| 153 | * { |
---|
| 154 | * rtems_resource_snapshot before; |
---|
| 155 | * |
---|
| 156 | * test_setup(); |
---|
| 157 | * rtems_resource_snapshot_take(&before); |
---|
| 158 | * test(); |
---|
| 159 | * assert(rtems_resource_snapshot_check(&before)); |
---|
| 160 | * test_cleanup(); |
---|
| 161 | * } |
---|
| 162 | * @endcode |
---|
| 163 | */ |
---|
| 164 | void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot); |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | * @brief Compares two resource snapshots for equality. |
---|
| 168 | * |
---|
[25ba0cd] | 169 | * @param[in] a One resource snapshot. |
---|
| 170 | * @param[in] b Another resource snapshot. |
---|
| 171 | * |
---|
[4027e63] | 172 | * @retval true The resource snapshots are equal. |
---|
[25ba0cd] | 173 | * @retval false Otherwise. |
---|
[c5d2760] | 174 | * |
---|
| 175 | * @see rtems_resource_snapshot_take(). |
---|
| 176 | */ |
---|
| 177 | bool rtems_resource_snapshot_equal( |
---|
| 178 | const rtems_resource_snapshot *a, |
---|
| 179 | const rtems_resource_snapshot *b |
---|
| 180 | ); |
---|
| 181 | |
---|
| 182 | /** |
---|
| 183 | * @brief Takes a new resource snapshot and checks that it is equal to the |
---|
[25ba0cd] | 184 | * given resource snapshot. |
---|
[c5d2760] | 185 | * |
---|
[25ba0cd] | 186 | * @param[in] snapshot The resource snapshot used for comparison with the new |
---|
| 187 | * resource snapshot. |
---|
[c5d2760] | 188 | * |
---|
[4027e63] | 189 | * @retval true The resource snapshots are equal. |
---|
[25ba0cd] | 190 | * @retval false Otherwise. |
---|
[c5d2760] | 191 | * |
---|
| 192 | * @see rtems_resource_snapshot_take(). |
---|
| 193 | */ |
---|
| 194 | bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot); |
---|
| 195 | |
---|
[4027e63] | 196 | /** @} */ |
---|
| 197 | |
---|
[ac7d5ef0] | 198 | #ifdef __cplusplus |
---|
| 199 | } |
---|
| 200 | #endif |
---|
| 201 | |
---|
| 202 | #endif |
---|
| 203 | /* end of include file */ |
---|