summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/SunOS/Memory.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-09-11 04:59:30 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-09-11 04:59:30 +0000
commit566ac28f359d5fced04ec491cf67508715719984 (patch)
treeca3bff6d249def5e26f06cad8b9d2824d12beea2 /llvm/lib/System/SunOS/Memory.cpp
parent2896c95bca59cf2ca53fc532a8c6ab8a7d5e4752 (diff)
downloadbcm5719-llvm-566ac28f359d5fced04ec491cf67508715719984.tar.gz
bcm5719-llvm-566ac28f359d5fced04ec491cf67508715719984.zip
Provide initial implementations of Memory and Process concepts for various
platforms. Implement GetLLVMSuffix function for the Path concept. llvm-svn: 16292
Diffstat (limited to 'llvm/lib/System/SunOS/Memory.cpp')
-rw-r--r--llvm/lib/System/SunOS/Memory.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/llvm/lib/System/SunOS/Memory.cpp b/llvm/lib/System/SunOS/Memory.cpp
new file mode 100644
index 00000000000..dd15f13495b
--- /dev/null
+++ b/llvm/lib/System/SunOS/Memory.cpp
@@ -0,0 +1,54 @@
+//===- SunOS/Memory.cpp - SunOS Memory Implementation -----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides the SunOS specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic unix implementation
+#include "../Unix/Memory.cpp"
+#include "llvm/System/Process.h"
+#include <sys/types.h>
+#include <sys/mman.h>
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only SunOS specific code
+//=== and must not be generic UNIX code (see ../Unix/Memory.cpp)
+//===----------------------------------------------------------------------===//
+
+void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) {
+ if (NumBytes == 0) return 0;
+
+ static const long pageSize = Process::GetPageSize();
+ unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+
+ void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+ MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ if (pa == (void*)-1) {
+ throw std::string("Can't allocate RWX Memory: ") + strerror(errno);
+ }
+ M.Address = pa;
+ M.AllocSize = NumPages*pageSize;
+ return pa;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+ if (M.Address == 0 || M.AllocSize == 0) return;
+ if (0 != munmap(M.Address, M.AllocSize)) {
+ throw std::string("Can't release RWX Memory: ") + sterror(errno);
+ }
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
OpenPOWER on IntegriCloud