blob: dc8f2d1c47559c93c6b310959a4c250231dadd05 [file] [log] [blame]
Reid Spencercbad7012004-09-11 04:59:30 +00001//===- AIX/Memory.cpp - AIX Memory Implementation ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Reid Spencer and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides the AIX specific implementation of various Memory
11// management utilities
12//
13//===----------------------------------------------------------------------===//
14
15// Include the generic unix implementation
16#include "../Unix/Memory.cpp"
17#include "llvm/System/Process.h"
18#include <sys/types.h>
19#include <sys/mman.h>
20
21namespace llvm {
22using namespace sys;
23
24//===----------------------------------------------------------------------===//
25//=== WARNING: Implementation here must contain only AIX specific code
26//=== and must not be generic UNIX code (see ../Unix/Memory.cpp)
27//===----------------------------------------------------------------------===//
28
Reid Spencer33189e72004-09-13 22:38:11 +000029MemoryBlock Memory::AllocateRWX(unsigned NumBytes) {
30 if (NumBytes == 0) return MemoryBlock();
Reid Spencercbad7012004-09-11 04:59:30 +000031
32 static const long pageSize = Process::GetPageSize();
33 unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
34
35 void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
36 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
37 if (pa == (void*)-1) {
38 throw std::string("Can't allocate RWX Memory: ") + strerror(errno);
39 }
Reid Spencer33189e72004-09-13 22:38:11 +000040 MemoryBlock result;
41 result.Address = pa;
42 result.Size = NumPages*pageSize;
43 return result;
Reid Spencercbad7012004-09-11 04:59:30 +000044}
45
Reid Spencer33189e72004-09-13 22:38:11 +000046void Memory::ReleaseRWX(MemoryBlock& M) {
47 if (M.Address == 0 || M.Size == 0) return;
48 if (0 != munmap(M.Address, M.Size)) {
Reid Spencer71447072004-09-11 20:18:08 +000049 throw std::string("Can't release RWX Memory: ") + strerror(errno);
Reid Spencercbad7012004-09-11 04:59:30 +000050 }
51}
52
53}
54
55// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab