diff --git a/.appveyor.yml b/.appveyor.yml index 103067d864..8bb782d5a5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -19,56 +19,56 @@ environment: MINGW_ARCH: x86_64 # Main minheadless VM variants. - - FLAVOR: squeak.cog.spur + - FLAVOR: squeak.cog.spur.minheadless ARCH: win32x86 CPU_ARCH: x86 CYG_ROOT: C:\cygwin MINGW_ARCH: i686 BUILD_WITH_CMAKE: yes - - FLAVOR: squeak.cog.spur - ARCH: win64x64 - CPU_ARCH: x64 - CYG_ROOT: C:\cygwin64 - MINGW_ARCH: x86_64 - BUILD_WITH_CMAKE: yes - - FLAVOR: pharo.cog.spur + # - FLAVOR: squeak.cog.spur + # ARCH: win64x64 + # CPU_ARCH: x64 + # CYG_ROOT: C:\cygwin64 + # MINGW_ARCH: x86_64 + # BUILD_WITH_CMAKE: yes + - FLAVOR: pharo.cog.spur.minheadless ARCH: win32x86 CPU_ARCH: x86 CYG_ROOT: C:\cygwin MINGW_ARCH: i686 BUILD_WITH_CMAKE: yes - - FLAVOR: pharo.cog.spur - ARCH: win64x64 - CPU_ARCH: x64 - CYG_ROOT: C:\cygwin64 - MINGW_ARCH: x86_64 - BUILD_WITH_CMAKE: yes + # - FLAVOR: pharo.cog.spur + # ARCH: win64x64 + # CPU_ARCH: x64 + # CYG_ROOT: C:\cygwin64 + # MINGW_ARCH: x86_64 + # BUILD_WITH_CMAKE: yes # Minheadless VM variants with SDL2 based support for traditional display. - - FLAVOR: squeak.cog.spur+sdl2 - ARCH: win32x86 - CPU_ARCH: x86 - CYG_ROOT: C:\cygwin - MINGW_ARCH: i686 - BUILD_WITH_CMAKE: yes - - FLAVOR: squeak.cog.spur+sdl2 - ARCH: win64x64 - CPU_ARCH: x64 - CYG_ROOT: C:\cygwin64 - MINGW_ARCH: x86_64 - BUILD_WITH_CMAKE: yes - - FLAVOR: pharo.cog.spur+sdl2 - ARCH: win32x86 - CPU_ARCH: x86 - CYG_ROOT: C:\cygwin - MINGW_ARCH: i686 - BUILD_WITH_CMAKE: yes - - FLAVOR: pharo.cog.spur+sdl2 - ARCH: win64x64 - CPU_ARCH: x64 - CYG_ROOT: C:\cygwin64 - MINGW_ARCH: x86_64 - BUILD_WITH_CMAKE: yes + # - FLAVOR: squeak.cog.spur+sdl2 + # ARCH: win32x86 + # CPU_ARCH: x86 + # CYG_ROOT: C:\cygwin + # MINGW_ARCH: i686 + # BUILD_WITH_CMAKE: yes + # - FLAVOR: squeak.cog.spur+sdl2 + # ARCH: win64x64 + # CPU_ARCH: x64 + # CYG_ROOT: C:\cygwin64 + # MINGW_ARCH: x86_64 + # BUILD_WITH_CMAKE: yes + # - FLAVOR: pharo.cog.spur+sdl2 + # ARCH: win32x86 + # CPU_ARCH: x86 + # CYG_ROOT: C:\cygwin + # MINGW_ARCH: i686 + # BUILD_WITH_CMAKE: yes + # - FLAVOR: pharo.cog.spur+sdl2 + # ARCH: win64x64 + # CPU_ARCH: x64 + # CYG_ROOT: C:\cygwin64 + # MINGW_ARCH: x86_64 + # BUILD_WITH_CMAKE: yes # Other VM variants - FLAVOR: squeak.sista.spur @@ -132,6 +132,8 @@ environment: matrix: fast_finish: true allow_failures: + - FLAVOR: squeak.cog.spur.minheadless + - FLAVOR: pharo.cog.spur.minheadless - FLAVOR: squeak.sista.spur - FLAVOR: pharo.sista.spur - FLAVOR: squeak.cog.spur.lowcode diff --git a/build.win32x86/common/Makefile b/build.win32x86/common/Makefile index 6ac0cdfca9..6e614c0c7a 100644 --- a/build.win32x86/common/Makefile +++ b/build.win32x86/common/Makefile @@ -279,7 +279,6 @@ $(OBJDIR)/%.lib: $(call plugin-makefile,$(*F)) rm -f $(BUILD)/vm/$(*F).ignore $(MAKE) $(MFLAGS) BUILD=$(BUILD) \ -f $(call plugin-makefile,$(*F)) \ - $(OBJDIR)/$(*F).lib LIBNAME=$(*F) INTERNAL_PLUGIN=1 VMSRCDIR=$(VMSRCDIR) \ COGDEFS="$(COGDEFS) -DSQUEAK_BUILTIN_PLUGIN=$(*F)" $(OBJDIR)/$(*F).lib diff --git a/build.win32x86/common/Makefile.lib.extra b/build.win32x86/common/Makefile.lib.extra index d93b074ba3..6d56c1b94b 100644 --- a/build.win32x86/common/Makefile.lib.extra +++ b/build.win32x86/common/Makefile.lib.extra @@ -10,15 +10,16 @@ THIRDPARTYDIR?=$(BUILD)/third-party THIRDPARTYLIBDIR?=$(THIRDPARTYOUTDIR)/bin THIRDPARTYINCLUDEDIR?=$(THIRDPARTYOUTDIR)/include THIRDPARTYCACHEDIR?=../../.thirdparty-cache -THIRDPARTYOUTDIR?=$(abspath $(THIRDPARTYCACHEDIR)/windows/x86_64) +THIRDPARTYOUTDIR?=$(abspath $(THIRDPARTYCACHEDIR)/windows/i386) export THIRDPARTYOUTDIR THIRDPARTYINSTALLDIR?=$(BUILD)/vm -THIRDPARTY_CFLAGS?=-m64 -static-libgcc -static-libstdc++ -THIRDPARTY_LDFLAGS?=-m64 -static-libgcc -static-libstdc++ +THIRDPARTY_CFLAGS?=-m32 -static-libgcc -static-libstdc++ +THIRDPARTY_LDFLAGS?=-m32 -static-libgcc -static-libstdc++ WGET?=wget -q --no-check-certificate #I need this toolchain to compile external libraries with appropriate gcc -THIRDPARTY_TOOLCHAIN:=CC=x86_64-w64-mingw32-gcc AR=x86_64-w64-mingw32-ar LD=x86_64-w64-mingw32-clang NM=x86_64-w64-mingw32-nm RC=x86_64-w64-mingw32-windres DLLTOOL=x86_64-w64-mingw32-dlltool DLLWRAP=x86_64-w64-mingw32-dllwrap +THIRDPARTY_TOOLCHAIN_PREFIX:=i686-w64-mingw32- +THIRDPARTY_TOOLCHAIN:=CC=$(THIRDPARTY_TOOLCHAIN_PREFIX)gcc AR=$(THIRDPARTY_TOOLCHAIN_PREFIX)ar LD=$(THIRDPARTY_TOOLCHAIN_PREFIX)clang NM=$(THIRDPARTY_TOOLCHAIN_PREFIX)nm RC=$(THIRDPARTY_TOOLCHAIN_PREFIX)windres DLLTOOL=$(THIRDPARTY_TOOLCHAIN_PREFIX)dlltool DLLWRAP=$(THIRDPARTY_TOOLCHAIN_PREFIX)dllwrap $(THIRDPARTYDIR): diff --git a/build.win32x86/common/Makefile.msvc b/build.win32x86/common/Makefile.msvc index 88d56626ea..fd6320ad26 100644 --- a/build.win32x86/common/Makefile.msvc +++ b/build.win32x86/common/Makefile.msvc @@ -1,5 +1,5 @@ ############################################################################# -# Common Makefile for Win64 VM using MSVC, e.g. 2017 Community, and gnu make +# Common Makefile for Win32 VM using MSVC, e.g. 2017 Community, and gnu make # Copyright (c) 2020 3D Immersive Collaboration Consulting, LLC # # Do make init to allow make -n to function. @@ -122,8 +122,8 @@ VMRES:= $(VM).res VMDEFIN:=$(VM).def.in BTOBJ:= $(OBJDIR)/btext.o ETOBJ:= $(OBJDIR)/etext.o -JMPASM:=_setjmp-x64.asm -JMPOBJ:=$(OBJDIR)/_setjmp-x64.o +JMPASM:=_setjmp-x86.asm +JMPOBJ:=$(OBJDIR)/_setjmp-x86.o .PRECIOUS: mkNamedPrims.exe diff --git a/build.win64x64/common/Makefile b/build.win64x64/common/Makefile index c93625bb22..b5c151ba4d 100644 --- a/build.win64x64/common/Makefile +++ b/build.win64x64/common/Makefile @@ -279,7 +279,6 @@ $(OBJDIR)/%.lib: $(call plugin-makefile,$(*F)) rm -f $(BUILD)/vm/$(*F).ignore $(MAKE) $(MFLAGS) BUILD=$(BUILD) \ -f $(call plugin-makefile,$(*F)) \ - $(OBJDIR)/$(*F).lib LIBNAME=$(*F) INTERNAL_PLUGIN=1 VMSRCDIR=$(VMSRCDIR) \ COGDEFS="$(COGDEFS) -DSQUEAK_BUILTIN_PLUGIN=$(*F)" $(OBJDIR)/$(*F).lib diff --git a/platforms/minheadless/windows/sqWin32Alloc.c b/platforms/minheadless/windows/sqWin32Alloc.c index 26538f0634..803475e86b 100644 --- a/platforms/minheadless/windows/sqWin32Alloc.c +++ b/platforms/minheadless/windows/sqWin32Alloc.c @@ -45,6 +45,22 @@ LONG CALLBACK sqExceptionFilter(LPEXCEPTION_POINTERS exp) return EXCEPTION_WRONG_ACCESS; } +# define roundDownToPage(v) ((sqIntptr_t)(v)&pageMask) +# define roundUpToPage(v) (((sqIntptr_t)(v)+pageSize-1)&pageMask) + +static void +initPageSize() +{ + SYSTEM_INFO sysInfo; + + /* determine page boundaries & available address space */ + if (!pageSize) { + GetSystemInfo(&sysInfo); + pageSize = sysInfo.dwPageSize; + pageMask = ~(pageSize - 1); + } +} + /************************************************************************/ /* sqAllocateMemory: Initialize virtual memory */ /************************************************************************/ @@ -59,10 +75,10 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) pageMask = ~(pageSize - 1); /* round the requested size up to the next page boundary */ - nowReserved = (desiredHeapSize + pageSize) & pageMask; + nowReserved = roundUpToPage(desiredHeapSize); /* round the initial commited size up to the next page boundary */ - initialCommit = (minHeapSize + pageSize) & pageMask; + initialCommit = roundUpToPage(minHeapSize); /* Here, we only reserve the maximum memory to be used It will later be committed during actual access */ @@ -78,7 +94,7 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) } while(!pageBase); if(!pageBase) { sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"), - "Unable to allocate memory (%d bytes requested)", + TEXT("Unable to allocate memory (%d bytes requested)"), maxReserved); return pageBase; } @@ -86,7 +102,7 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) commit = nowReserved; if(!VirtualAlloc(pageBase, commit, MEM_COMMIT, PAGE_READWRITE)) { sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"), - "Unable to commit memory (%d bytes requested)", + TEXT("Unable to commit memory (%d bytes requested)"), commit); return NULL; } @@ -176,34 +192,40 @@ sqMemoryExtraBytesLeft(int includingSwap) { return bytesLeft; } -#define roundDownToPage(v) ((v)&pageMask) -#define roundUpToPage(v) (((v)+pageSize-1)&pageMask) - # if COGVM void sqMakeMemoryExecutableFromToCodeToDataDelta(usqInt startAddr, usqInt endAddr, sqInt *codeToDataDelta) { - DWORD previous; - - if (!VirtualProtect((void *)startAddr, - endAddr - startAddr + 1, - PAGE_EXECUTE_READWRITE, - &previous)) - sqWin32PrintLastError("VirtualProtect(x,y,PAGE_EXECUTE_READWRITE)"); - if(codeToDataDelta) - *codeToDataDelta = 0; + DWORD previous; + SIZE_T size; + + size = endAddr - startAddr; + if (!VirtualProtect((void *)startAddr, + size, + PAGE_EXECUTE_READWRITE, + &previous)) + sqWin32PrintLastError("VirtualProtect(x,y,PAGE_EXECUTE_READWRITE)"); + if (codeToDataDelta) + *codeToDataDelta = 0; } -void -sqMakeMemoryNotExecutableFromTo(usqInt startAddr, usqInt endAddr) +void * +allocateJITMemory(usqInt *desiredSize) { - DWORD previous; + initPageSize(); + + sqInt allocBytes = roundUpToPage(*desiredSize); + + /* Allocate extra memory for the JIT. No need to make it executable (i.e., PAGE_EXECUTE_READWRITE) right away because there will be an extra call to sqMakeMemoryExecutableFromToCodeToDataDelta(..) anyway. */ + char *alloc = VirtualAlloc(NULL,allocBytes,MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); + + if (!alloc) { + sqWin32PrintLastError("Could not allocate JIT memory"); + exit(1); + } - if (!VirtualProtect((void *)startAddr, - endAddr - startAddr + 1, - PAGE_READWRITE, - &previous)) - sqWin32PrintLastError("VirtualProtect(x,y,PAGE_EXECUTE_READWRITE)"); + *desiredSize = allocBytes; + return alloc; } # endif /* COGVM */ #endif /* !defined(NO_VIRTUAL_MEMORY) && !SPURVM */ diff --git a/platforms/minheadless/windows/sqWin32SpurAlloc.c b/platforms/minheadless/windows/sqWin32SpurAlloc.c index f689bbf1cc..9eb7b31ea3 100644 --- a/platforms/minheadless/windows/sqWin32SpurAlloc.c +++ b/platforms/minheadless/windows/sqWin32SpurAlloc.c @@ -35,32 +35,24 @@ static sqIntptr_t pageSize; /* size of a memory page */ static char *minAppAddr; /* SYSTEM_INFO lpMinimumApplicationAddress */ static char *maxAppAddr; /* SYSTEM_INFO lpMaximumApplicationAddress */ -# define roundDownToPage(v) ((v)&pageMask) -# define roundUpToPage(v) (((v)+pageSize-1)&pageMask) +# define roundDownToPage(v) ((sqIntptr_t)(v)&pageMask) +# define roundUpToPage(v) (((sqIntptr_t)(v)+pageSize-1)&pageMask) -/************************************************************************/ -/* sqAllocateMemory: Initialize virtual memory */ -/************************************************************************/ -void * -sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) +static char * +minAddressHint() { - char *hint, *address, *alloc; + char *hint; usqIntptr_t alignment; - sqInt allocBytes; SYSTEM_INFO sysInfo; - if (pageSize) { - sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"), - "sqAllocateMemory already called"); - exit(1); - } - /* determine page boundaries & available address space */ - GetSystemInfo(&sysInfo); - pageSize = sysInfo.dwPageSize; - pageMask = ~(pageSize - 1); - minAppAddr = sysInfo.lpMinimumApplicationAddress; - maxAppAddr = sysInfo.lpMaximumApplicationAddress; + if (!pageSize) { + GetSystemInfo(&sysInfo); + pageSize = sysInfo.dwPageSize; + pageMask = ~(pageSize - 1); + minAppAddr = sysInfo.lpMinimumApplicationAddress; + maxAppAddr = sysInfo.lpMaximumApplicationAddress; + } /* choose a suitable starting point. In MinGW the malloc heap is below the * program, so take the max of a malloc and something from uninitialized @@ -71,22 +63,36 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) hint = max(hint,(char *)&fIsConsole); alignment = max(pageSize,1024*1024); - address = (char *)(((usqInt)hint + alignment - 1) & ~(alignment - 1)); + return (char *)(((usqInt)hint + alignment - 1) & ~(alignment - 1)); +} + +/************************************************************************/ +/* sqAllocateMemory: Initialize virtual memory */ +/************************************************************************/ +void * +sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) +{ + char *alloc; + sqInt allocBytes; + +#if !COGVM + if (pageSize) { + sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"), + TEXT("sqAllocateMemory already called")); + exit(1); + } +#endif alloc = sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto - (roundUpToPage(desiredHeapSize), address, &allocBytes); + (desiredHeapSize, minAddressHint(), &allocBytes); if (!alloc) { - exit(errno); sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"), - "sqAllocateMemory: initial alloc failed!\n"); + TEXT("sqAllocateMemory: initial alloc failed!\n")); exit(1); } return alloc; } -#define roundDownToPage(v) ((v)&pageMask) -#define roundUpToPage(v) (((v)+pageSize-1)&pageMask) - /* Allocate a region of memory of at least size bytes, at or above minAddress. * If the attempt fails, answer null. If the attempt succeeds, answer the * start of the region and assign its size through allocatedSizePointer. @@ -115,7 +121,7 @@ address_space_used(char *address, usqInt bytes) return 1; if (!VirtualQuery(address, &info, sizeof(info))) sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"), - "Unable to VirtualQuery range [%p, %p), Error: %u", + TEXT("Unable to VirtualQuery range [%p, %p), Error: %u"), address, (char *)address + bytes, GetLastError()); addressSpaceUnused = info.BaseAddress == address @@ -161,12 +167,12 @@ sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto(sqInt size, void *minAddress DWORD lastError = GetLastError(); #if 0 /* Can't report this without making the system unusable... */ sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"), - "Unable to VirtualAlloc committed memory at desired address (%" PRIuSQINT " bytes requested at %p, above %p), Error: %lu", + TEXT("Unable to VirtualAlloc committed memory at desired address (%") TEXT(PRIuSQINT) TEXT(" bytes requested at %p, above %p), Error: %lu")), bytes, address, minAddress, lastError); #else if (fIsConsole) fprintf(stderr, - "Unable to VirtualAlloc committed memory at desired address (%" PRIuSQINT " bytes requested at %p, above %p), Error: %lu\n", + TEXT("Unable to VirtualAlloc committed memory at desired address (%" PRIuSQINT " bytes requested at %p, above %p), Error: %lu\n"), bytes, address, minAddress, lastError); #endif return 0; @@ -176,7 +182,7 @@ sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto(sqInt size, void *minAddress */ if (alloc && !VirtualFree(alloc, SizeForRelease(bytes), MEM_RELEASE)) sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Warning:"), - "Unable to VirtualFree committed memory (%" PRIuSQINT " bytes requested), Error: %ul", + TEXT("Unable to VirtualFree committed memory (%") TEXT(PRIuSQINT) TEXT(" bytes requested), Error: %ul"), bytes, GetLastError()); address += delta; } @@ -191,7 +197,7 @@ sqDeallocateMemorySegmentAtOfSize(void *addr, sqInt sz) { if (!VirtualFree(addr, SizeForRelease(sz), MEM_RELEASE)) sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Warning:"), - "Unable to VirtualFree committed memory (%" PRIuSQINT " bytes requested), Error: %ul", + TEXT("Unable to VirtualFree committed memory (%") TEXT(PRIuSQINT) TEXT(" bytes requested), Error: %ul"), sz, GetLastError()); } @@ -214,18 +220,20 @@ sqMakeMemoryExecutableFromToCodeToDataDelta(usqInt startAddr, *codeToDataDelta = 0; } -void -sqMakeMemoryNotExecutableFromTo(usqInt startAddr, usqInt endAddr) +void * +allocateJITMemory(usqInt *desiredSize) { - DWORD previous; - SIZE_T size; + sqInt allocBytes; - size = endAddr - startAddr; - if (!VirtualProtect((void *)startAddr, - size, - PAGE_READWRITE, - &previous)) - sqWin32PrintLastError("VirtualProtect(x,y,PAGE_EXECUTE_READWRITE)"); + char *alloc = sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto + (*desiredSize, minAddressHint(), &allocBytes); + + if (!alloc) { + sqWin32PrintLastError("Could not allocate JIT memory"); + exit(1); + } + *desiredSize = allocBytes; + return alloc; } # endif /* COGVM */ diff --git a/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c b/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c index e786c38c67..8792c97f00 100755 --- a/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c +++ b/platforms/win32/plugins/SoundPlugin/sqWin32Sound.c @@ -724,7 +724,7 @@ static sqInt dx_snd_SetRecordLevel(sqInt level) { return 1000.0L * accessMixerVolume(recorderDevices.defaultDevice.mmID, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, level / 1000.0L); } -static int +int snd_GetRecordLevel() { return 1000.0L * accessMixerVolume(recorderDevices.defaultDevice.mmID, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, -1.0); } diff --git a/platforms/win32/vm/sqWin32Alloc.c b/platforms/win32/vm/sqWin32Alloc.c index 93e04ef3f3..2ef7008d24 100644 --- a/platforms/win32/vm/sqWin32Alloc.c +++ b/platforms/win32/vm/sqWin32Alloc.c @@ -44,6 +44,23 @@ LONG CALLBACK sqExceptionFilter(LPEXCEPTION_POINTERS exp) return EXCEPTION_WRONG_ACCESS; } +# define roundDownToPage(v) ((sqIntptr_t)(v)&pageMask) +# define roundUpToPage(v) (((sqIntptr_t)(v)+pageSize-1)&pageMask) + +static void +initPageSize() +{ + SYSTEM_INFO sysInfo; + + /* determine page boundaries & available address space */ + if (!pageSize) { + GetSystemInfo(&sysInfo); + pageSize = sysInfo.dwPageSize; + pageMask = ~(pageSize - 1); + } +} + + /************************************************************************/ /* sqAllocateMemory: Initialize virtual memory */ /************************************************************************/ @@ -52,15 +69,13 @@ void *sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) DWORD initialCommit, commit; /* determine page boundaries */ - GetSystemInfo(&sysInfo); - pageSize = sysInfo.dwPageSize; - pageMask = ~(pageSize - 1); + initPageSize(); /* round the requested size up to the next page boundary */ - nowReserved = (desiredHeapSize + pageSize) & pageMask; + nowReserved = roundUpToPage(desiredHeapSize); /* round the initial commited size up to the next page boundary */ - initialCommit = (minHeapSize + pageSize) & pageMask; + initialCommit = roundUpToPage(minHeapSize); /* Here, we only reserve the maximum memory to be used It will later be committed during actual access */ @@ -171,9 +186,6 @@ int sqMemoryExtraBytesLeft(int includingSwap) { return bytesLeft; } -#define roundDownToPage(v) ((v)&pageMask) -#define roundUpToPage(v) (((v)+pageSize-1)&pageMask) - # if COGVM void sqMakeMemoryExecutableFromToCodeToDataDelta(usqInt startAddr, @@ -181,9 +193,11 @@ sqMakeMemoryExecutableFromToCodeToDataDelta(usqInt startAddr, sqInt *codeToDataDelta) { DWORD previous; + SIZE_T size; + size = endAddr - startAddr; if (!VirtualProtect((void *)startAddr, - endAddr - startAddr + 1, + size, PAGE_EXECUTE_READWRITE, &previous)) perror("VirtualProtect(x,y,PAGE_EXECUTE_READWRITE)"); @@ -194,24 +208,19 @@ sqMakeMemoryExecutableFromToCodeToDataDelta(usqInt startAddr, void * allocateJITMemory(usqInt *desiredSize) { - char *address, *alloc; - usqIntptr_t alignment; - SYSTEM_INFO sysInfo; + initPageSize(); - /* determine page boundaries & available address space */ - GetSystemInfo(&sysInfo); - pageSize = sysInfo.dwPageSize; - pageMask = ~(pageSize - 1); - - alloc = sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto - (roundUpToPage(*desiredSize), - roundUpToPage(address), - desiredSize); + sqInt allocBytes = roundUpToPage(*desiredSize); + /* Allocate extra memory for the JIT. No need to make it executable (i.e., PAGE_EXECUTE_READWRITE) right away because there will be an extra call to sqMakeMemoryExecutableFromToCodeToDataDelta(..) anyway. */ + char *alloc = VirtualAlloc(NULL,allocBytes,MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); + if (!alloc) { perror("Could not allocate JIT memory"); exit(1); } + + *desiredSize = allocBytes; return alloc; } # endif /* COGVM */ diff --git a/platforms/win32/vm/sqWin32SpurAlloc.c b/platforms/win32/vm/sqWin32SpurAlloc.c index 0657f0cc53..71f94f2897 100644 --- a/platforms/win32/vm/sqWin32SpurAlloc.c +++ b/platforms/win32/vm/sqWin32SpurAlloc.c @@ -83,7 +83,7 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize) #endif alloc = sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto - (roundUpToPage(desiredHeapSize), minAddressHint(), &allocBytes); + (desiredHeapSize, minAddressHint(), &allocBytes); if (!alloc) { sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"), TEXT("sqAllocateMemory: initial alloc failed!\n")); @@ -225,7 +225,7 @@ allocateJITMemory(usqInt *desiredSize) sqInt allocBytes; char *alloc = sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto - (roundUpToPage(*desiredSize), minAddressHint(), &allocBytes); + (*desiredSize, minAddressHint(), &allocBytes); if (!alloc) { perror("Could not allocate JIT memory");