radeon,r200: use align_calloc for the context to fix m32 crashes
authorMarek Olšák <marek.olsak@amd.com>
Tue, 23 Feb 2021 15:44:36 +0000 (10:44 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 25 Feb 2021 02:33:12 +0000 (02:33 +0000)
Fixes: 3175b63a0dfa290 "mesa: don't allocate matrices with malloc"

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9220>

src/mesa/drivers/dri/r200/r200_context.c
src/mesa/drivers/dri/radeon/radeon_common_context.c
src/mesa/drivers/dri/radeon/radeon_context.c

index efcf986..e804451 100644 (file)
@@ -66,6 +66,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "utils.h"
 #include "util/driconf.h" /* for symbolic values of enum-type options */
+#include "util/u_memory.h"
 
 /* Return various strings for glGetString().
  */
@@ -200,7 +201,7 @@ GLboolean r200CreateContext( gl_api api,
    assert(screen);
 
    /* Allocate the R200 context */
-   rmesa = calloc(1, sizeof(*rmesa));
+   rmesa = align_calloc(sizeof(*rmesa), 16);
    if ( !rmesa ) {
       *error = __DRI_CTX_ERROR_NO_MEMORY;
       return GL_FALSE;
@@ -238,7 +239,7 @@ GLboolean r200CreateContext( gl_api api,
    if (!radeonInitContext(&rmesa->radeon, api, &functions,
                          glVisual, driContextPriv,
                          sharedContextPrivate)) {
-     free(rmesa);
+     align_free(rmesa);
      *error = __DRI_CTX_ERROR_NO_MEMORY;
      return GL_FALSE;
    }
index 622b38e..fbe8b8e 100644 (file)
@@ -45,6 +45,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
 #include "tnl/tnl.h"
+#include "util/u_memory.h"
 
 #ifndef RADEON_DEBUG
 int RADEON_DEBUG = (0);
@@ -286,7 +287,7 @@ void radeonDestroyContext(__DRIcontext *driContextPriv )
                fclose(track);
        }
 #endif
-       free(radeon);
+       align_free(radeon);
 }
 
 /* Force the context `c' to be unbound from its buffer.
index 3c80963..497a566 100644 (file)
@@ -67,6 +67,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "utils.h"
 #include "util/driconf.h" /* for symbolic values of enum-type options */
+#include "util/u_memory.h"
 
 extern const struct tnl_pipeline_stage _radeon_render_stage;
 extern const struct tnl_pipeline_stage _radeon_tcl_stage;
@@ -165,7 +166,7 @@ r100CreateContext( gl_api api,
    assert(screen);
 
    /* Allocate the Radeon context */
-   rmesa = calloc(1, sizeof(*rmesa));
+   rmesa = align_calloc(sizeof(*rmesa), 16);
    if ( !rmesa ) {
       *error = __DRI_CTX_ERROR_NO_MEMORY;
       return GL_FALSE;
@@ -200,7 +201,7 @@ r100CreateContext( gl_api api,
    if (!radeonInitContext(&rmesa->radeon, api, &functions,
                          glVisual, driContextPriv,
                          sharedContextPrivate)) {
-     free(rmesa);
+     align_free(rmesa);
      *error = __DRI_CTX_ERROR_NO_MEMORY;
      return GL_FALSE;
    }