Hi Daniel and kamailio users,
In my integration adventure of wolfSSL and kamailio I have encountered an alignment issue sometime causing segfaults.
May I enquire what is the alignment of shm_malloc and friends?
The wolfSSL library integration requires that ser_malloc and ser_realloc return values aligned on alignof(_max_align_t) which in the case of x86_64 is 16.
Thank you Shih-Ping
Hello,
iirc, the alignment is to sizeof(void*), which is 8.
I haven't met cases when the alignment is required to be different that the size of the pointer/memory address. Any particular reason for wolfssl to require that?
On 20.06.22 12:52, Richard Chan wrote:
Hi Daniel and kamailio users,
In my integration adventure of wolfSSL and kamailio I have encountered an alignment issue sometime causing segfaults.
May I enquire what is the alignment of shm_malloc and friends?
The wolfSSL library integration requires that ser_malloc and ser_realloc return values aligned on alignof(_max_align_t) which in the case of x86_64 is 16.
Thank you Shih-Ping
Kamailio - Users Mailing List - Non Commercial Discussions
- sr-users@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe:
On Mon, 20 Jun 2022 at 7:09 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
iirc, the alignment is to sizeof(void*), which is 8.
I haven't met cases when the alignment is required to be different that the size of the pointer/memory address. Any particular reason for wolfssl to require that?
https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.htm... Modern malloc/realloc return 16 byte aligned memory on 64bit systems so 3rd party libraries now assume this behaviour.
wolfSSL has some optimisations with aligned data and Debian has this flag on by default in 5.2.0. I did verify that without this flag existing shm functions work. With this flag turned on Kamailio will segfault unless I add wrappers to align up to 16 bytes.
Hello Daniel,
On Mon, 20 Jun 2022 at 19:09, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
iirc, the alignment is to sizeof(void*), which is 8.
The qm allocator naturally returns 16-byte aligned memory. However the definition of DBG_SR_MEMORY(from 'make cfg' with all the defaults.) causes 16 to drop to 8.
Is this intentional?
Regards S-P //qm naturally aligns on 16 bytes without DBG_QM_MALLOC!
#ifdef DBG_QM_MALLOC #if defined(__CPU_sparc64) || defined(__CPU_sparc) /* tricky, on sun in 32 bits mode long long must be 64 bits aligned * but long can be 32 bits aligned => malloc should return long long * aligned memory */ #define ROUNDTO sizeof(long long) #else #define ROUNDTO sizeof(void*) /* minimum possible ROUNDTO
* ->heavy debugging*/ #endif #else /* DBG_QM_MALLOC */ #define ROUNDTO 16UL /* size we round to, must be = 2^n and also * sizeof(qm_frag)+sizeof(qm_frag_end) * must be multiple of ROUNDTO! */ #endif