From 1b5f9207a649a64a1bba20b0283253425f9208d7 Mon Sep 17 00:00:00 2001 From: Francesco Mazzoli Date: Fri, 9 Sep 2016 18:15:49 +0100 Subject: Make start address of `osReserveHeapMemory` tunable via command line -xb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: We stumbled upon a case where an external library (OpenCL) does not work if a specific address (0x200000000) is taken. It so happens that `osReserveHeapMemory` starts trying to mmap at 0x200000000: ``` void *hint = (void*)((W_)8 * (1 << 30) + attempt * BLOCK_SIZE); at = osTryReserveHeapMemory(*len, hint); ``` This makes it impossible to use Haskell programs compiled with GHC 8 with C functions that use OpenCL. See this example ​https://github.com/chpatrick/oclwtf for a repro. This patch allows the user to work around this kind of behavior outside our control by letting the user override the starting address through an RTS command line flag. Reviewers: bgamari, Phyx, simonmar, erikd, austin Reviewed By: Phyx, simonmar Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D2513 --- rts/win32/OSMem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'rts/win32') diff --git a/rts/win32/OSMem.c b/rts/win32/OSMem.c index 3450267d9c..3d9a304fda 100644 --- a/rts/win32/OSMem.c +++ b/rts/win32/OSMem.c @@ -430,19 +430,20 @@ void setExecutable (void *p, W_ len, rtsBool exec) static void* heap_base = NULL; -void *osReserveHeapMemory (W_ *len) +void *osReserveHeapMemory (void *startAddress, W_ *len) { void *start; - heap_base = VirtualAlloc(NULL, *len + MBLOCK_SIZE, + heap_base = VirtualAlloc(startAddress, *len + MBLOCK_SIZE, MEM_RESERVE, PAGE_READWRITE); if (heap_base == NULL) { if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) { errorBelch("out of memory"); } else { sysErrorBelch( - "osReserveHeapMemory: VirtualAlloc MEM_RESERVE %llu bytes failed", - len + MBLOCK_SIZE); + "osReserveHeapMemory: VirtualAlloc MEM_RESERVE %llu bytes \ + at address %p bytes failed", + len + MBLOCK_SIZE, startAddress); } stg_exit(EXIT_FAILURE); } -- cgit v1.2.1