summaryrefslogtreecommitdiffstats
path: root/src/egl/main/eglglobals.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/egl/main/eglglobals.c')
-rw-r--r--src/egl/main/eglglobals.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
index baf96bb1ec5..6fdc6c31ce3 100644
--- a/src/egl/main/eglglobals.c
+++ b/src/egl/main/eglglobals.c
@@ -37,6 +37,12 @@
#include "eglglobals.h"
#include "egldisplay.h"
#include "egldriver.h"
+#include "egllog.h"
+
+#ifdef HAVE_MINCORE
+#include <unistd.h>
+#include <sys/mman.h>
+#endif
static mtx_t _eglGlobalMutex = _MTX_INITIALIZER_NP;
@@ -142,3 +148,28 @@ _eglGetClientExtensionString(void)
mtx_unlock(_eglGlobal.Mutex);
return ret;
}
+
+EGLBoolean
+_eglPointerIsDereferencable(void *p)
+{
+#ifdef HAVE_MINCORE
+ uintptr_t addr = (uintptr_t) p;
+ unsigned char valid = 0;
+ const long page_size = getpagesize();
+
+ if (p == NULL)
+ return EGL_FALSE;
+
+ /* align addr to page_size */
+ addr &= ~(page_size - 1);
+
+ if (mincore((void *) addr, page_size, &valid) < 0) {
+ _eglLog(_EGL_DEBUG, "mincore failed: %m");
+ return EGL_FALSE;
+ }
+
+ return (valid & 0x01) == 0x01;
+#else
+ return p != NULL;
+#endif
+}