libmicrohttpd

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

commit cc5f66001e7227b7cba4046807c3b08e246bdfc7
parent e657e19644a7b76412b4e22975e49c91dc0a0365
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Tue, 18 Feb 2014 18:37:13 +0000

memorypool.c: use native memory function for W32

Diffstat:
Msrc/microhttpd/memorypool.c | 19+++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c @@ -71,7 +71,7 @@ struct MemoryPool size_t end; /** - * #MHD_NO if pool was malloc'ed, #MHD_YES if mmapped. + * #MHD_NO if pool was malloc'ed, #MHD_YES if mmapped (VirtualAlloc'ed for W32). */ int is_mmap; }; @@ -91,12 +91,17 @@ MHD_pool_create (size_t max) pool = malloc (sizeof (struct MemoryPool)); if (NULL == pool) return NULL; -#ifdef MAP_ANONYMOUS +#if defined(MAP_ANONYMOUS) || defined(_WIN32) if (max <= 32 * 1024) pool->memory = MAP_FAILED; else - pool->memory = MMAP (NULL, max, PROT_READ | PROT_WRITE, +#if defined(MAP_ANONYMOUS) && !defined(_WIN32) + pool->memory = mmap (NULL, max, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +#elif defined(_WIN32) + pool->memory = VirtualAlloc(NULL, max, MEM_COMMIT | MEM_RESERVE, + PAGE_READWRITE); +#endif #else pool->memory = MAP_FAILED; #endif @@ -134,7 +139,13 @@ MHD_pool_destroy (struct MemoryPool *pool) if (pool->is_mmap == MHD_NO) free (pool->memory); else - MUNMAP (pool->memory, pool->size); +#if defined(MAP_ANONYMOUS) && !defined(_WIN32) + munmap (pool->memory, pool->size); +#elif defined(_WIN32) + VirtualFree(pool->memory, 0, MEM_RELEASE); +#else + abort(); +#endif free (pool); }