|
|
|
@ -741,36 +741,57 @@ static void force_inline _ast_assert(int condition, const char *condition_str,
|
|
|
|
|
#include "asterisk/strings.h"
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Add space and let result be a multiple of space.
|
|
|
|
|
* \param initial A number to add space to.
|
|
|
|
|
* \param space The space to add, this would typically be sizeof(sometype).
|
|
|
|
|
* \return The sum of initial plus space plus at most space-1.
|
|
|
|
|
* \brief Return the number of bytes used in the alignment of type.
|
|
|
|
|
* \param type
|
|
|
|
|
* \return The number of bytes required for alignment.
|
|
|
|
|
*
|
|
|
|
|
* Many systems prefer integers to be stored on aligned on memory locations.
|
|
|
|
|
* A use case for this is when prepending length fields of type int to a buffer.
|
|
|
|
|
* If you keep the total used bytes a multiple of the size of the integer type,
|
|
|
|
|
* a next block of length+buffer will have the length field automatically
|
|
|
|
|
* aligned.
|
|
|
|
|
* This is really just __alignof__(), but tucked away in this header so we
|
|
|
|
|
* don't have to look at the nasty underscores in the source.
|
|
|
|
|
*/
|
|
|
|
|
#define ast_alignof(type) __alignof__(type)
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Increase offset so it is a multiple of the required alignment of type.
|
|
|
|
|
* \param offset The value that should be increased.
|
|
|
|
|
* \param type The data type that offset should be aligned to.
|
|
|
|
|
* \return The smallest multiple of alignof(type) larger than or equal to offset.
|
|
|
|
|
* \see ast_make_room_for()
|
|
|
|
|
*
|
|
|
|
|
* It looks kind of ugly, but the compiler will optimize this down to 4 or 5
|
|
|
|
|
* inexpensive instructions (on x86_64).
|
|
|
|
|
* Many systems prefer integers to be stored on aligned on memory locations.
|
|
|
|
|
* This macro will increase an offset so a value of the supplied type can be
|
|
|
|
|
* safely be stored on such a memory location.
|
|
|
|
|
*
|
|
|
|
|
* Examples:
|
|
|
|
|
* ast_add_and_make_multiple_of(0x18, sizeof(int64_t)) ==> 0x20
|
|
|
|
|
* ast_add_and_make_multiple_of(0x19, sizeof(int64_t)) ==> 0x28
|
|
|
|
|
* ast_align_for(0x17, int64_t) ==> 0x18
|
|
|
|
|
* ast_align_for(0x18, int64_t) ==> 0x18
|
|
|
|
|
* ast_align_for(0x19, int64_t) ==> 0x20
|
|
|
|
|
*
|
|
|
|
|
* Don't mind the ugliness, the compiler will optimize it.
|
|
|
|
|
*/
|
|
|
|
|
#define ast_add_and_make_multiple_of(initial, space) (((initial + (2 * space - 1)) / space) * space)
|
|
|
|
|
#define ast_align_for(offset, type) (((offset + __alignof__(type) - 1) / __alignof__(type)) * __alignof__(type))
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Add bytes so that result is a multiple of size.
|
|
|
|
|
* \param initial A number to enlarge.
|
|
|
|
|
* \param size The block size the number should be a multiple of.
|
|
|
|
|
* \return The sum of initial plus at most size-1.
|
|
|
|
|
* \brief Increase offset by the required alignment of type and make sure it is
|
|
|
|
|
* a multiple of said alignment.
|
|
|
|
|
* \param offset The value that should be increased.
|
|
|
|
|
* \param type The data type that room should be reserved for.
|
|
|
|
|
* \return The smallest multiple of alignof(type) larger than or equal to offset
|
|
|
|
|
* plus alignof(type).
|
|
|
|
|
* \see ast_align_for()
|
|
|
|
|
*
|
|
|
|
|
* A use case for this is when prepending length fields of type int to a buffer.
|
|
|
|
|
* If you keep the offset a multiple of the alignment of the integer type,
|
|
|
|
|
* a next block of length+buffer will have the length field automatically
|
|
|
|
|
* aligned.
|
|
|
|
|
*
|
|
|
|
|
* Examples:
|
|
|
|
|
* ast_make_room_for(0x17, int64_t) ==> 0x20
|
|
|
|
|
* ast_make_room_for(0x18, int64_t) ==> 0x20
|
|
|
|
|
* ast_make_room_for(0x19, int64_t) ==> 0x28
|
|
|
|
|
*
|
|
|
|
|
* Similar ast_add_and_make_multiple_of, except that this doesn't add the room
|
|
|
|
|
* for the length object, it only ensures that the total is aligned.
|
|
|
|
|
* Don't mind the ugliness, the compiler will optimize it.
|
|
|
|
|
*/
|
|
|
|
|
#define ast_make_multiple_of(initial, size) (((initial + size - 1) / size) * size)
|
|
|
|
|
#define ast_make_room_for(offset, type) (((offset + (2 * __alignof__(type) - 1)) / __alignof__(type)) * __alignof__(type))
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief An Entity ID is essentially a MAC address, brief and unique
|
|
|
|
|