LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pagesize.h

Go to the documentation of this file.
00001 /* 
00002  *                     The LLVM Compiler Infrastructure
00003  *
00004  * This file was developed by the LLVM research group and is distributed under
00005  * the University of Illinois Open Source License. See LICENSE.TXT for details.
00006  * 
00007  ******************************************************************************
00008  *
00009  * This header file provides a platform-independent way of quering page size.
00010  */
00011 
00012 #ifndef PAGESIZE_H
00013 #define PAGESIZE_H
00014 
00015 #include "llvm/Config/unistd.h"
00016 #include <sys/param.h>
00017 
00018 namespace llvm {
00019 
00020 /* Compatibility chart:
00021  *
00022  * Linux/x86:        _SC_PAGESIZE, _SC_PAGE_SIZE
00023  * MacOS X/PowerPC:  v. 10.2: NBPG, 
00024  *                   v. 10.3: _SC_PAGESIZE
00025  * Solaris/Sparc:    _SC_PAGESIZE, _SC_PAGE_SIZE
00026  */
00027 
00028 /**
00029  * GetPageSize - wrapper to return page size in bytes for various 
00030  *  architecture/OS combinations
00031  */ 
00032 unsigned GetPageSize() {
00033 #ifdef _SC_PAGESIZE
00034   return sysconf(_SC_PAGESIZE);
00035 #elif defined(_SC_PAGE_SIZE)
00036   return sysconf(_SC_PAGE_SIZE);
00037 #elif defined(NBPG)
00038 #ifndef CLSIZE
00039 #define CLSIZE 1
00040 #endif
00041   return NBPG * CLSIZE;
00042 #else
00043   return 4096; /* allocate 4KB as a fall-back */
00044 #endif
00045 }
00046 
00047 }
00048 
00049 #endif