Skip to content

Commit

Permalink
Bug 1841250 - Always skip first code page on Windows 64-bit platforms…
Browse files Browse the repository at this point in the history
…. r=iain, a=RyanVM

On Win64 platforms (`NEED_JIT_UNWIND_HANDLING`), we reserve an extra page in
`ReserveProcessExecutableMemory` for the generated exception handler.

Before this patch we'd skip the first page if we generated an exception handler there.
If we didn't generate an exception handler (for example JS shell builds on ARM64)
we'd not skip the first page and instead have an unused page at the end of the JIT
code region.

With this patch we always skip the first page if we reserved one. This fixes an
assertion failure in `UnregisterJitCodeRegion` for Windows ARM64 JS shell builds
because the size didn't match what we passed to `RegisterJitCodeRegion`.

Differential Revision: https://phabricator.services.mozilla.com/D182726
  • Loading branch information
jandem committed Jul 5, 2023
1 parent abff4e8 commit 6ce8996
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions js/src/jit/ProcessExecutableMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,6 @@ static void* ReserveProcessExecutableMemory(size_t bytes) {

# ifdef NEED_JIT_UNWIND_HANDLING
if (RegisterExecutableMemory(p, bytes, pageSize)) {
// If this returns false the page remained unused.
p = (uint8_t*)p + pageSize;
bytes -= pageSize;
sHasInstalledFunctionTable = true;
} else {
if (sJitExceptionHandler) {
Expand All @@ -364,6 +361,11 @@ static void* ReserveProcessExecutableMemory(size_t bytes) {
}
}

// Skip the first page where we might have allocated an exception handler
// record.
p = (uint8_t*)p + pageSize;
bytes -= pageSize;

RegisterJitCodeRegion((uint8_t*)p, bytes);
# endif
return p;
Expand All @@ -373,9 +375,10 @@ static void DeallocateProcessExecutableMemory(void* addr, size_t bytes) {
# ifdef NEED_JIT_UNWIND_HANDLING
UnregisterJitCodeRegion((uint8_t*)addr, bytes);

size_t pageSize = gc::SystemPageSize();
addr = (uint8_t*)addr - pageSize;

if (sHasInstalledFunctionTable) {
size_t pageSize = gc::SystemPageSize();
addr = (uint8_t*)addr - pageSize;
UnregisterExecutableMemory(addr, bytes, pageSize);
}
# endif
Expand Down

0 comments on commit 6ce8996

Please sign in to comment.