Got it to compile under VC

This commit is contained in:
Josh Yelon 2005-10-02 02:50:52 +00:00
parent 818cf9d7a5
commit fb46c04ad6

View File

@ -2,10 +2,10 @@
license as well as the LGPL, in spite of the comments below. See license as well as the LGPL, in spite of the comments below. See
http://www.malloc.de . */ http://www.malloc.de . */
#include "dtoolbase.h"
#if defined(USE_MEMORY_PTMALLOC2) && !defined(linux) #if defined(USE_MEMORY_PTMALLOC2) && !defined(linux)
#define USE_DL_PREFIX 1 #define USE_DL_PREFIX 1
#define __STDC__ 1
#define MREMAP_MAYMOVE 1 /* terrible hack--drose */
/* Malloc implementation for multiple threads without lock contention. /* Malloc implementation for multiple threads without lock contention.
Copyright (C) 1996,1997,1998,1999,2000,01,02 Free Software Foundation, Inc. Copyright (C) 1996,1997,1998,1999,2000,01,02 Free Software Foundation, Inc.
@ -238,14 +238,6 @@
probably don't want to touch unless you are extending or adapting malloc. probably don't want to touch unless you are extending or adapting malloc.
*/ */
/*
WIN32 sets up defaults for MS environment and compilers.
Otherwise defaults are for unix.
*/
/* #define WIN32 */
/*************************** thread-m.h ******************************/ /*************************** thread-m.h ******************************/
@ -2248,7 +2240,7 @@ struct malloc_chunk {
}; };
/*typedef struct malloc_chunk* mchunkptr;*/ typedef struct malloc_chunk* mchunkptr;
/* /*
malloc_chunk details: malloc_chunk details:
@ -2868,7 +2860,7 @@ struct malloc_par {
char* sbrk_base; char* sbrk_base;
}; };
/*typedef struct malloc_state *mstate;*/ typedef struct malloc_state *mstate;
/* There are several instances of this struct ("arenas") in this /* There are several instances of this struct ("arenas") in this
malloc. If you are adapting this malloc in a way that does NOT use malloc. If you are adapting this malloc in a way that does NOT use
@ -5320,9 +5312,6 @@ mremap_chunk(p, new_size) mchunkptr p; size_t new_size;
/* Note the extra SIZE_SZ overhead as in mmap_chunk(). */ /* Note the extra SIZE_SZ overhead as in mmap_chunk(). */
new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask; new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask;
#ifndef MREMAP_MAYMOVE
#define MREMAP_MAYMOVE 1 /* terrible hack--drose */
#endif
cp = (char *)mremap((char *)p - offset, size + offset, new_size, cp = (char *)mremap((char *)p - offset, size + offset, new_size,
MREMAP_MAYMOVE); MREMAP_MAYMOVE);
@ -7830,6 +7819,9 @@ sbrk_exit:
static void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) { static void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) {
static long g_pagesize; static long g_pagesize;
static long g_regionsize; static long g_regionsize;
DWORD alloc=MEM_RESERVE|MEM_TOP_DOWN;
DWORD ntprot=0;
long rounding=0;
#ifdef TRACE #ifdef TRACE
printf ("mmap %p %d %d %d\n", ptr, size, prot, type); printf ("mmap %p %d %d %d\n", ptr, size, prot, type);
#endif #endif
@ -7844,8 +7836,6 @@ static void *mmap (void *ptr, long size, long prot, long type, long handle, long
assert ((unsigned) ptr % g_pagesize == 0); assert ((unsigned) ptr % g_pagesize == 0);
assert (size % g_pagesize == 0); assert (size % g_pagesize == 0);
/* Allocate this */ /* Allocate this */
DWORD alloc=MEM_RESERVE|MEM_TOP_DOWN, ntprot=0;
long rounding=0;
if(!(type & MAP_NORESERVE)) alloc|=MEM_COMMIT; if(!(type & MAP_NORESERVE)) alloc|=MEM_COMMIT;
if((prot & (PROT_READ|PROT_WRITE))==(PROT_READ|PROT_WRITE)) ntprot|=PAGE_READWRITE; if((prot & (PROT_READ|PROT_WRITE))==(PROT_READ|PROT_WRITE)) ntprot|=PAGE_READWRITE;
else if(prot & PROT_READ) ntprot|=PAGE_READONLY; else if(prot & PROT_READ) ntprot|=PAGE_READONLY;
@ -7865,7 +7855,8 @@ static void *mmap (void *ptr, long size, long prot, long type, long handle, long
{ /* prot==PROT_NONE also appears to be a euphemism for free */ { /* prot==PROT_NONE also appears to be a euphemism for free */
MEMORY_BASIC_INFORMATION mbi; MEMORY_BASIC_INFORMATION mbi;
DWORD read=0; DWORD read=0;
for(char *p=((char *)ptr)+read; read<size && VirtualQuery(p, &mbi, sizeof(mbi)); read+=mbi.RegionSize) char *p;
for(p=((char *)ptr)+read; read<size && VirtualQuery(p, &mbi, sizeof(mbi)); read+=mbi.RegionSize)
{ {
if(mbi.State & MEM_COMMIT) if(mbi.State & MEM_COMMIT)
{ {
@ -7905,7 +7896,7 @@ static void *mmap (void *ptr, long size, long prot, long type, long handle, long
#ifdef TRACE #ifdef TRACE
printf ("%s %p %d %d %d\n", (type & MAP_NORESERVE) ? "Reserve" : "Commit", ptr, size, prot, type); printf ("%s %p %d %d %d\n", (type & MAP_NORESERVE) ? "Reserve" : "Commit", ptr, size, prot, type);
#endif #endif
mmap_exit: mmap_exit:
/* Release spin lock */ /* Release spin lock */
slrelease (&g_sl); slrelease (&g_sl);
return ptr; return ptr;
@ -7933,7 +7924,7 @@ static long munmap (void *ptr, long size) {
#ifdef TRACE #ifdef TRACE
printf ("Release %p %d\n", ptr, size); printf ("Release %p %d\n", ptr, size);
#endif #endif
munmap_exit: munmap_exit:
/* Release spin lock */ /* Release spin lock */
/* slrelease (&g_sl); */ /* slrelease (&g_sl); */
return rc; return rc;
@ -7943,6 +7934,7 @@ static int mprotect(const void *addr, long len, int prot)
{ {
static long g_pagesize; static long g_pagesize;
static long g_regionsize; static long g_regionsize;
DWORD ntprot=0, oldntprot=0;
int rc = -1; int rc = -1;
#ifdef TRACE #ifdef TRACE
printf ("mprotect %p %d %d\n", addr, len, prot); printf ("mprotect %p %d %d\n", addr, len, prot);
@ -7958,7 +7950,6 @@ static int mprotect(const void *addr, long len, int prot)
assert ((unsigned) addr % g_pagesize == 0); assert ((unsigned) addr % g_pagesize == 0);
assert (len% g_pagesize == 0); assert (len% g_pagesize == 0);
DWORD ntprot=0, oldntprot=0;
if((prot & (PROT_READ|PROT_WRITE))==(PROT_READ|PROT_WRITE)) ntprot|=PAGE_READWRITE; if((prot & (PROT_READ|PROT_WRITE))==(PROT_READ|PROT_WRITE)) ntprot|=PAGE_READWRITE;
else if(prot & PROT_READ) ntprot|=PAGE_READONLY; else if(prot & PROT_READ) ntprot|=PAGE_READONLY;
else if(prot & PROT_WRITE) ntprot|=PAGE_READWRITE; else if(prot & PROT_WRITE) ntprot|=PAGE_READWRITE;
@ -7984,7 +7975,8 @@ static int mprotect(const void *addr, long len, int prot)
{ /* prot==PROT_NONE also appears to be a euphemism for free */ { /* prot==PROT_NONE also appears to be a euphemism for free */
MEMORY_BASIC_INFORMATION mbi; MEMORY_BASIC_INFORMATION mbi;
DWORD read=0; DWORD read=0;
for(char *p=((char *)addr)+read; read<len && VirtualQuery(p, &mbi, sizeof(mbi)); read+=mbi.RegionSize) char *p;
for(p=((char *)addr)+read; read<len && VirtualQuery(p, &mbi, sizeof(mbi)); read+=mbi.RegionSize)
{ {
if(mbi.State & MEM_COMMIT) if(mbi.State & MEM_COMMIT)
{ {
@ -8003,7 +7995,7 @@ static int mprotect(const void *addr, long len, int prot)
#ifdef TRACE #ifdef TRACE
printf ("Protect %p %d %d\n", addr, len, prot); printf ("Protect %p %d %d\n", addr, len, prot);
#endif #endif
mprotect_exit: mprotect_exit:
/* Release spin lock */ /* Release spin lock */
/* slrelease (&g_sl); */ /* slrelease (&g_sl); */
return rc; return rc;
@ -8220,5 +8212,4 @@ History:
*/ */
#endif // USE_MEMORY_PTMALLOC2 #endif