libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 747adebc630dae6e9d18431c2849ec5189f726af
parent b88b6d2bbc2c53f76574dfff332f8f39917e3146
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu, 28 Jan 2010 20:14:18 +0000

fixing alignment issue

Diffstat:
MChangeLog | 4++++
Msrc/daemon/daemon.c | 2+-
Msrc/daemon/memorypool.c | 14+++++++++++++-
3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Thu Jan 28 20:35:48 CET 2010 + Make sure addresses returned by memory pool are + aligned (fixes bus errors on Sparc). -CG + Thu Dec 17 20:26:52 CET 2009 poll.h is not stricly required anymore. -ND diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -495,8 +495,8 @@ MHD_handle_connection (void *data) struct timeval tv; unsigned int timeout; time_t now; - struct MHD_Pollfd mp; #ifdef HAVE_POLL_H + struct MHD_Pollfd mp; struct pollfd p; #endif diff --git a/src/daemon/memorypool.c b/src/daemon/memorypool.c @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007, 2009 Daniel Pittman and Christian Grothoff + (C) 2007, 2009, 2010 Daniel Pittman and Christian Grothoff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -32,6 +32,15 @@ #define MAP_FAILED ((void*)-1) #endif +/** + * Align to 2x word size (as GNU libc does). + */ +#define ALIGN_SIZE (2 * sizeof(void*)) + +/** + * Round up 'n' to a multiple of ALIGN_SIZE. + */ +#define ROUND_TO_ALIGN(n) ((n+(ALIGN_SIZE-1)) & (~(ALIGN_SIZE-1))) struct MemoryPool { @@ -127,6 +136,7 @@ MHD_pool_allocate (struct MemoryPool *pool, { void *ret; + size = ROUND_TO_ALIGN (size); if ((pool->pos + size > pool->end) || (pool->pos + size < pool->pos)) return NULL; if (from_end == MHD_YES) @@ -166,6 +176,7 @@ MHD_pool_reallocate (struct MemoryPool *pool, { void *ret; + new_size = ROUND_TO_ALIGN (new_size); if ((pool->end < old_size) || (pool->end < new_size)) return NULL; /* unsatisfiable or bogus request */ @@ -211,6 +222,7 @@ MHD_pool_reset (struct MemoryPool *pool, void *keep, size_t size) { + size = ROUND_TO_ALIGN (size); if (keep != NULL) { if (keep != pool->memory)