[Mesa-dev] [PATCH 11/14] i965: Validate API and version in brwCreateContext
Ian Romanick
idr at freedesktop.org
Wed Aug 8 10:38:19 PDT 2012
From: Ian Romanick <ian.d.romanick at intel.com>
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/mesa/drivers/dri/i965/brw_context.c | 40 ++++++++++++++++++++++++++--
src/mesa/drivers/dri/i965/brw_context.h | 3 ++
src/mesa/drivers/dri/intel/intel_screen.c | 8 ++++-
3 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index a5711e4..013ec14 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -75,27 +75,61 @@ bool
brwCreateContext(int api,
const struct gl_config *mesaVis,
__DRIcontext *driContextPriv,
+ unsigned major_version,
+ unsigned minor_version,
+ unsigned *error,
void *sharedContextPrivate)
{
__DRIscreen *sPriv = driContextPriv->driScreenPriv;
struct intel_screen *screen = sPriv->driverPrivate;
struct dd_function_table functions;
- struct brw_context *brw = rzalloc(NULL, struct brw_context);
- struct intel_context *intel = &brw->intel;
- struct gl_context *ctx = &intel->ctx;
unsigned i;
+ /* Filter against the requested API and version.
+ */
+ switch (api) {
+ case API_OPENGL: {
+#ifdef TEXTURE_FLOAT_ENABLED
+ const unsigned max_version =
+ (screen->gen == 6 ||
+ (screen->gen == 7 && screen->kernel_has_gen7_sol_reset))
+ ? 0x300 : 0x201;
+#else
+ const unsigned max_version = 0x201;
+#endif
+ const unsigned req_version = (major_version << 8) | minor_version;
+
+ if (req_version > max_version) {
+ *error = __DRI_CTX_ERROR_BAD_VERSION;
+ return false;
+ }
+ break;
+ }
+ case API_OPENGLES:
+ case API_OPENGLES2:
+ break;
+ default:
+ *error = __DRI_CTX_ERROR_BAD_API;
+ return false;
+ }
+
+ struct brw_context *brw = rzalloc(NULL, struct brw_context);
if (!brw) {
printf("%s: failed to alloc context\n", __FUNCTION__);
+ *error = __DRI_CTX_ERROR_NO_MEMORY;
return false;
}
brwInitDriverFunctions(screen, &functions);
+ struct intel_context *intel = &brw->intel;
+ struct gl_context *ctx = &intel->ctx;
+
if (!intelInitContext( intel, api, mesaVis, driContextPriv,
sharedContextPrivate, &functions )) {
printf("%s: failed to init intel context\n", __FUNCTION__);
FREE(brw);
+ *error = __DRI_CTX_ERROR_NO_MEMORY;
return false;
}
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 1548f81..77d88ea 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1097,6 +1097,9 @@ void brwInitVtbl( struct brw_context *brw );
bool brwCreateContext(int api,
const struct gl_config *mesaVis,
__DRIcontext *driContextPriv,
+ unsigned major_version,
+ unsigned minor_version,
+ unsigned *error,
void *sharedContextPrivate);
/*======================================================================
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index bc8c265..26b3732 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -688,6 +688,9 @@ extern bool
brwCreateContext(int api,
const struct gl_config *mesaVis,
__DRIcontext *driContextPriv,
+ unsigned major_version,
+ unsigned minor_version,
+ unsigned *error,
void *sharedContextPrivate);
static GLboolean
@@ -751,8 +754,9 @@ intelCreateContext(gl_api api,
}
#else
success = brwCreateContext(api, mesaVis,
- driContextPriv,
- sharedContextPrivate);
+ driContextPriv,
+ major_version, minor_version, error,
+ sharedContextPrivate);
#endif
if (success) {
--
1.7.6.5
More information about the mesa-dev
mailing list