Hi,

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

http://people.apache.org/~rjung/patches/mod_socache_shmcb-padding.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 wrong.

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?

Regards,

Rainer

Reply via email to