util: Add os_get_page_size query
authorJesse Natalie <jenatali@microsoft.com>
Thu, 19 Nov 2020 02:15:22 +0000 (18:15 -0800)
committerJesse Natalie <jenatali@microsoft.com>
Wed, 2 Dec 2020 18:12:27 +0000 (10:12 -0800)
No Apple/BSD implementation yet, I have no idea how to do that

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

src/util/os_misc.c
src/util/os_misc.h

index 7eb6ba48a7ee17fa75d0550caf3a752b121e1ea4..79a8b6b8850de80260419d2833abc6c9c2174489 100644 (file)
@@ -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
+}
index ef474c6ee0bab8695c0e2ba55f087f1205ba428c..432bfe1abf552a463a998e4e953b5dfc08595ca0 100644 (file)
@@ -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
 }