i965: Validate API and version in brwCreateContext
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 7 Aug 2012 19:43:17 +0000 (12:43 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 14 Aug 2012 00:38:55 +0000 (17:38 -0700)
v2: Use base-10 for versions like gl_context::Version.  Suggested by Ken.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/intel/intel_screen.c

index a5711e4a58dfa15e32e96d4605e0595bb973c0a7..e72d5b6710f19ea60aebe1d9a3932327feee7009 100644 (file)
@@ -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))
+         ? 30 : 21;
+#else
+      const unsigned max_version = 21;
+#endif
+      const unsigned req_version = major_version * 10 + 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;
    }
 
index 51dfcca4827fd4639f0869528eea0c3cbde2006c..15ef0a35d4f89e9efe3d87ccb5554b675fec06c7 100644 (file)
@@ -1099,6 +1099,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);
 
 /*======================================================================
index 737cc49b16bcc056048989572187324302695ce6..034499bf801b3112031306d3efa0da3237b1192a 100644 (file)
@@ -701,6 +701,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
@@ -764,8 +767,9 @@ intelCreateContext(gl_api api,
    }
 #else
    success = brwCreateContext(api, mesaVis,
-                             driContextPriv,
-                             sharedContextPrivate);
+                              driContextPriv,
+                              major_version, minor_version, error,
+                              sharedContextPrivate);
 #endif
 
    if (success) {