From a97cd0077fbe2df315a9356e38b39a5065b77c02 Mon Sep 17 00:00:00 2001 From: CeRiAl Date: Tue, 18 Oct 2011 13:10:20 +0200 Subject: WINCE: Add workaround for memory management problem on Windows CE < 6.0 This fixes the "32MB memory limit per process" problem in Windows CE < 6.0 --- backends/platform/wince/README-WinCE.txt | 21 +++++++++------ backends/platform/wince/wince-sdl.cpp | 44 ++++++++++++++++++++++++++++++++ backends/platform/wince/wince.mk | 4 +++ configure | 2 ++ 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/backends/platform/wince/README-WinCE.txt b/backends/platform/wince/README-WinCE.txt index 60bcf710bb..429168c293 100644 --- a/backends/platform/wince/README-WinCE.txt +++ b/backends/platform/wince/README-WinCE.txt @@ -1,18 +1,23 @@ ScummVM Windows CE FAQ -Last updated: 2011-07-20 -Release version: x.x.x +Last updated: 2011-10-15 +Release version: 1.4.0 ------------------------------------------------------------------------ New in this version ------------------- -x.x.x: -- Changed default values for "high_sample_rate" & "FM_high_quality" to "true" as - most devices today are fast enough to handle this. It's still possible to set - this to "false" if you have a slower device. +1.4.0: +- Changed the memory management so that it is finally possible to break the + 32MB per process barrier on Windows CE. It should be possible now (finally) + to play nearly every game with the "big" binary (scummvm.exe, which includes + all game engines). +- Changed default values for "high_sample_rate" & "FM_high_quality" to "true" + as most devices today are fast enough to handle this. It's still possible to + set this to "false" if you have a slower device. - Fix for TeenAgent & Hugo engines (both weren't running at all, crashed right at the beginning) -- Replaced the game mass-adding functionality with the functionality used on all - other platforms. It now shows progress while searching for games. +- Discworld 2 is now playable (works now because of the new memory management) +- Replaced the game mass-adding functionality with the functionality used on + all other platforms. It now shows progress while searching for games. 1.3.1: - Fix for Normal2xAspect scaler which was causing screen update issues in some diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp index 1abc3cb350..4e17827e5c 100644 --- a/backends/platform/wince/wince-sdl.cpp +++ b/backends/platform/wince/wince-sdl.cpp @@ -72,6 +72,50 @@ extern "C" _CRTIMP FILE *__cdecl _wfreopen(const wchar_t *, const wchar_t *, FILE *); #endif +#ifdef WRAP_MALLOC + +extern "C" void *__real_malloc(size_t size); +extern "C" void __real_free(void *ptr); + +extern "C" void *__wrap_malloc(size_t size) { +/* + void *ptr = __real_malloc(size); + printf("malloc(%d) = %p\n", size, ptr); + return ptr; +*/ + if (size < 64 * 1024) { + void *ptr = __real_malloc(size+4); +// printf("malloc(%d) = %p\n", size, ptr); + if (ptr != NULL) { + *((HANDLE*)ptr) = 0; + return 4+(char*)ptr; + } + return NULL; + } + HANDLE H = CreateFileMapping((HANDLE)INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size+4, 0); + void *ptr = MapViewOfFile(H, FILE_MAP_ALL_ACCESS, 0, 0, 0); + *((HANDLE*)ptr) = H; + return 4+(char*)ptr; +} + +extern "C" void __wrap_free(void *ptr) { +/* + __real_free(ptr); + printf("free(%p)\n", ptr); +*/ + if (ptr != NULL) { + HANDLE H = *(HANDLE*)((char *)ptr-4); + if (H == 0) { + __real_free((char*)ptr-4); + return; + } + UnmapViewOfFile((char *)ptr-4); + CloseHandle(H); + } +} + +#endif + using namespace CEGUI; // ******************************************************************************************** diff --git a/backends/platform/wince/wince.mk b/backends/platform/wince/wince.mk index cac3ad4e8f..c5f3274747 100644 --- a/backends/platform/wince/wince.mk +++ b/backends/platform/wince/wince.mk @@ -1,3 +1,7 @@ +ifdef WRAP_MALLOC + LDFLAGS += -Wl,--wrap,malloc -Wl,--wrap,free +endif + backends/platform/wince/PocketSCUMM.o: $(srcdir)/backends/platform/wince/PocketSCUMM.rc $(QUIET)$(MKDIR) $(*D) $(WINDRES) $(WINDRESFLAGS) -I$(srcdir)/backends/platform/wince $< $@ diff --git a/configure b/configure index ede6dd350a..6fa45ba5ba 100755 --- a/configure +++ b/configure @@ -2066,9 +2066,11 @@ case $_host_os in DEFINES="$DEFINES -DUNICODE" DEFINES="$DEFINES -DFPM_DEFAULT" DEFINES="$DEFINES -DNONSTANDARD_PORT" + DEFINES="$DEFINES -DWRAP_MALLOC" DEFINES="$DEFINES -DWIN32" DEFINES="$DEFINES -Dcdecl=" DEFINES="$DEFINES -D__cdecl__=" + add_line_to_config_mk "WRAP_MALLOC = 1" ;; esac -- cgit v1.2.3