llvm.org GIT mirror llvm / 19cfd73
Revert r48676. I had plans for using it, but now it's just dead code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48743 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
3 changed file(s) with 0 addition(s) and 83 deletion(s). Raw diff Collapse all Expand all
5656 const MemoryBlock *NearBlock,
5757 std::string *ErrMsg = 0);
5858
59 /// This method allocates a block of Read/Write memory. This memory
60 /// needs to have executable permissions set before it can be used
61 /// to execute JIT'ed code.
62 ///
63 /// On success, this returns a non-null memory block, otherwise it returns
64 /// a null memory block and fills in *ErrMsg.
65 ///
66 /// @brief Allocate Read/Write/Execute memory.
67 static MemoryBlock AllocateRW(unsigned NumBytes,
68 const MemoryBlock *NearBlock,
69 std::string *ErrMsg = 0);
70
7159 /// This method releases a block of Read/Write/Execute memory that was
7260 /// allocated with the AllocateRWX method. It should not be used to
7361 /// release any memory block allocated any other way.
7765 /// @throws std::string if an error occurred.
7866 /// @brief Release Read/Write/Execute memory.
7967 static bool ReleaseRWX(MemoryBlock &block, std::string *ErrMsg = 0);
80
8168 /// @}
8269 };
8370 }
6666 return result;
6767 }
6868
69 /// AllocateRWMemory - Allocate a slab of memory with read/write permissions.
70 /// This memory needs to have executable permissions set before it can be used
71 /// to execute JIT'ed code.
72 llvm::sys::MemoryBlock
73 llvm::sys::Memory::AllocateRW(unsigned NumBytes, const MemoryBlock* NearBlock,
74 std::string *ErrMsg) {
75 if (NumBytes == 0) return MemoryBlock();
76
77 long pageSize = Process::GetPageSize();
78 unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
79
80 int fd = -1;
81 #ifdef NEED_DEV_ZERO_FOR_MMAP
82 static int zero_fd = open("/dev/zero", O_RDWR);
83 if (zero_fd == -1) {
84 MakeErrMsg(ErrMsg, "Can't open /dev/zero device");
85 return MemoryBlock();
86 }
87 fd = zero_fd;
88 #endif
89
90 int flags = MAP_PRIVATE |
91 #ifdef HAVE_MMAP_ANONYMOUS
92 MAP_ANONYMOUS
93 #else
94 MAP_ANON
95 #endif
96 ;
97
98 void* start = NearBlock ? (unsigned char*)NearBlock->base() +
99 NearBlock->size() : 0;
100
101 void *pa = ::mmap(start, pageSize*NumPages, PROT_READ|PROT_WRITE,
102 flags, fd, 0);
103 if (pa == MAP_FAILED) {
104 if (NearBlock) //Try again without a near hint
105 return AllocateRW(NumBytes, 0);
106
107 MakeErrMsg(ErrMsg, "Can't allocate RWX Memory");
108 return MemoryBlock();
109 }
110 MemoryBlock result;
111 result.Address = pa;
112 result.Size = NumPages*pageSize;
113 return result;
114 }
115
11669 bool llvm::sys::Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
11770 if (M.Address == 0 || M.Size == 0) return false;
11871 if (0 != ::munmap(M.Address, M.Size))
4545 return result;
4646 }
4747
48 MemoryBlock Memory::AllocateRW(unsigned NumBytes,
49 const MemoryBlock *NearBlock,
50 std::string *ErrMsg) {
51 if (NumBytes == 0) return MemoryBlock();
52
53 static const long pageSize = Process::GetPageSize();
54 unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
55
56 //FIXME: support NearBlock if ever needed on Win64.
57
58 void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT,
59 PAGE_READWRITE);
60 if (pa == NULL) {
61 MakeErrMsg(ErrMsg, "Can't allocate RWX Memory: ");
62 return MemoryBlock();
63 }
64
65 MemoryBlock result;
66 result.Address = pa;
67 result.Size = NumPages*pageSize;
68 return result;
69 }
70
7148 bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
7249 if (M.Address == 0 || M.Size == 0) return false;
7350 if (!VirtualFree(M.Address, 0, MEM_RELEASE))