Re: [Mesa-dev] [PATCH v2 1/5] util/hash_table: Fix hashing in clears on 32-bit

2019-08-07 Thread Caio Marcelo de Oliveira Filho
On Wed, Aug 07, 2019 at 10:36:53AM +0200, Tomeu Vizoso wrote:
> Some hash functions (eg. key_u64_hash) will attempt to dereference the
> key, causing an invalid access when passed DELETED_KEY_VALUE (0x1) or
> FREED_KEY_VALUE (0x0).
> 
> To avoid this problem, stuff the fake keys into a hash_key_u64 struct
> and pass the pointer to it instead.

A more precise description would be something along the lines

   When in 32-bit arch a 64-bit key value doesn't fit into a pointer,
   so hash_table_u64 internally use a pointer to a struct containing
   the 64-bit key value.

   Fix _mesa_hash_table_u64_clear() to handle the 32-bit case by
   creating a temporary hash_key_u64 to pass to the hash function.


This patch is

   Reviewed-by: Caio Marcelo de Oliveira Filho 


Caio
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

[Mesa-dev] [PATCH v2 1/5] util/hash_table: Fix hashing in clears on 32-bit

2019-08-07 Thread Tomeu Vizoso
Some hash functions (eg. key_u64_hash) will attempt to dereference the
key, causing an invalid access when passed DELETED_KEY_VALUE (0x1) or
FREED_KEY_VALUE (0x0).

To avoid this problem, stuff the fake keys into a hash_key_u64 struct
and pass the pointer to it instead.

Signed-off-by: Tomeu Vizoso 
Suggested-by: Caio Marcelo de Oliveira Filho 
Cc: Samuel Pitoiset 
Cc: Nicolai Hähnle 
---
 src/util/hash_table.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/util/hash_table.c b/src/util/hash_table.c
index f58575de558f..58e6fc2d9169 100644
--- a/src/util/hash_table.c
+++ b/src/util/hash_table.c
@@ -667,7 +667,12 @@ _mesa_hash_table_u64_clear(struct hash_table_u64 *ht,
  struct hash_entry entry;
 
  /* Create a fake entry for the delete function. */
- entry.hash = table->key_hash_function(table->deleted_key);
+ if (sizeof(void *) == 8) {
+entry.hash = table->key_hash_function(table->deleted_key);
+ } else {
+struct hash_key_u64 _key = { .value = 
(uintptr_t)table->deleted_key };
+entry.hash = table->key_hash_function(&_key);
+ }
  entry.key = table->deleted_key;
  entry.data = ht->deleted_key_data;
 
@@ -682,7 +687,12 @@ _mesa_hash_table_u64_clear(struct hash_table_u64 *ht,
  struct hash_entry entry;
 
  /* Create a fake entry for the delete function. */
- entry.hash = table->key_hash_function(uint_key(FREED_KEY_VALUE));
+ if (sizeof(void *) == 8) {
+entry.hash = table->key_hash_function(uint_key(FREED_KEY_VALUE));
+ } else {
+struct hash_key_u64 _key = { .value = (uintptr_t)FREED_KEY_VALUE };
+entry.hash = table->key_hash_function(&_key);
+ }
  entry.key = uint_key(FREED_KEY_VALUE);
  entry.data = ht->freed_key_data;
 
-- 
2.20.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev