m2mb API docs  25.30.003
m2mb API sets documentation
m2mb_os_debug.h File Reference

Basic functionality of Operating systems debug to build an AppZone app containing these debug traces: More...

#include "m2mb_types.h"
#include "m2mb_os_types.h"
#include "m2mb_os.h"

Go to the source code of this file.

Functions

void * m2mb_os_malloc_debug (UINT32 size, const CHAR *place, INT32 line)
 Allocates bytes of memory (to be used for debug purposes) More...
 
void * m2mb_os_calloc_debug (UINT32 size, const CHAR *place, INT32 line)
 Allocates bytes of memory and init space with 0 (to be used for debug purposes) More...
 
M2MB_OS_RESULT_E m2mb_os_free_debug (void *pMem, const CHAR *place, INT32 line)
 Free allocated memory (to be used for debug purposes) More...
 
void * m2mb_os_realloc_debug (void *ptr, UINT32 size, const CHAR *place, INT32 line)
 Dynamic memory reallocation (to be used for debug purposes) More...
 

Detailed Description

Basic functionality of Operating systems debug to build an AppZone app containing these debug traces:

m2m/m2m_generic/common/m2mb_inc/m2mb_os_debug.h

  1. add the header file m2mb_os_debug.h in every file that includes m2mb_os.h (if using m2mb_os_api.h, note that it already includes both)
  2. add the M2MB_MEM_DBG define to the AppZone project defines (in makefile.in)
  3. enable the M2MB_TC_GENERIC by calling the m2mb_trace_enable( M2MB_TC_GENERIC ); (please refer to m2mb_trace.h for further info)

OS debug functions

@notes Dependencies: m2mb_types.h m2mb_os_types.h m2mb_platform_conf.h m2mb_os.h

Author
Pierluigi Collu
Date
30/01/2020

Function Documentation

◆ m2mb_os_calloc_debug()

void* m2mb_os_calloc_debug ( UINT32  size,
const CHAR *  place,
INT32  line 
)

Allocates bytes of memory and init space with 0 (to be used for debug purposes)

This function provides service to reserve memory space to the caller and initialize it to 0

Parameters
[in]sizesize in byte of memory to be allocated and initialize
[in]placethe code it is called from (e.g. FUNCTION or MODULE)
[in]linethe line it is called from (e.g. LINE)
Returns
valid pointer in case of success
NULL in case of error
Note
The performance of this service is a function of the requested block size and the amount of fragmentation in the heap. Hence, this service should not be used during time-critical task of execution. Allowed From Initialization and tasks Preemption Possible Yes

Example

//pointer to 10 UINT32
typedf struct
{
INT32 a;
INT8 b;
void *ptr;
}GEN_T;
GEN_T *pStruct;
pStruct = ( GEN_T * )m2mb_os_calloc( sizeof(GEN_T), __FUNCTION__, __LINE__ );
if ( pStruct == NULL )
exit(...)
//all pStruct initialized to 0: pStruct->a = 0; pStruct->b = 0; pStruct->ptr = 0;

◆ m2mb_os_free_debug()

M2MB_OS_RESULT_E m2mb_os_free_debug ( void *  pMem,
const CHAR *  place,
INT32  line 
)

Free allocated memory (to be used for debug purposes)

This function provides service to free already allocated memory space

Parameters
[in]pMempointer to memory where to release previous allocation
[in]placethe code it is called from (e.g. FUNCTION or MODULE)
[in]linethe line it is called from (e.g. LINE)
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_PTR_ERROR Invalid memory area pointer M2MB_OS_CALLER_ERROR Invalid caller of this service
Note
The application must prevent using the memory area after it is released. Allowed From Initialization and tasks Preemption Possible Yes

Example

M2MB_OS_RESULT_E osRes;
osRes = m2mb_os_free( pStruct, __FUNCTION__, __LINE__ );
if ( osRes != M2MB_OS_SUCCESS )
//...

◆ m2mb_os_malloc_debug()

void* m2mb_os_malloc_debug ( UINT32  size,
const CHAR *  place,
INT32  line 
)

Allocates bytes of memory (to be used for debug purposes)

This function provides service to reserve memory space to the caller

Parameters
[in]sizesize in byte of memory to be allocated
[in]placethe code it is called from (e.g. FUNCTION or MODULE)
[in]linethe line it is called from (e.g. LINE)
Returns
valid pointer in case of success
NULL in case of error
Note
The performance of this service is a function of the requested block size and the amount of fragmentation in the heap. Hence, this service should not be used during time-critical task of execution. Allowed From Initialization and tasks Preemption Possible Yes

pointer to 10 UINT32 UINT32 *pUint; pUint = ( UINT32 * )m2mb_os_malloc( 10 * sizeof(UINT32), FUNCTION, LINE ); if ( pUint == NULL ) exit(...)

◆ m2mb_os_realloc_debug()

void* m2mb_os_realloc_debug ( void *  ptr,
UINT32  size,
const CHAR *  place,
INT32  line 
)

Dynamic memory reallocation (to be used for debug purposes)

Changes the size of the memory block pointed to by ptr.

The function may move the memory block to a new location (whose address is returned by the function).

The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. If the new size is larger, the value of the newly allocated portion is indeterminate.

In case that ptr is a null pointer, the function behaves like malloc, assigning a new block of size bytes and returning a pointer to its beginning.

Parameters
[in]
m2mb_os_free
M2MB_OS_RESULT_E m2mb_os_free(void *pMem)
Free allocated memory.
m2mb_os_calloc
void * m2mb_os_calloc(UINT32 size)
Allocates bytes of memory and init space with 0.