pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
llvm-netbsd: Update patch for RWX allocation
Module Name: pkgsrc-wip
Committed By: Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By: kamil
Date: Wed Jun 7 03:27:22 2017 +0200
Changeset: 15516e17a602083978a18172fc19d509bed04834
Modified Files:
llvm-netbsd/distinfo
llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc
Added Files:
llvm-netbsd/patches/patch-include_llvm_Support_Memory.h
Log Message:
llvm-netbsd: Update patch for RWX allocation
Alter for notes from review.
Sponsored by <The NetBSD Foundation>
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=15516e17a602083978a18172fc19d509bed04834
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
llvm-netbsd/distinfo | 3 +-
.../patches/patch-include_llvm_Support_Memory.h | 25 +++++++
.../patches/patch-lib_Support_Unix_Memory.inc | 78 +++++++++-------------
3 files changed, 57 insertions(+), 49 deletions(-)
diffs:
diff --git a/llvm-netbsd/distinfo b/llvm-netbsd/distinfo
index 356e680034..bd1d620645 100644
--- a/llvm-netbsd/distinfo
+++ b/llvm-netbsd/distinfo
@@ -13,4 +13,5 @@ SHA1 (llvm-3.6.2.src.tar.xz) = 7a00257eb2bc9431e4c77c3a36b033072c54bc7e
RMD160 (llvm-3.6.2.src.tar.xz) = 521cbc5fe2925ea3c6e90c7a31f752a04045c972
Size (llvm-3.6.2.src.tar.xz) = 12802380 bytes
SHA1 (patch-include_llvm_ADT_Triple.h) = be08dde07a038259a3314ec7791d2ccf8a682c0c
-SHA1 (patch-lib_Support_Unix_Memory.inc) = fa0fe0137a1c6b6a143f1b15a5a6f5ef53edfe1c
+SHA1 (patch-include_llvm_Support_Memory.h) = 8828c30722635d2db04f886383d3ce910adb88a0
+SHA1 (patch-lib_Support_Unix_Memory.inc) = 2c9a1359c8af2b0a7c329dddf64f7feef465919c
diff --git a/llvm-netbsd/patches/patch-include_llvm_Support_Memory.h b/llvm-netbsd/patches/patch-include_llvm_Support_Memory.h
new file mode 100644
index 0000000000..e9229e52ef
--- /dev/null
+++ b/llvm-netbsd/patches/patch-include_llvm_Support_Memory.h
@@ -0,0 +1,25 @@
+$NetBSD$
+
+--- include/llvm/Support/Memory.h.orig 2016-12-16 22:50:53.000000000 +0000
++++ include/llvm/Support/Memory.h
+@@ -28,14 +28,16 @@ namespace sys {
+ /// @brief Memory block abstraction.
+ class MemoryBlock {
+ public:
+- MemoryBlock() : Address(nullptr), Size(0) { }
+- MemoryBlock(void *addr, size_t size) : Address(addr), Size(size) { }
++ MemoryBlock() : Address(nullptr), SecondaryAddress(nullptr), Size(0) { }
++ MemoryBlock(void *addr, size_t size)
++ : Address(addr), SecondaryAddress(nullptr), Size(size) {}
+ void *base() const { return Address; }
+ size_t size() const { return Size; }
+
+ private:
+- void *Address; ///< Address of first byte of memory area
+- size_t Size; ///< Size, in bytes of the memory area
++ void *Address; ///< Address of first byte of memory area
++ void *SecondaryAddress; ///< Secondary address of first byte of memory area
++ size_t Size; ///< Size, in bytes of the memory area
+ friend class Memory;
+ };
+
diff --git a/llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc b/llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc
index 3604b1b7fd..2e9b9add54 100644
--- a/llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc
+++ b/llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc
@@ -2,44 +2,35 @@ $NetBSD$
--- lib/Support/Unix/Memory.inc.orig 2016-12-16 22:52:53.000000000 +0000
+++ lib/Support/Unix/Memory.inc
-@@ -177,7 +177,16 @@ Memory::AllocateRWX(size_t NumBytes, con
- if (NumBytes == 0) return MemoryBlock();
-
- static const size_t PageSize = Process::getPageSize();
-- size_t NumPages = (NumBytes+PageSize-1)/PageSize;
-+
-+ static const size_t overhead =
-+#if __NetBSD_Version__ - 0 >= 799007200
-+ sizeof(void*)
-+#else
-+ 0
-+#endif
-+ ;
-+
-+ size_t NumPages = (NumBytes + overhead + PageSize - 1) / PageSize;
-
- int fd = -1;
-
-@@ -195,6 +204,10 @@ Memory::AllocateRWX(size_t NumBytes, con
+@@ -195,14 +195,14 @@ Memory::AllocateRWX(size_t NumBytes, con
#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_EXEC,
flags, fd, 0);
-+#elif __NetBSD_Version__ - 0 >= 799007200
+-#else
+- void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+- flags, fd, 0);
++#elif defined(__NetBSD__) && defined(PROT_MPROTECT)
+ void *pa =
+ ::mmap(start, PageSize * NumPages,
+ PROT_READ | PROT_WRITE | PROT_MPROTECT(PROT_EXEC), flags, fd, 0);
- #else
- void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
- flags, fd, 0);
-@@ -223,19 +236,51 @@ Memory::AllocateRWX(size_t NumBytes, con
+ #endif
+ if (pa == MAP_FAILED) {
+ if (NearBlock) //Try again without a near hint
+ return AllocateRWX(NumBytes, nullptr);
+-
+ MakeErrMsg(ErrMsg, "Can't allocate RWX Memory");
+ return MemoryBlock();
+ }
+@@ -223,10 +223,35 @@ Memory::AllocateRWX(size_t NumBytes, con
MakeErrMsg(ErrMsg, "vm_protect RW failed");
return MemoryBlock();
}
-+#elif __NetBSD_Version__ - 0 >= 799007200
++#elif defined(__NetBSD__) && defined(PROT_MPROTECT)
+ void *codeseg =
-+ mremap(pa, PageSize * NumPages, NULL, PageSize * NumPages, MAP_REMAPDUP);
++ ::mremap(pa, PageSize * NumPages, NULL, PageSize * NumPages,
++ MAP_REMAPDUP);
+ if (codeseg == MAP_FAILED) {
-+ munmap(pa, PageSize * NumPages);
++ ::munmap(pa, PageSize * NumPages);
+
+ if (NearBlock) // Try again without a near hint
+ return AllocateRWX(NumBytes, nullptr);
@@ -47,41 +38,32 @@ $NetBSD$
+ MakeErrMsg(ErrMsg, "Can't allocate RWX Memory");
+ return MemoryBlock();
+ }
-+ if (mprotect(codeseg, PageSize * NumPages, PROT_READ | PROT_EXEC) == -1) {
-+ munmap(pa, PageSize * NumPages);
-+ munmap(codeseg, PageSize * NumPages);
++ if (::mprotect(codeseg, PageSize * NumPages, PROT_READ | PROT_EXEC) == -1) {
++ ::munmap(pa, PageSize * NumPages);
++ ::munmap(codeseg, PageSize * NumPages);
+ if (NearBlock) // Try again without a near hint
+ return AllocateRWX(NumBytes, nullptr);
+
+ MakeErrMsg(ErrMsg, "Can't allocate RWX Memory");
+ return MemoryBlock();
+ }
-+ // Rembember code segment pointer, to be able to free it later
-+ memcpy(pa, &codeseg, sizeof(void *));
#endif
MemoryBlock result;
-- result.Address = pa;
-- result.Size = NumPages*PageSize;
-+ result.Address = (void *)((uintptr_t)pa + overhead);
-+ result.Size = NumPages*PageSize - overhead;
+ result.Address = pa;
++#if defined(__NetBSD__) && defined(PROT_MPROTECT)
++ result.SecondaryAddress = codeseg;
++#endif
+ result.Size = NumPages*PageSize;
return result;
- }
-
- bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
+@@ -236,6 +261,9 @@ bool Memory::ReleaseRWX(MemoryBlock &M,
if (M.Address == nullptr || M.Size == 0) return false;
-+#if __NetBSD_Version__ - 0 >= 799007200
-+ static const size_t overhead = sizeof(void *);
-+ void *codeseg;
-+ memcpy(&codeseg, (void *)((uintptr_t)M.Address - overhead), sizeof(void *));
-+ if (0 != ::munmap(codeseg, M.Size + overhead) ||
-+ 0 != ::munmap(M.Address, M.Size + overhead))
-+ return MakeErrMsg(ErrMsg, "Can't release RWX Memory");
-+#else
if (0 != ::munmap(M.Address, M.Size))
return MakeErrMsg(ErrMsg, "Can't release RWX Memory");
-+#endif
++ if (M.SecondaryAddress)
++ if (0 != ::munmap(M.SecondaryAddress, M.Size))
++ return MakeErrMsg(ErrMsg, "Can't release RWX Memory");
return false;
}
Home |
Main Index |
Thread Index |
Old Index