On platforms without mincore(), _eglPointerIsDereferencable()
currently just checks whether p != NULL. This is not sufficient:
In the Wayland platform code (i.e., in get_wl_surface_proxy()),
_eglPointerIsDereferencable() is called on the version field
of `struct wl_egl_window` which is 3 on current versions of
Wayland. This causes a segfault when trying to dereference p.
Fix this behavior by assuming that the first page of the
process is never dereferencable.
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3103>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3103>
EGLBoolean
_eglPointerIsDereferencable(void *p)
{
-#ifdef HAVE_MINCORE
uintptr_t addr = (uintptr_t) p;
- unsigned char valid = 0;
const long page_size = getpagesize();
+#ifdef HAVE_MINCORE
+ unsigned char valid = 0;
if (p == NULL)
return EGL_FALSE;
*/
return EGL_TRUE;
#else
- return p != NULL;
+ // Without mincore(), we just assume that the first page is unmapped.
+ return addr >= page_size;
#endif
}