summaryrefslogtreecommitdiff
path: root/include/llvm/Config/pagesize.h
blob: f37b29770d42ee70f325416e7951a9ddfaa5366d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* 
 *                     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 header file provides a platform-independent way of quering page size.
 */

#ifndef PAGESIZE_H
#define PAGESIZE_H

#include "Config/unistd.h"
#include <sys/param.h>

namespace llvm {

/* Compatibility chart:
 *
 * Linux/x86:        _SC_PAGESIZE, _SC_PAGE_SIZE
 * MacOS X/PowerPC:  v. 10.2: NBPG, 
 *                   v. 10.3: _SC_PAGESIZE
 * Solaris/Sparc:    _SC_PAGESIZE, _SC_PAGE_SIZE
 */

/**
 * GetPageSize - wrapper to return page size in bytes for various 
 *  architecture/OS combinations
 */ 
unsigned GetPageSize() {
#ifdef _SC_PAGESIZE
  return sysconf(_SC_PAGESIZE);
#elif defined(_SC_PAGE_SIZE)
  return sysconf(_SC_PAGE_SIZE);
#elif defined(NBPG)
#ifndef CLSIZE
#define CLSIZE 1
#endif
  return NBPG * CLSIZE;
#else
  return 4096; /* allocate 4KB as a fall-back */
#endif
}

}

#endif