+
+const char *
+_eglGetClientExtensionString(void)
+{
+ const char *ret;
+
+ mtx_lock(_eglGlobal.Mutex);
+
+ if (_eglGlobal.ClientExtensionString == NULL) {
+ size_t clientLen = strlen(_eglGlobal.ClientOnlyExtensionString);
+ size_t platformLen = strlen(_eglGlobal.PlatformExtensionString);
+
+ _eglGlobal.ClientExtensionString = (char *) malloc(clientLen + platformLen + 1);
+ if (_eglGlobal.ClientExtensionString != NULL) {
+ char *ptr = _eglGlobal.ClientExtensionString;
+
+ memcpy(ptr, _eglGlobal.ClientOnlyExtensionString, clientLen);
+ ptr += clientLen;
+
+ if (platformLen > 0) {
+ // Note that if PlatformExtensionString is not empty, then it will
+ // already have a leading space.
+ assert(_eglGlobal.PlatformExtensionString[0] == ' ');
+ memcpy(ptr, _eglGlobal.PlatformExtensionString, platformLen);
+ ptr += platformLen;
+ }
+ *ptr = '\0';
+ }
+ }
+ ret = _eglGlobal.ClientExtensionString;
+
+ mtx_unlock(_eglGlobal.Mutex);
+ return ret;
+}
+
+EGLBoolean
+_eglPointerIsDereferencable(void *p)
+{
+ uintptr_t addr = (uintptr_t) p;
+ const long page_size = getpagesize();
+#ifdef HAVE_MINCORE
+ unsigned char valid = 0;
+
+ if (p == NULL)
+ return EGL_FALSE;
+
+ /* align addr to page_size */
+ addr &= ~(page_size - 1);
+
+ if (mincore((void *) addr, page_size, &valid) < 0) {
+ return EGL_FALSE;
+ }
+
+ /* mincore() returns 0 on success, and -1 on failure. The last parameter
+ * is a vector of bytes with one entry for each page queried. mincore
+ * returns page residency information in the first bit of each byte in the
+ * vector.
+ *
+ * Residency doesn't actually matter when determining whether a pointer is
+ * dereferenceable, so the output vector can be ignored. What matters is
+ * whether mincore succeeds. See:
+ *
+ * http://man7.org/linux/man-pages/man2/mincore.2.html
+ */
+ return EGL_TRUE;
+#else
+ // Without mincore(), we just assume that the first page is unmapped.
+ return addr >= page_size;
+#endif
+}