[llvm-commits] CVS: llvm-poolalloc/include/poolalloc/MMAPSupport.h

John Criswell criswell at cs.uiuc.edu
Wed May 18 12:57:03 PDT 2005



Changes in directory llvm-poolalloc/include/poolalloc:

MMAPSupport.h updated: 1.3 -> 1.4
---
Log message:

Bring all of these files back from the "release_15" merge.




---
Diffs of the changes:  (+56 -0)

 MMAPSupport.h |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+)


Index: llvm-poolalloc/include/poolalloc/MMAPSupport.h
diff -u /dev/null llvm-poolalloc/include/poolalloc/MMAPSupport.h:1.4
--- /dev/null	Wed May 18 14:57:03 2005
+++ llvm-poolalloc/include/poolalloc/MMAPSupport.h	Wed May 18 14:56:22 2005
@@ -0,0 +1,56 @@
+//===- MMAPSupport.h - mmap portability wrappers ----------------*- C++ -*-===//
+// 
+//                       The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file allows clients to use some functionality of mmap efficiently and
+// portably.  This is used for the pool allocator runtime implementations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "poolalloc/Config/config.h"
+#include <cstdlib>
+#include <cassert>
+
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#ifdef HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
+#define MAP_ANONYMOUS MAP_ANON
+#endif /* defined(MAP_ANON) && !defined(MAP_ANONYMOUS) */
+
+static void *AllocateSpaceWithMMAP(size_t Size, bool UseNoReserve = false) {
+  // NOTE: this assumes Size is a multiple of the page size.
+  int FD = -1;
+#ifdef NEED_DEV_ZERO_FOR_MMAP
+  static int DevZeroFD = open("/dev/zero", O_RDWR);
+  if (DevZeroFD == -1) {
+    perror("Can't open /dev/zero device");
+    abort();
+  }
+  FD = zero_fd;
+#endif
+
+  int Flags = MAP_PRIVATE | MAP_ANONYMOUS;
+#ifdef MMAP_NORESERVE
+  if (UseNoReserve)
+    Flags |= MMAP_NORESERVE;
+#endif
+
+  void *Mem = ::mmap(0, Size, PROT_READ|PROT_WRITE, Flags, FD, 0);
+  assert(Mem != MAP_FAILED && "couldn't get space!");
+  return Mem;
+}






More information about the llvm-commits mailing list