Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 93339 invoked by uid 500); 1 Mar 2002 16:49:04 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 93318 invoked from network); 1 Mar 2002 16:49:03 -0000 Date: Fri, 1 Mar 2002 08:49:05 -0800 From: Aaron Bannert To: dev@httpd.apache.org, dev@apr.apache.org Subject: Re: [PATCH] fix alignment on shared memory Message-ID: <20020301084905.Y15055@clove.org> Mail-Followup-To: Aaron Bannert , dev@httpd.apache.org, dev@apr.apache.org References: <20020222180446.P23835@clove.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.23i X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N I've still got sleep in my eyes, so I might not be seeing this correctly yet, but isn't the problem not that the segment itself is misaligned, but that the structure that is being placed over that segment not properly padded to account for alignment? This looks like the problem to me: AP_DECLARE(int) ap_calc_scoreboard_size(void) { ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit); ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit); scoreboard_size = sizeof(global_score); scoreboard_size += sizeof(process_score) * server_limit; scoreboard_size += sizeof(worker_score) * server_limit * thread_limit; return scoreboard_size; } -aaron On Fri, Mar 01, 2002 at 11:14:05AM -0500, Jeff Trawick wrote: > Jeff Trawick writes: > > > Aaron Bannert writes: > > > > > Could this be what's causing the SIGBUS? My current theory is that > > > there's a size mismatch betwen ws->conn_bytes (an apr_off_t) and > > > the (unsigned long) that only shows up on word-alignment-picky > > > chips like sparcs. > > > > I'm bombing today on Solaris/sparc trying to do > > > > ap_scoreboard_image->global->restart_time = apr_time_now() > > > > That field lives at 0x14 from the start of the page. I would suppose > > that there are alignment requirements that we aren't maintaining. > > ap_scoreboard_image->global is at 0x4 from the start of the page. > > Does anybody know about any documentation on alignment requirements? > > Should the shared memory code return storage on 8-byte alignment? > > 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)); > > apr_pool_cleanup_register(new_m->pool, new_m, shm_cleanup_owner, > apr_pool_cleanup_null); > @@ -206,7 +212,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)); > > apr_pool_cleanup_register(new_m->pool, new_m, shm_cleanup_owner, > apr_pool_cleanup_null); > @@ -345,7 +351,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)); > > apr_pool_cleanup_register(new_m->pool, new_m, shm_cleanup_owner, > apr_pool_cleanup_null); > @@ -508,7 +514,7 @@ > } > > /* metadata isn't part of the usable segment */ > - 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)); > > apr_pool_cleanup_register(new_m->pool, new_m, shm_cleanup_attach, > apr_pool_cleanup_null); > > > -- > Jeff Trawick | trawick@attglobal.net | PGP public key at web site: > http://www.geocities.com/SiliconValley/Park/9289/ > Born in Roswell... married an alien...