Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-11-13 00:16:53 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-11-13 00:16:53 +0300
commitbdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch)
treed00eb50b749cb001e2b08272c91791e66740b05d /intern/guardedalloc
parent78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff)
parent7e4db234cee71ead34ee81a12e27da4bd548eb4b (diff)
Merge of trunk into blender 2.5:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416 Issues: * GHOST/X11 had conflicting changes. Some code was added in 2.5, which was later added in trunk also, but reverted partially, specifically revision 16683. I have left out this reversion in the 2.5 branch since I think it is needed there. http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683 * Scons had various conflicting changes, I decided to go with trunk version for everything except priorities and some library renaming. * In creator.c, there were various fixes and fixes for fixes related to the -w -W and -p options. In 2.5 -w and -W is not coded yet, and -p is done differently. Since this is changed so much, and I don't think those fixes would be needed in 2.5, I've left them out. * Also in creator.c: there was code for a python bugfix where the screen was not initialized when running with -P. The code that initializes the screen there I had to disable, that can't work in 2.5 anymore but left it commented as a reminder. Further I had to disable some new function calls. using src/ and python/, as was done already in this branch, disabled function calls: * bpath.c: error reporting * BME_conversions.c: editmesh conversion functions. * SHD_dynamic: disabled almost completely, there is no python/. * KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled. * text.c: clipboard copy call. * object.c: OB_SUPPORT_MATERIAL. * DerivedMesh.c and subsurf_ccg, stipple_quarttone. Still to be done: * Go over files and functions that were moved to a different location but could still use changes that were done in trunk.
Diffstat (limited to 'intern/guardedalloc')
-rw-r--r--intern/guardedalloc/BLO_sys_types.h125
-rw-r--r--intern/guardedalloc/MEM_guardedalloc.h17
-rw-r--r--intern/guardedalloc/intern/mallocn.c169
-rw-r--r--intern/guardedalloc/intern/mmap_win.c260
-rw-r--r--intern/guardedalloc/make/msvc_7_0/guardedalloc.vcproj13
-rw-r--r--intern/guardedalloc/make/msvc_9_0/guardedalloc.vcproj369
-rw-r--r--intern/guardedalloc/mmap_win.h54
7 files changed, 991 insertions, 16 deletions
diff --git a/intern/guardedalloc/BLO_sys_types.h b/intern/guardedalloc/BLO_sys_types.h
new file mode 100644
index 00000000000..5ed3117c890
--- /dev/null
+++ b/intern/guardedalloc/BLO_sys_types.h
@@ -0,0 +1,125 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ * A platform-independent definition of [u]intXX_t
+ * Plus the accompanying header include for htonl/ntohl
+ *
+ * This file includes <sys/types.h> to define [u]intXX_t types, where
+ * XX can be 8, 16, 32 or 64. Unfortunately, not all systems have this
+ * file.
+ * - Windows uses __intXX compiler-builtin types. These are signed,
+ * so we have to flip the signs.
+ * For these rogue platforms, we make the typedefs ourselves.
+ *
+ */
+
+/*
+// DG: original BLO_sys_types.h is in source/blender/blenkernel
+// but is not allowed be accessed here because of bad-level-call
+*/
+
+#ifndef BLO_SYS_TYPES_H
+#define BLO_SYS_TYPES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_WIN32) && !defined(FREE_WINDOWS)
+
+/* The __intXX are built-in types of the visual complier! So we don't
+ * need to include anything else here. */
+
+typedef signed __int8 int8_t;
+typedef signed __int16 int16_t;
+typedef signed __int32 int32_t;
+typedef signed __int64 int64_t;
+
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+
+#ifndef _INTPTR_T_DEFINED
+#ifdef _WIN64
+typedef __int64 intptr_t;
+#else
+typedef long intptr_t;
+#endif
+#define _INTPTR_T_DEFINED
+#endif
+
+#ifndef _UINTPTR_T_DEFINED
+#ifdef _WIN64
+typedef unsigned __int64 uintptr_t;
+#else
+typedef unsigned long uintptr_t;
+#endif
+#define _UINTPTR_T_DEFINED
+#endif
+
+#elif defined(__linux__)
+
+ /* Linux-i386, Linux-Alpha, Linux-ppc */
+#include <stdint.h>
+
+#elif defined (__APPLE__)
+
+#include <inttypes.h>
+
+#elif defined(FREE_WINDOWS)
+
+#include <stdint.h>
+
+#else
+
+ /* FreeBSD, Irix, Solaris */
+#include <sys/types.h>
+
+#endif /* ifdef platform for types */
+
+#ifdef _WIN32
+#ifndef htonl
+#define htonl(x) correctByteOrder(x)
+#endif
+#ifndef ntohl
+#define ntohl(x) correctByteOrder(x)
+#endif
+#elif defined (__FreeBSD__) || defined (__OpenBSD__)
+#include <sys/param.h>
+#elif defined (__APPLE__)
+#include <sys/types.h>
+#else /* irix sun linux */
+#include <netinet/in.h>
+#endif /* ifdef platform for htonl/ntohl */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* eof */
+
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index ef40b2a1163..1d4c753802b 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -58,8 +58,8 @@
#ifndef MEM_MALLOCN_H
#define MEM_MALLOCN_H
-/* Needed for FILE* */
-#include "stdio.h"
+#include "stdio.h" /* needed for FILE* */
+#include "BLO_sys_types.h" /* needed for uintptr_t */
#ifdef __cplusplus
extern "C" {
@@ -97,9 +97,16 @@ extern "C" {
void *MEM_mapallocN(unsigned int len, const char * str);
/** Print a list of the names and sizes of all allocated memory
+ * blocks. as a python dict for easy investigation */
+ void MEM_printmemlist_pydict(void);
+
+ /** Print a list of the names and sizes of all allocated memory
* blocks. */
void MEM_printmemlist(void);
+ /** Print statistics about memory usage */
+ void MEM_printmemlist_stats(void);
+
/** Set the callback function for error output. */
void MEM_set_error_callback(void (*func)(char *));
@@ -116,6 +123,12 @@ extern "C" {
/** Attempt to enforce OSX (or other OS's) to have malloc and stack nonzero */
void MEM_set_memory_debug(void);
+ /* Memory usage stats
+ * - MEM_get_memory_in_use is all memory
+ * - MEM_get_mapped_memory_in_use is a subset of all memory */
+ uintptr_t MEM_get_memory_in_use(void);
+ uintptr_t MEM_get_mapped_memory_in_use(void);
+ int MEM_get_memory_blocks_in_use(void);
#ifdef __cplusplus
}
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index b9d5a595363..7bdca7339fc 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -38,7 +38,10 @@
#include <stdarg.h>
/* mmap exception */
-#if defined(AMIGA) || defined(__BeOS) || defined(WIN32)
+#if defined(AMIGA) || defined(__BeOS)
+#elif defined(WIN32)
+#include <sys/types.h>
+#include "mmap_win.h"
#else
#include <sys/types.h>
#include <sys/mman.h>
@@ -108,11 +111,11 @@ static const char *check_memlist(MemHead *memh);
/* --------------------------------------------------------------------- */
-volatile int totblock= 0;
-volatile unsigned long mem_in_use= 0, mmap_in_use= 0;
+static volatile int totblock= 0;
+static volatile uintptr_t mem_in_use= 0, mmap_in_use= 0;
-volatile static struct localListBase _membase;
-volatile static struct localListBase *membase = &_membase;
+static volatile struct localListBase _membase;
+static volatile struct localListBase *membase = &_membase;
static void (*error_callback)(char *) = NULL;
static void (*thread_lock_callback)(void) = NULL;
static void (*thread_unlock_callback)(void) = NULL;
@@ -289,7 +292,7 @@ void *MEM_callocN(unsigned int len, const char *str)
/* note; mmap returns zero'd memory */
void *MEM_mapallocN(unsigned int len, const char *str)
{
-#if defined(AMIGA) || defined(__BeOS) || defined(WIN32)
+#if defined(AMIGA) || defined(__BeOS)
return MEM_callocN(len, str);
#else
MemHead *memh;
@@ -329,25 +332,146 @@ void *MEM_mapallocN(unsigned int len, const char *str)
#endif
}
+/* Memory statistics print */
+typedef struct MemPrintBlock {
+ const char *name;
+ uintptr_t len;
+ int items;
+} MemPrintBlock;
+
+static int compare_name(const void *p1, const void *p2)
+{
+ const MemPrintBlock *pb1= (const MemPrintBlock*)p1;
+ const MemPrintBlock *pb2= (const MemPrintBlock*)p2;
+
+ return strcmp(pb1->name, pb2->name);
+}
+
+static int compare_len(const void *p1, const void *p2)
+{
+ const MemPrintBlock *pb1= (const MemPrintBlock*)p1;
+ const MemPrintBlock *pb2= (const MemPrintBlock*)p2;
+
+ if(pb1->len < pb2->len)
+ return 1;
+ else if(pb1->len == pb2->len)
+ return 0;
+ else
+ return -1;
+}
-void MEM_printmemlist()
+void MEM_printmemlist_stats()
{
MemHead *membl;
+ MemPrintBlock *pb, *printblock;
+ int totpb, a, b;
mem_lock_thread();
+ /* put memory blocks into array */
+ printblock= malloc(sizeof(MemPrintBlock)*totblock);
+
+ pb= printblock;
+ totpb= 0;
+
membl = membase->first;
if (membl) membl = MEMNEXT(membl);
+
while(membl) {
- print_error("%s len: %d %p\n",membl->name,membl->len, membl+1);
+ pb->name= membl->name;
+ pb->len= membl->len;
+ pb->items= 1;
+
+ totpb++;
+ pb++;
+
if(membl->next)
membl= MEMNEXT(membl->next);
else break;
}
+ /* sort by name and add together blocks with the same name */
+ qsort(printblock, totpb, sizeof(MemPrintBlock), compare_name);
+ for(a=0, b=0; a<totpb; a++) {
+ if(a == b) {
+ continue;
+ }
+ else if(strcmp(printblock[a].name, printblock[b].name) == 0) {
+ printblock[b].len += printblock[a].len;
+ printblock[b].items++;
+ }
+ else {
+ b++;
+ memcpy(&printblock[b], &printblock[a], sizeof(MemPrintBlock));
+ }
+ }
+ totpb= b+1;
+
+ /* sort by length and print */
+ qsort(printblock, totpb, sizeof(MemPrintBlock), compare_len);
+ printf("\ntotal memory len: %.3f MB\n", (double)mem_in_use/(double)(1024*1024));
+ for(a=0, pb=printblock; a<totpb; a++, pb++)
+ printf("%s items: %d, len: %.3f MB\n", pb->name, pb->items, (double)pb->len/(double)(1024*1024));
+
+ free(printblock);
+
+ mem_unlock_thread();
+}
+
+/* Prints in python syntax for easy */
+static void MEM_printmemlist_internal( int pydict )
+{
+ MemHead *membl;
+
+ mem_lock_thread();
+
+ membl = membase->first;
+ if (membl) membl = MEMNEXT(membl);
+
+ if (pydict) {
+ print_error("# membase_debug.py\n");
+ print_error("membase = [\\\n");
+ }
+ while(membl) {
+ if (pydict) {
+ fprintf(stderr, "{'len':%i, 'name':'''%s''', 'pointer':'%p'},\\\n", membl->len, membl->name, membl+1);
+ } else {
+ print_error("%s len: %d %p\n",membl->name,membl->len, membl+1);
+ }
+ if(membl->next)
+ membl= MEMNEXT(membl->next);
+ else break;
+ }
+ if (pydict) {
+ fprintf(stderr, "]\n\n");
+ fprintf(stderr,
+"mb_userinfo = {}\n"
+"totmem = 0\n"
+"for mb_item in membase:\n"
+"\tmb_item_user_size = mb_userinfo.setdefault(mb_item['name'], [0,0])\n"
+"\tmb_item_user_size[0] += 1 # Add a user\n"
+"\tmb_item_user_size[1] += mb_item['len'] # Increment the size\n"
+"\ttotmem += mb_item['len']\n"
+"print '(membase) items:', len(membase), '| unique-names:', len(mb_userinfo), '| total-mem:', totmem\n"
+"mb_userinfo_sort = mb_userinfo.items()\n"
+"for sort_name, sort_func in (('size', lambda a: -a[1][1]), ('users', lambda a: -a[1][0]), ('name', lambda a: a[0])):\n"
+"\tprint '\\nSorting by:', sort_name\n"
+"\tmb_userinfo_sort.sort(key = sort_func)\n"
+"\tfor item in mb_userinfo_sort:\n"
+"\t\tprint 'name:%%s, users:%%i, len:%%i' %% (item[0], item[1][0], item[1][1])\n"
+ );
+ }
+
mem_unlock_thread();
}
+void MEM_printmemlist( void ) {
+ MEM_printmemlist_internal(0);
+}
+void MEM_printmemlist_pydict( void ) {
+ MEM_printmemlist_internal(1);
+}
+
short MEM_freeN(void *vmemh) /* anders compileertie niet meer */
{
short error = 0;
@@ -361,14 +485,14 @@ short MEM_freeN(void *vmemh) /* anders compileertie niet meer */
return(-1);
}
- if(sizeof(long)==8) {
- if (((long) memh) & 0x7) {
+ if(sizeof(intptr_t)==8) {
+ if (((intptr_t) memh) & 0x7) {
MemorY_ErroR("free","attempt to free illegal pointer");
return(-1);
}
}
else {
- if (((long) memh) & 0x3) {
+ if (((intptr_t) memh) & 0x3) {
MemorY_ErroR("free","attempt to free illegal pointer");
return(-1);
}
@@ -405,8 +529,10 @@ short MEM_freeN(void *vmemh) /* anders compileertie niet meer */
} else{
error = -1;
name = check_memlist(memh);
- if (name == 0) MemorY_ErroR("free","pointer not in memlist");
- else MemorY_ErroR(name,"error in header");
+ if (name == 0)
+ MemorY_ErroR("free","pointer not in memlist");
+ else
+ MemorY_ErroR(name,"error in header");
}
totblock--;
@@ -463,7 +589,7 @@ static void rem_memblock(MemHead *memh)
totblock--;
mem_in_use -= memh->len;
-#if defined(AMIGA) || defined(__BeOS) || defined(WIN32)
+#if defined(AMIGA) || defined(__BeOS)
free(memh);
#else
@@ -570,4 +696,19 @@ static const char *check_memlist(MemHead *memh)
return(name);
}
+uintptr_t MEM_get_memory_in_use(void)
+{
+ return mem_in_use;
+}
+
+uintptr_t MEM_get_mapped_memory_in_use(void)
+{
+ return mmap_in_use;
+}
+
+int MEM_get_memory_blocks_in_use(void)
+{
+ return totblock;
+}
+
/* eof */
diff --git a/intern/guardedalloc/intern/mmap_win.c b/intern/guardedalloc/intern/mmap_win.c
new file mode 100644
index 00000000000..642cc16296e
--- /dev/null
+++ b/intern/guardedalloc/intern/mmap_win.c
@@ -0,0 +1,260 @@
+/**
+ * $Id: $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Andrea Weikert.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#if defined(WIN32)
+
+#include <windows.h>
+#include <errno.h>
+#include <io.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+#include "mmap_win.h"
+
+#ifndef FILE_MAP_EXECUTE
+//not defined in earlier versions of the Platform SDK (before February 2003)
+#define FILE_MAP_EXECUTE 0x0020
+#endif
+
+/* --------------------------------------------------------------------- */
+/* local storage definitions */
+/* --------------------------------------------------------------------- */
+/* all memory mapped chunks are put in linked lists */
+typedef struct mmapLink
+{
+ struct mmapLink *next,*prev;
+} mmapLink;
+
+typedef struct mmapListBase
+{
+ void *first, *last;
+} mmapListBase;
+
+typedef struct MemMap {
+ struct MemMap *next,*prev;
+ void *mmap;
+ HANDLE fhandle;
+ HANDLE maphandle;
+} MemMap;
+
+/* --------------------------------------------------------------------- */
+/* local functions */
+/* --------------------------------------------------------------------- */
+
+static void mmap_addtail(volatile mmapListBase *listbase, void *vlink);
+static void mmap_remlink(volatile mmapListBase *listbase, void *vlink);
+static void *mmap_findlink(volatile mmapListBase *listbase, void *ptr);
+
+static int mmap_get_prot_flags (int flags);
+static int mmap_get_access_flags (int flags);
+
+/* --------------------------------------------------------------------- */
+/* vars */
+/* --------------------------------------------------------------------- */
+volatile static struct mmapListBase _mmapbase;
+volatile static struct mmapListBase *mmapbase = &_mmapbase;
+
+
+/* --------------------------------------------------------------------- */
+/* implementation */
+/* --------------------------------------------------------------------- */
+
+/* mmap for windows */
+void *mmap(void *start, size_t len, int prot, int flags, int fd, off_t offset)
+{
+ HANDLE fhandle = INVALID_HANDLE_VALUE;
+ HANDLE maphandle;
+ int prot_flags = mmap_get_prot_flags(prot);
+ int access_flags = mmap_get_access_flags(prot);
+ MemMap *mm = NULL;
+ void *ptr = NULL;
+
+ if ( flags & MAP_FIXED ) {
+ return MAP_FAILED;
+ }
+
+ /*
+ if ( fd == -1 ) {
+ _set_errno( EBADF );
+ return MAP_FAILED;
+ }
+ */
+
+ if ( fd != -1 ) {
+ fhandle = (HANDLE) _get_osfhandle (fd);
+ }
+ if ( fhandle == INVALID_HANDLE_VALUE ) {
+ if (!(flags & MAP_ANONYMOUS)) {
+ errno = EBADF;
+ return MAP_FAILED;
+ }
+ } else {
+ if ( !DuplicateHandle( GetCurrentProcess(), fhandle, GetCurrentProcess(),
+ &fhandle, 0, FALSE, DUPLICATE_SAME_ACCESS ) ) {
+ return MAP_FAILED;
+ }
+ }
+
+ maphandle = CreateFileMapping(fhandle, NULL, prot_flags, 0, len, NULL);
+ if ( maphandle == 0 ) {
+ errno = EBADF;
+ return MAP_FAILED;
+ }
+
+ ptr = MapViewOfFile(maphandle, access_flags, 0, offset, 0);
+ if ( ptr == NULL ) {
+ DWORD dwLastErr = GetLastError();
+ if ( dwLastErr == ERROR_MAPPED_ALIGNMENT )
+ errno=EINVAL;
+ else
+ errno=EACCES;
+ CloseHandle(maphandle);
+ return MAP_FAILED;
+ }
+
+ mm= (MemMap *)malloc(sizeof(MemMap));
+ if (!mm) {
+ errno=ENOMEM;
+ }
+ mm->fhandle = fhandle;
+ mm->maphandle = maphandle;
+ mm->mmap = ptr;
+ mmap_addtail(mmapbase, mm);
+
+ return ptr;
+}
+
+/* munmap for windows */
+intptr_t munmap(void *ptr, intptr_t size)
+{
+ MemMap *mm = mmap_findlink(mmapbase, ptr);
+ if (!mm) {
+ errno=EINVAL;
+ return -1;
+ }
+ UnmapViewOfFile( mm->mmap );
+ CloseHandle( mm->maphandle );
+ CloseHandle( mm->fhandle);
+ mmap_remlink(mmapbase, mm);
+ return 0;
+}
+
+/* --------------------------------------------------------------------- */
+/* local functions */
+/* --------------------------------------------------------------------- */
+
+static void mmap_addtail(volatile mmapListBase *listbase, void *vlink)
+{
+ struct mmapLink *link= vlink;
+
+ if (link == 0) return;
+ if (listbase == 0) return;
+
+ link->next = 0;
+ link->prev = listbase->last;
+
+ if (listbase->last) ((struct mmapLink *)listbase->last)->next = link;
+ if (listbase->first == 0) listbase->first = link;
+ listbase->last = link;
+}
+
+static void mmap_remlink(volatile mmapListBase *listbase, void *vlink)
+{
+ struct mmapLink *link= vlink;
+
+ if (link == 0) return;
+ if (listbase == 0) return;
+
+ if (link->next) link->next->prev = link->prev;
+ if (link->prev) link->prev->next = link->next;
+
+ if (listbase->last == link) listbase->last = link->prev;
+ if (listbase->first == link) listbase->first = link->next;
+}
+
+static void *mmap_findlink(volatile mmapListBase *listbase, void *ptr)
+{
+ MemMap *mm;
+
+ if (ptr == 0) return NULL;
+ if (listbase == 0) return NULL;
+
+ mm = (MemMap *)listbase->first;
+ while (mm) {
+ if (mm->mmap == ptr) {
+ return mm;
+ }
+ mm = mm->next;
+ }
+ return NULL;
+}
+
+static int mmap_get_prot_flags (int flags)
+{
+ int prot = PAGE_NOACCESS;
+
+ if ( ( flags & PROT_READ ) == PROT_READ ) {
+ if ( ( flags & PROT_WRITE ) == PROT_WRITE ) {
+ prot = (flags & PROT_EXEC) ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
+ } else {
+ prot = (flags & PROT_EXEC) ? PAGE_EXECUTE_READ : PAGE_READONLY;
+ }
+ } else if ( ( flags & PROT_WRITE ) == PROT_WRITE ) {
+ prot = (flags & PROT_EXEC) ? PAGE_EXECUTE_READ : PAGE_WRITECOPY;
+ } else if ( ( flags & PROT_EXEC ) == PROT_EXEC ) {
+ prot = PAGE_EXECUTE_READ;
+ }
+ return prot;
+}
+
+static int mmap_get_access_flags (int flags)
+{
+ int access = 0;
+
+ if ( ( flags & PROT_READ ) == PROT_READ ) {
+ if ( ( flags & PROT_WRITE ) == PROT_WRITE ) {
+ access = FILE_MAP_WRITE;
+ } else {
+ access = (flags & PROT_EXEC) ? FILE_MAP_EXECUTE : FILE_MAP_READ;
+ }
+ } else if ( ( flags & PROT_WRITE ) == PROT_WRITE ) {
+ access = FILE_MAP_COPY;
+ } else if ( ( flags & PROT_EXEC ) == PROT_EXEC ) {
+ access = FILE_MAP_EXECUTE;
+ }
+ return access;
+}
+
+
+#endif // WIN32
+
+
+
+
+
diff --git a/intern/guardedalloc/make/msvc_7_0/guardedalloc.vcproj b/intern/guardedalloc/make/msvc_7_0/guardedalloc.vcproj
index cb3490716fa..974acef4e70 100644
--- a/intern/guardedalloc/make/msvc_7_0/guardedalloc.vcproj
+++ b/intern/guardedalloc/make/msvc_7_0/guardedalloc.vcproj
@@ -251,6 +251,9 @@ ECHO Done
<File
RelativePath="..\..\intern\mallocn.c">
</File>
+ <File
+ RelativePath="..\..\intern\mmap_win.c">
+ </File>
</Filter>
<Filter
Name="Header Files"
@@ -259,8 +262,18 @@ ECHO Done
Name="extern"
Filter="">
<File
+ RelativePath="..\..\BLO_sys_types.h">
+ </File>
+ <File
RelativePath="..\..\MEM_guardedalloc.h">
</File>
+ <File
+ RelativePath="..\..\mmap_win.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="intern"
+ Filter="">
</Filter>
</Filter>
</Files>
diff --git a/intern/guardedalloc/make/msvc_9_0/guardedalloc.vcproj b/intern/guardedalloc/make/msvc_9_0/guardedalloc.vcproj
new file mode 100644
index 00000000000..d59b80f7b62
--- /dev/null
+++ b/intern/guardedalloc/make/msvc_9_0/guardedalloc.vcproj
@@ -0,0 +1,369 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9,00"
+ Name="INT_guardedalloc"
+ ProjectGUID="{1CC733F1-6AB5-4904-8F63-C08C46B79DD9}"
+ RootNamespace="guardedalloc"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Blender Release|Win32"
+ OutputDirectory="..\..\..\..\..\build\msvc_9\intern\guardedalloc"
+ IntermediateDirectory="..\..\..\..\..\build\msvc_9\intern\guardedalloc"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ InlineFunctionExpansion="1"
+ AdditionalIncludeDirectories="..\.."
+ PreprocessorDefinitions="WIN32,NDEBUG,_LIB"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile="..\..\..\..\..\build\msvc_9\intern\guardedalloc\guardedalloc.pch"
+ AssemblerListingLocation="..\..\..\..\..\build\msvc_9\intern\guardedalloc\"
+ ObjectFile="..\..\..\..\..\build\msvc_9\intern\guardedalloc\"
+ ProgramDataBaseFileName="..\..\..\..\..\build\msvc_9\intern\guardedalloc\"
+ WarningLevel="2"
+ SuppressStartupBanner="true"
+ CompileAs="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile="..\..\..\..\..\build\msvc_9\libs\intern\libguardedalloc.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Copying MEM files library to lib tree."
+ CommandLine="ECHO Copying header files&#x0D;&#x0A;IF NOT EXIST ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include MKDIR ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include&#x0D;&#x0A;XCOPY /Y ..\..\*.h ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include&#x0D;&#x0A;ECHO Done&#x0D;&#x0A;"
+ />
+ </Configuration>
+ <Configuration
+ Name="Blender Debug|Win32"
+ OutputDirectory="..\..\..\..\..\build\msvc_9\intern\guardedalloc\debug"
+ IntermediateDirectory="..\..\..\..\..\build\msvc_9\intern\guardedalloc\debug"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\.."
+ PreprocessorDefinitions="WIN32,_DEBUG,_LIB"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ BufferSecurityCheck="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile="..\..\..\..\..\build\msvc_9\intern\guardedalloc\debug\guardedalloc.pch"
+ AssemblerListingLocation="..\..\..\..\..\build\msvc_9\intern\guardedalloc\debug\"
+ ObjectFile="..\..\..\..\..\build\msvc_9\intern\guardedalloc\debug\"
+ ProgramDataBaseFileName="..\..\..\..\..\build\msvc_9\intern\guardedalloc\debug\"
+ WarningLevel="2"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ CompileAs="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile="..\..\..\..\..\build\msvc_9\libs\intern\debug\libguardedalloc.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Copying MEM files library (debug target) to lib tree."
+ CommandLine="ECHO Copying header files&#x0D;&#x0A;IF NOT EXIST ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include MKDIR ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include&#x0D;&#x0A;XCOPY /Y ..\..\*.h ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include&#x0D;&#x0A;ECHO Done&#x0D;&#x0A;"
+ />
+ </Configuration>
+ <Configuration
+ Name="3DPlugin Release|Win32"
+ OutputDirectory="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll"
+ IntermediateDirectory="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ InlineFunctionExpansion="1"
+ AdditionalIncludeDirectories="..\.."
+ PreprocessorDefinitions="WIN32,NDEBUG,_LIB"
+ StringPooling="true"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\guardedalloc.pch"
+ AssemblerListingLocation="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\"
+ ObjectFile="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\"
+ ProgramDataBaseFileName="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\"
+ WarningLevel="2"
+ SuppressStartupBanner="true"
+ CompileAs="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile="..\..\..\..\..\build\msvc_9\libs\intern\mtdll\libguardedalloc.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Copying MEM files library to lib tree."
+ CommandLine="ECHO Copying header files&#x0D;&#x0A;IF NOT EXIST ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include MKDIR ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include&#x0D;&#x0A;XCOPY /Y ..\..\*.h ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include&#x0D;&#x0A;ECHO Done&#x0D;&#x0A;"
+ />
+ </Configuration>
+ <Configuration
+ Name="3DPlugin Debug|Win32"
+ OutputDirectory="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\debug"
+ IntermediateDirectory="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\debug"
+ ConfigurationType="4"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\.."
+ PreprocessorDefinitions="WIN32,_DEBUG,_LIB"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ BufferSecurityCheck="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\debug\guardedalloc.pch"
+ AssemblerListingLocation="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\debug\"
+ ObjectFile="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\debug\"
+ ProgramDataBaseFileName="..\..\..\..\..\build\msvc_9\intern\guardedalloc\mtdll\debug\"
+ WarningLevel="2"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ CompileAs="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile="..\..\..\..\..\build\msvc_9\libs\intern\mtdll\debug\libguardedalloc.lib"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Copying MEM files library (debug target) to lib tree."
+ CommandLine="ECHO Copying header files&#x0D;&#x0A;IF NOT EXIST ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include MKDIR ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include&#x0D;&#x0A;XCOPY /Y ..\..\*.h ..\..\..\..\..\build\msvc_9\intern\guardedalloc\include&#x0D;&#x0A;ECHO Done&#x0D;&#x0A;"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+ >
+ <File
+ RelativePath="..\..\intern\mallocn.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\intern\mmap_win.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl"
+ >
+ <Filter
+ Name="extern"
+ >
+ <File
+ RelativePath="..\..\BLO_sys_types.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\MEM_guardedalloc.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\mmap_win.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="intern"
+ >
+ </Filter>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/intern/guardedalloc/mmap_win.h b/intern/guardedalloc/mmap_win.h
new file mode 100644
index 00000000000..443c3b6f4ce
--- /dev/null
+++ b/intern/guardedalloc/mmap_win.h
@@ -0,0 +1,54 @@
+/**
+ * $Id: $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Andrea Weikert.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef MMAP_WIN_H
+#define MMAP_WIN_H
+
+#define PROT_NONE 0
+#define PROT_READ 1
+#define PROT_WRITE 2
+#define PROT_EXEC 4
+
+#define MAP_FILE 0
+#define MAP_SHARED 1
+#define MAP_PRIVATE 2
+#define MAP_TYPE 0xF
+#define MAP_FIXED 0x10
+#define MAP_ANONYMOUS 0x20
+#define MAP_ANON MAP_ANONYMOUS
+
+#define MAP_FAILED ((void *)-1)
+
+#include "BLO_sys_types.h" // needed for intptr_t
+
+void *mmap(void *start, size_t len, int prot, int flags, int fd, off_t offset);
+intptr_t munmap(void *ptr, intptr_t size);
+
+#endif
+