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

Chris Lattner lattner at cs.uiuc.edu
Thu Mar 10 11:28:24 PST 2005



Changes in directory llvm-poolalloc/include/poolalloc:

MMAPSupport.h added (r1.1)
---
Log message:

initial implementation of this header to abstract stuff out of the runtime
libs.


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

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


Index: llvm-poolalloc/include/poolalloc/MMAPSupport.h
diff -c /dev/null llvm-poolalloc/include/poolalloc/MMAPSupport.h:1.1
*** /dev/null	Thu Mar 10 13:28:18 2005
--- llvm-poolalloc/include/poolalloc/MMAPSupport.h	Thu Mar 10 13:28:08 2005
***************
*** 0 ****
--- 1,58 ----
+ //===- 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.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ /// FIXME: This isn't installed, add copies of the configure checks to the pool
+ /// allocator project configure script.
+ #include "llvm/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