Index: include/asterisk/stringfields.h =================================================================== --- include/asterisk/stringfields.h (revision 280983) +++ include/asterisk/stringfields.h (working copy) @@ -102,6 +102,9 @@ #include "asterisk/inline_api.h" +/* the type of storage used to track how many bytes were allocated for a field */ +typedef uint16_t ast_string_field_allocation; + /*! \internal \brief An opaque type for managed string fields in structures @@ -112,7 +115,7 @@ In addition to the string itself, the amount of space allocated for the field is stored in the two bytes immediately preceding it. */ -typedef const char * ast_string_field; +typedef const char * __attribute__((aligned(sizeof(ast_string_field_allocation)))) ast_string_field; /*! \internal @@ -293,10 +296,6 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head, const ast_string_field ptr); -/* the type of storage used to track how many bytes were allocated for a field */ - -typedef uint16_t ast_string_field_allocation; - /*! \brief Macro to provide access to the allocation field that lives immediately in front of a string field \param x Pointer to the string field Index: main/utils.c =================================================================== --- main/utils.c (revision 280983) +++ main/utils.c (working copy) @@ -1615,7 +1615,8 @@ size_t space = (*pool_head)->size - (*pool_head)->used; size_t to_alloc = needed + sizeof(ast_string_field_allocation); - if (__builtin_expect(to_alloc > space, 0)) { + /* This +1 accounts for alignment on SPARC */ + if (__builtin_expect(to_alloc + 1 > space, 0)) { size_t new_size = (*pool_head)->size; while (new_size < to_alloc) { @@ -1632,6 +1633,13 @@ } result = (*pool_head)->base + (*pool_head)->used; +#ifdef __sparc__ + /* SPARC requires that the allocation field be aligned. */ + if ((long) result % sizeof(ast_string_field_allocation)) { + result++; + (*pool_head)->used++; + } +#endif (*pool_head)->used += to_alloc; (*pool_head)->active += needed; result += sizeof(ast_string_field_allocation); @@ -1706,6 +1714,12 @@ } } else { target = (*pool_head)->base + (*pool_head)->used + sizeof(ast_string_field_allocation); +#ifdef __sparc__ + if ((long) target % sizeof(ast_string_field_allocation)) { + target++; + space--; + } +#endif available = space - sizeof(ast_string_field_allocation); }