Skip to content

Commit

Permalink
win64-debug: relax 32-bit reservation requirement
Browse files Browse the repository at this point in the history
I've been encountering this assertion consistently now on recent versions of Windows 10, so make it non-fatal as it is not essential.
  • Loading branch information
vtjnash authored and JeffBezanson committed Jul 28, 2018
1 parent 8e65833 commit 505f719
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions ui/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,9 @@ int main(int argc, char *argv[])
uv_setup_args(argc, argv); // no-op on Windows
#else

#if defined(_P64) && defined(JL_DEBUG_BUILD)
static int is_running_under_wine()
{
static const char * (CDECL *pwine_get_version)(void);
HMODULE hntdll = GetModuleHandle("ntdll.dll");
assert(hntdll);
pwine_get_version = (void *)GetProcAddress(hntdll, "wine_get_version");
return pwine_get_version != 0;
}
#endif

static void lock_low32() {
#if defined(_P64) && defined(JL_DEBUG_BUILD)
// Wine currently has a that causes it to answer VirtualQuery incorrectly.
// See https://www.winehq.org/pipermail/wine-devel/2016-March/112188.html for details
int under_wine = is_running_under_wine();
// block usage of the 32-bit address space on win64, to catch pointer cast errors
char *const max32addr = (char*)0xffffffffL;
SYSTEM_INFO info;
Expand All @@ -198,16 +185,19 @@ static void lock_low32() {
if (meminfo.State == MEM_FREE) { // reserve all free pages in the first 4GB of memory
char *first = (char*)meminfo.BaseAddress;
char *last = first + meminfo.RegionSize;
char *p;
if (last > max32addr)
last = max32addr;
// adjust first up to the first allocation granularity boundary
// adjust last down to the last allocation granularity boundary
first = (char*)(((long long)first + info.dwAllocationGranularity - 1) & ~(info.dwAllocationGranularity - 1));
last = (char*)((long long)last & ~(info.dwAllocationGranularity - 1));
if (last != first) {
p = VirtualAlloc(first, last - first, MEM_RESERVE, PAGE_NOACCESS); // reserve all memory in between
assert(under_wine || p == first);
void *p = VirtualAlloc(first, last - first, MEM_RESERVE, PAGE_NOACCESS); // reserve all memory in between
if ((char*)p != first)
// Wine and Windows10 seem to have issues with reporting memory access information correctly
// so we sometimes end up with unexpected results - this is just ignore those and continue
// this is just a debugging aid to help find accidental pointer truncation anyways, so it's not critical
VirtualFree(p, 0, MEM_RELEASE);
}
}
meminfo.BaseAddress += meminfo.RegionSize;
Expand Down

0 comments on commit 505f719

Please sign in to comment.