picotm  0.10.0
Macros | Functions
picotm-lib-ptr.h File Reference
#include "compiler.h"
#include <stddef.h>
#include <stdint.h>

Macros

#define picotm_containerof(ptr, type, member)
 
#define picotm_sizeof_align(__type)
 Returns the number of size and alignment bytes of a given type. More...
 

Functions

static uintptr_t picotm_address_ceil (uintptr_t addr, size_t algn)
 Rounds an address upwards to the nearest address with the given alignment. More...
 
static PICOTM_BEGIN_DECLS uintptr_t picotm_address_floor (uintptr_t addr, size_t algn)
 Rounds an address downwards to the nearest address with the given alignment. More...
 
static void * picotm_ptr_ceil (const void *ptr, size_t algn)
 Rounds a memory location upwards to the nearest address with the given alignment. More...
 
static ptrdiff_t picotm_ptr_diff (const void *hi, const void *lo)
 Subtracts two memory locations and returns the number of raw bytes between them. More...
 
static void * picotm_ptr_floor (const void *ptr, size_t algn)
 Rounds a memory location downwards to the nearest address with the given alignment. More...
 

Macro Definition Documentation

◆ picotm_containerof

#define picotm_containerof (   ptr,
  type,
  member 
)

Returns the container of a data structure.

Parameters
ptrA pointer to a data structure.
typeThe type of the container.
memberThe name of the container's member field.
Returns
A pointer to the container data structure.

◆ picotm_sizeof_align

#define picotm_sizeof_align (   __type)
Parameters
__typeThe type.
Returns
The number of bytes to hold a value of the given type and its aligment bytes.

Function Documentation

◆ picotm_address_ceil()

static uintptr_t picotm_address_ceil ( uintptr_t  addr,
size_t  algn 
)
inlinestatic
Parameters
addrA memory address.
algnThe alignment of the result address.
Returns
The next higher address with the given alignment.

◆ picotm_address_floor()

static PICOTM_BEGIN_DECLS uintptr_t picotm_address_floor ( uintptr_t  addr,
size_t  algn 
)
inlinestatic
Parameters
addrA memory address.
algnThe alignment of the result address.
Returns
The next lower address with the given alignment.

◆ picotm_ptr_ceil()

static void* picotm_ptr_ceil ( const void *  ptr,
size_t  algn 
)
inlinestatic
Parameters
ptrA pointer to a memory location.
algnThe alignment of the result memory location.
Returns
The next higher memory location with the given alignment.

◆ picotm_ptr_diff()

static ptrdiff_t picotm_ptr_diff ( const void *  hi,
const void *  lo 
)
inlinestatic
Parameters
hiThe higher memory location.
loThe lower memory location.
Returns
The number of bytes between lo an hi.

◆ picotm_ptr_floor()

static void* picotm_ptr_floor ( const void *  ptr,
size_t  algn 
)
inlinestatic
Parameters
ptrA pointer to a memory location.
algnThe alignment of the result memory location.
Returns
The next lower memory location with the given alignment.