egl: Move _eglPointerIsDereferencable() to eglglobals.[ch]
Move _eglPointerIsDereferencable() to eglglobals.[ch] and make it a non-static function so it can be used out of egldisplay.c Signed-off-by: Miguel A. Vico <mvicomoya@nvidia.com> Reviewed-by: James Jones <jajones@nvidia.com> Acked-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
This commit is contained in:

committed by
Emil Velikov

parent
dad0c5d2d7
commit
045108938c
@@ -49,10 +49,6 @@
|
|||||||
#include "eglsync.h"
|
#include "eglsync.h"
|
||||||
|
|
||||||
/* Includes for _eglNativePlatformDetectNativeDisplay */
|
/* Includes for _eglNativePlatformDetectNativeDisplay */
|
||||||
#ifdef HAVE_MINCORE
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_WAYLAND_PLATFORM
|
#ifdef HAVE_WAYLAND_PLATFORM
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -105,35 +101,6 @@ _eglGetNativePlatformFromEnv(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform validity checks on a generic pointer.
|
|
||||||
*/
|
|
||||||
static 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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try detecting native platform with the help of native display characteristcs.
|
* Try detecting native platform with the help of native display characteristcs.
|
||||||
*/
|
*/
|
||||||
|
@@ -37,6 +37,12 @@
|
|||||||
#include "eglglobals.h"
|
#include "eglglobals.h"
|
||||||
#include "egldisplay.h"
|
#include "egldisplay.h"
|
||||||
#include "egldriver.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;
|
static mtx_t _eglGlobalMutex = _MTX_INITIALIZER_NP;
|
||||||
@@ -142,3 +148,28 @@ _eglGetClientExtensionString(void)
|
|||||||
mtx_unlock(_eglGlobal.Mutex);
|
mtx_unlock(_eglGlobal.Mutex);
|
||||||
return ret;
|
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
|
||||||
|
}
|
||||||
|
@@ -87,4 +87,10 @@ static inline unsigned int DebugBitFromType(EGLenum type)
|
|||||||
extern const char *
|
extern const char *
|
||||||
_eglGetClientExtensionString(void);
|
_eglGetClientExtensionString(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform validity checks on a generic pointer.
|
||||||
|
*/
|
||||||
|
extern EGLBoolean
|
||||||
|
_eglPointerIsDereferencable(void *p);
|
||||||
|
|
||||||
#endif /* EGLGLOBALS_INCLUDED */
|
#endif /* EGLGLOBALS_INCLUDED */
|
||||||
|
Reference in New Issue
Block a user