httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Jung <>
Subject How to align shm in an neat way?
Date Mon, 13 Aug 2012 16:30:43 GMT

PR 53040 reveals, that mod_socache_shmcb has an alignment problem. One 
of the three structs mapped into shm contains an apr_time_t member, 
which at least on Sparc is 8 Bytes, whereas for 32 bit builds long is 
only 4 Bytes.

Currently everything is aligned for 4 Bytes, so we get bus 
errors/crashes when trying to assign the apr_time_t to an address that 
is only divisible by 4 instead of 8.

I can easily reproduce the problem.

A possible solution is to pad the three structures SHMCBHeader, 
SHMCBSubcache and SHMCBIndex to a multiple of 8 Bytes length. For 
Subcache and Index this is already true by coincidence, SHMCBHeader 
needs another 4 Bytes.

I wonder what the right solution is. In the patch

I hard coded the padding, but I don't really like it, because it breaks 
if members are added to the struct. I could add a sizeof() test during 
startup or probably even compilation to warn or err, if the padding is 

I see several recipes for alignment using pragmas and attribute, but all 
of them are compiler specific.

One could also wrap the struct in a wrapped struct, so that one could 
use the sizeof() of the inner struct to determine the padding of the 
outer struct. That would make the code convoluted.

I checked other parts of the code, but couldn't find a simple solution. 
Any hints how to do this nicely?



View raw message