Global¶
- group Global_supportStdlib
supportStdlib globals
lorem
Macros¶
- group Macros_supportStdlib_h
Variables¶
- group Variables_supportStdlib_h
API’s¶
- group Apis_supportStdlib_h
Getters¶
- group Getters_supportStdlib_h
Setters¶
- group Setters_supportStdlib_h
General¶
- group General_supportStdlib_h
Functions
-
void *supportStdlib_malloc(size_t size)¶
Stdlib malloc function implementation redesigned for CosmOS DEMO. Thread safe.
The implementation contains obtaining of the core configuration by calling function core_getCoreCfg. The return address is set to NULL in the case no suitable memory chunk will be found (to return NULL pointer). Schedulable in execution type is then checked in the implemented if condition if it is equal to the SCHEDULABLE_INSTANCE_ENUM__THREAD, if yes the program variable in execution is obtained by calling function core_getCoreProgramInExecution and used to get the heap configuration structure by calling program_getHeap function. Then the heap configuration structure is used in the functions heap_getHeapLowAddress and heap_getHeapHighAddress to get the heap low and high adresses. The pre-initialization before the do-while loop is needed therefore allocated boolean variable is preset to the False and currentMallocVar pointer is set to the heap low address. Because the heap allocation can be requested from multiple threads within one program the mutual exclusion is needed and mutex_getMutex function is called with the program specific mutex variable. After this point the do-while loop is implemented iterating over the linked list of the mutex variables till the currentMallocVar is not null pointer or till the allocated boolean is not true. Inside the do-while loop is if condition that checks if the currentMallocVar is not NULL - nextAvailableAddress is as the currentMallocVar plus its size member and checked in the nested if condition if the required size argument is smaller than currentMallocVar next member address minus the nextAvailableAddress variable. If no the currentMallocVar is set to the currentMallocVar next member. If yes the new malloc variable is allocated by calling supportStdlib_mallocVar helper function and the result is then used to linked it between the currentMallocVar and the next malloc variable. Then to the returnAddress is stored the newly allocated address with the respect to the aligned malloc variable offset and allocated boolean variable is set to True. If the currentMallocVar is was NULL, it means that its the end of the linked list. The nextAvailableAddress is then calculated as the currentMallocVar plus its size member and checked in the nested if condition if the required size argument is smaller than heap high address minus the nextAvailableAddress variable. If yes the new malloc variable is allocated by calling supportStdlib_mallocVar helper function and the result is then used to linked it to the currentMallocVar. Then to the returnAddress is stored the newly allocated address with the respect to the aligned malloc variable offset and allocated boolean variable is set to True. In the end the mutex for the specific program is released and the address returned.
- Parameters
size – [in] number of bytes that should be allocated
- Returns
void *
-
void supportStdlib_free(void *ptr)¶
Stdlib free function implementation redesigned for CosmOS DEMO. Thread safe.
The implementation contains obtaining of the mallocVarToFree by subtracting the aligned size of the malloc variable type from the ptr argument. Then the core configuration is obtained by calling function core_getCoreCfg. Schedulable in execution type is then checked in the implemented if condition if it is equal to the SCHEDULABLE_INSTANCE_ENUM__THREAD, if yes the program variable in execution is obtained by calling function core_getCoreProgramInExecution. Because the heap allocation can be requested from multiple threads within one program the mutual exclusion is needed and mutex_getMutex function is called with the program specific mutex variable. Then the malloc variable to free is unlinked from the list and the mutex for the specific program is released.
- Parameters
ptr – [in] pointer to free
- Returns
none
-
void *supportStdlib_malloc(size_t size)¶