summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2004-06-18 15:30:25 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2004-06-18 15:30:25 +0000
commit0ed24ad96875969749d653b3cfc8154ae3046c74 (patch)
treecb97e465d5301e64f20aa610f98c08270c9d2c4a
parent9d2427c07437a4ad473ff79a4746e08b9e4b87b3 (diff)
downloadllvm-0ed24ad96875969749d653b3cfc8154ae3046c74.tar.gz
llvm-0ed24ad96875969749d653b3cfc8154ae3046c74.tar.bz2
llvm-0ed24ad96875969749d653b3cfc8154ae3046c74.tar.xz
Add a target-independent way to query page size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14232 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/Config/pagesize.h49
-rw-r--r--include/llvm/Config/pagesize.h49
2 files changed, 98 insertions, 0 deletions
diff --git a/include/Config/pagesize.h b/include/Config/pagesize.h
new file mode 100644
index 0000000000..638ece0328
--- /dev/null
+++ b/include/Config/pagesize.h
@@ -0,0 +1,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:
+ *
+ * x86/Linux: _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
diff --git a/include/llvm/Config/pagesize.h b/include/llvm/Config/pagesize.h
new file mode 100644
index 0000000000..638ece0328
--- /dev/null
+++ b/include/llvm/Config/pagesize.h
@@ -0,0 +1,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:
+ *
+ * x86/Linux: _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