Module: Mesa
Branch: staging/20.0
Commit: 1a6ce0f9afe39a6783ca70119479d442bcc6597d
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=1a6ce0f9afe39a6783ca70119479d442bcc6597d

Author: Rhys Perry <[email protected]>
Date:   Thu Mar 26 15:49:05 2020 +0000

glsl: fix race in instance getters

Insertions can modify entry->data. Seems to fix random Fossilize crashes.

Signed-off-by: Rhys Perry <[email protected]>
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Reviewed-by: Eric Engestrom <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
CC: <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4335>
(cherry picked from commit d101ca3f5ad85731cedbe7ab399d4323cca1aac6)

---

 .pick_status.json           |  2 +-
 src/compiler/glsl_types.cpp | 20 +++++++++++++++-----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index cd1b23455f1..f8331cf10d5 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -697,7 +697,7 @@
         "description": "glsl: fix race in instance getters",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": null
     },
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 79e2f684fcf..96dc5313b1c 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -663,9 +663,11 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, 
unsigned columns,
       assert(((glsl_type *) entry->data)->matrix_columns == columns);
       assert(((glsl_type *) entry->data)->explicit_stride == explicit_stride);
 
+      const glsl_type *t = (const glsl_type *) entry->data;
+
       mtx_unlock(&glsl_type::hash_mutex);
 
-      return (const glsl_type *) entry->data;
+      return t;
    }
 
    assert(!row_major);
@@ -1024,9 +1026,11 @@ glsl_type::get_array_instance(const glsl_type *base,
    assert(((glsl_type *) entry->data)->length == array_size);
    assert(((glsl_type *) entry->data)->fields.array == base);
 
+   glsl_type *t = (glsl_type *) entry->data;
+
    mtx_unlock(&glsl_type::hash_mutex);
 
-   return (glsl_type *) entry->data;
+   return t;
 }
 
 bool
@@ -1225,9 +1229,11 @@ glsl_type::get_struct_instance(const glsl_struct_field 
*fields,
    assert(strcmp(((glsl_type *) entry->data)->name, name) == 0);
    assert(((glsl_type *) entry->data)->packed == packed);
 
+   glsl_type *t = (glsl_type *) entry->data;
+
    mtx_unlock(&glsl_type::hash_mutex);
 
-   return (glsl_type *) entry->data;
+   return t;
 }
 
 
@@ -1261,9 +1267,11 @@ glsl_type::get_interface_instance(const 
glsl_struct_field *fields,
    assert(((glsl_type *) entry->data)->length == num_fields);
    assert(strcmp(((glsl_type *) entry->data)->name, block_name) == 0);
 
+   glsl_type *t = (glsl_type *) entry->data;
+
    mtx_unlock(&glsl_type::hash_mutex);
 
-   return (glsl_type *) entry->data;
+   return t;
 }
 
 const glsl_type *
@@ -1290,9 +1298,11 @@ glsl_type::get_subroutine_instance(const char 
*subroutine_name)
    assert(((glsl_type *) entry->data)->base_type == GLSL_TYPE_SUBROUTINE);
    assert(strcmp(((glsl_type *) entry->data)->name, subroutine_name) == 0);
 
+   glsl_type *t = (glsl_type *) entry->data;
+
    mtx_unlock(&glsl_type::hash_mutex);
 
-   return (glsl_type *) entry->data;
+   return t;
 }
 
 

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to