summaryrefslogtreecommitdiff
path: root/include/asterisk/stringfields.h
diff options
context:
space:
mode:
authorWalter Doekes <walter+asterisk@wjd.nu>2011-11-02 22:02:07 +0000
committerWalter Doekes <walter+asterisk@wjd.nu>2011-11-02 22:02:07 +0000
commit7fd2a68b0ecc0261e9090915dafcd65fee9cc6b8 (patch)
treec30bd204b03e58ed781b196f344020fa6a7e8b14 /include/asterisk/stringfields.h
parent55ffab4cd934e923cfe5c4fb1030325591b942fa (diff)
Ensure that string field lengths are properly aligned
Integers should always be aligned. For some platforms (ARM, SPARC) this is more important than for others. This changeset ensures that the string field string lengths are aligned on *all* platforms, not just on the SPARC for which there was a workaround. It also fixes that the length integer can be resized to 32 bits without problems if needed. (closes issue ASTERISK-17310) Reported by: radael, S Adrian Reviewed by: Tzafrir Cohen, Terry Wilson Tested by: S Adrian Review: https://reviewboard.asterisk.org/r/1549 ........ Merged revisions 343157 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 343158 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@343163 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/stringfields.h')
-rw-r--r--include/asterisk/stringfields.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h
index 51a169604..4039bf482 100644
--- a/include/asterisk/stringfields.h
+++ b/include/asterisk/stringfields.h
@@ -114,6 +114,10 @@
*/
typedef const char * ast_string_field;
+/* the type of storage used to track how many bytes were allocated for a field */
+
+typedef uint16_t ast_string_field_allocation;
+
/*!
\internal
\brief A constant empty string used for fields that have no other value
@@ -123,13 +127,15 @@ extern const char *__ast_string_field_empty;
/*!
\internal
\brief Structure used to hold a pool of space for string fields
+ \note base is aligned so base+used can stay aligned by incrementing used with
+ aligned numbers only
*/
struct ast_string_field_pool {
struct ast_string_field_pool *prev; /*!< pointer to the previous pool, if any */
size_t size; /*!< the total size of the pool */
size_t used; /*!< the space used in the pool */
size_t active; /*!< the amount of space actively in use by fields */
- char base[0]; /*!< storage space for the fields */
+ char base[0] __attribute__((aligned(sizeof(ast_string_field_allocation)))); /*!< storage space for the fields */
};
/*!
@@ -293,10 +299,6 @@ void * attribute_malloc __ast_calloc_with_stringfields(unsigned int num_structs,
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