apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@attglobal.net>
Subject Re: [PATCH] fix alignment on shared memory
Date Fri, 01 Mar 2002 16:35:32 GMT
Jeff Trawick <trawick@attglobal.net> writes:

> This patch gets me running again:
> 
> Index: srclib/apr/shmem/unix/shm.c
> ===================================================================
> RCS file: /home/cvs/apr/shmem/unix/shm.c,v
> retrieving revision 1.14
> diff -u -r1.14 shm.c
> --- srclib/apr/shmem/unix/shm.c	5 Feb 2002 04:32:52 -0000	1.14
> +++ srclib/apr/shmem/unix/shm.c	1 Mar 2002 16:03:33 -0000
> @@ -59,6 +59,12 @@
>  #include "apr_user.h"
>  #include "apr_strings.h"
>  
> +/* APR_ALIGN() is only to be used to align on a power of 2 boundary */
> +#define APR_ALIGN(size, boundary) \
> +    (((size) + ((boundary) - 1)) & ~((boundary) - 1))
> +
> +#define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
> +
>  static apr_status_t shm_cleanup_owner(void *m_)
>  {
>      apr_shm_t *m = (apr_shm_t *)m_;
> @@ -189,7 +195,7 @@
>          /* store the real size in the metadata */
>          *(apr_size_t*)(new_m->base) = new_m->realsize;
>          /* metadata isn't usable */
> -        new_m->usable = (char *)new_m->base + sizeof(apr_size_t);
> +        new_m->usable = (char *)new_m->base + APR_ALIGN_DEFAULT(sizeof(apr_size_t));

but something missing from the patch is taking into account the
alignment when calculating new_m->realsize (minor detail :) )

that alignment has to be reflected in other places as well
(apr_shm_attach() when we mmap the file)

-- 
Jeff Trawick | trawick@attglobal.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Mime
View raw message