diff --git a/src/cgmemmgr.cpp b/src/cgmemmgr.cpp index 8684178ab02a6..6931ee0a7f76c 100644 --- a/src/cgmemmgr.cpp +++ b/src/cgmemmgr.cpp @@ -62,7 +62,8 @@ static void unmap_page(void *ptr, size_t size) enum class Prot : int { RW = PAGE_READWRITE, RX = PAGE_EXECUTE, - RO = PAGE_READONLY + RO = PAGE_READONLY, + NO = PAGE_NOACCESS }; static void protect_page(void *ptr, size_t size, Prot flags) @@ -79,7 +80,8 @@ static void protect_page(void *ptr, size_t size, Prot flags) enum class Prot : int { RW = PROT_READ | PROT_WRITE, RX = PROT_READ | PROT_EXEC, - RO = PROT_READ + RO = PROT_READ, + NO = PROT_NONE }; static void protect_page(void *ptr, size_t size, Prot flags) @@ -623,7 +625,7 @@ class DualMapAllocator : public ROAllocator { unmap_page((void*)block.wr_ptr, block.total); } else { - protect_page((void*)block.wr_ptr, block.total, Prot::RO); + protect_page((void*)block.wr_ptr, block.total, Prot::NO); block.state = SplitPtrBlock::WRInit; } } diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index de44454794fde..4f6aa1dd8d9b1 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -131,6 +131,8 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam tbl->BeginAddress = (DWORD)(Code - Section); tbl->EndAddress = (DWORD)(Code - Section + Size); tbl->UnwindData = (DWORD)(UnwindData - Section); + assert(Code >= Section && Code + Size <= Section + Allocated); + assert(UnwindData >= Section && UnwindData <= Section + Allocated); #else // defined(_CPU_X86_64_) Section += (uintptr_t)Code; mod_size = Size; @@ -321,24 +323,18 @@ class JuliaJITEventListener: public JITEventListener uint8_t *catchjmp = NULL; for (const object::SymbolRef &sym_iter : debugObj.symbols()) { StringRef sName = cantFail(sym_iter.getName()); - uint8_t **pAddr = NULL; - if (sName.equals("__UnwindData")) { - pAddr = &UnwindData; - } - else if (sName.equals("__catchjmp")) { - pAddr = &catchjmp; - } - if (pAddr) { + if (sName.equals("__UnwindData") || sName.equals("__catchjmp")) { uint64_t Addr = cantFail(sym_iter.getAddress()); auto Section = cantFail(sym_iter.getSection()); assert(Section != EndSection && Section->isText()); uint64_t SectionAddr = Section->getAddress(); #if JL_LLVM_VERSION >= 100000 - sName = cantFail(Section->getName()); + StringRef secName = cantFail(Section->getName()); #else - Section->getName(sName); + StringRef secName; + Section->getName(secName); #endif - uint64_t SectionLoadAddr = getLoadAddress(sName); + uint64_t SectionLoadAddr = getLoadAddress(secName); assert(SectionLoadAddr); if (SectionAddrCheck) // assert that all of the Sections are at the same location assert(SectionAddrCheck == SectionAddr && @@ -350,7 +346,12 @@ class JuliaJITEventListener: public JITEventListener SectionWriteCheck = (uintptr_t)lookupWriteAddressFor(memmgr, (void*)SectionLoadAddr); Addr += SectionWriteCheck - SectionLoadAddr; - *pAddr = (uint8_t*)Addr; + if (sName.equals("__UnwindData")) { + UnwindData = (uint8_t*)Addr; + } + else if (sName.equals("__catchjmp")) { + catchjmp = (uint8_t*)Addr; + } } } assert(catchjmp); @@ -373,6 +374,7 @@ class JuliaJITEventListener: public JITEventListener UnwindData[6] = 1; // first instruction UnwindData[7] = 0x50; // push RBP *(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - (uint8_t*)SectionWriteCheck); // relative location of catchjmp + UnwindData -= SectionWriteCheck - SectionLoadCheck; #endif // defined(_OS_X86_64_) #endif // defined(_OS_WINDOWS_)