Mesa (master): util: Add os_get_page_size query

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 2 18:52:48 UTC 2020


Module: Mesa
Branch: master
Commit: cdf3a6a83b5013dad78a3d95817cd772a146ca40
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cdf3a6a83b5013dad78a3d95817cd772a146ca40

Author: Jesse Natalie <jenatali at microsoft.com>
Date:   Wed Nov 18 18:15:22 2020 -0800

util: Add os_get_page_size query

No Apple/BSD implementation yet, I have no idea how to do that

Reviewed-by: Francisco Jerez <currojerez at riseup.net>
Reviewed-by: Karol Herbst <kherbst at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7680>

---

 src/util/os_misc.c | 31 +++++++++++++++++++++++++++++++
 src/util/os_misc.h |  6 ++++++
 2 files changed, 37 insertions(+)

diff --git a/src/util/os_misc.c b/src/util/os_misc.c
index 7eb6ba48a7e..79a8b6b8850 100644
--- a/src/util/os_misc.c
+++ b/src/util/os_misc.c
@@ -322,3 +322,34 @@ os_get_available_system_memory(uint64_t *size)
    return false;
 #endif
 }
+
+/**
+ * Return the size of a page
+ * \param size returns the size of a page
+ * \return true for success, or false on failure
+ */
+bool
+os_get_page_size(uint64_t *size)
+{
+#if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || DETECT_OS_HURD
+   const long page_size = sysconf(_SC_PAGE_SIZE);
+
+   if (page_size <= 0)
+      return false;
+
+   *size = (uint64_t)page_size;
+   return true;
+#elif DETECT_OS_HAIKU
+   *size = (uint64_t)B_PAGE_SIZE;
+   return true;
+#elif DETECT_OS_WINDOWS
+   SYSTEM_INFO SysInfo;
+
+   GetSystemInfo(&SysInfo);
+   *size = SysInfo.dwPageSize;
+   return true;
+#else
+#error unexpected platform in os_sysinfo.c
+   return false;
+#endif
+}
diff --git a/src/util/os_misc.h b/src/util/os_misc.h
index ef474c6ee0b..432bfe1abf5 100644
--- a/src/util/os_misc.h
+++ b/src/util/os_misc.h
@@ -101,6 +101,12 @@ os_get_total_physical_memory(uint64_t *size);
 bool
 os_get_available_system_memory(uint64_t *size);
 
+/*
+ * Size of a page
+ */
+bool
+os_get_page_size(uint64_t *size);
+
 
 #ifdef	__cplusplus
 }



More information about the mesa-commit mailing list