Return-Path: Delivered-To: apmail-httpd-dev-archive@httpd.apache.org Received: (qmail 59233 invoked by uid 500); 1 Mar 2002 16:16:55 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 59152 invoked from network); 1 Mar 2002 16:16:55 -0000 X-Authentication-Warning: rdu163-40-092.nc.rr.com: trawick set sender to trawick@attglobal.net using -f Sender: trawick@rdu163-40-092.nc.rr.com To: dev@httpd.apache.org, dev@apr.apache.org Subject: [PATCH] fix alignment on shared memory References: <20020222180446.P23835@clove.org> From: Jeff Trawick Date: 01 Mar 2002 11:14:05 -0500 In-Reply-To: Message-ID: Lines: 83 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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...