summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/hash.c8
-rw-r--r--src/vppinfra/hash.h15
-rw-r--r--src/vppinfra/mheap.c2
-rw-r--r--src/vppinfra/test_macros.c5
4 files changed, 27 insertions, 3 deletions
diff --git a/src/vppinfra/hash.c b/src/vppinfra/hash.c
index 79103b6d3f4..abc7c4ce4a2 100644
--- a/src/vppinfra/hash.c
+++ b/src/vppinfra/hash.c
@@ -282,6 +282,10 @@ key_sum (hash_t * h, uword key)
sum = string_key_sum (h, key);
break;
+ case KEY_FUNC_MEM:
+ sum = mem_key_sum (h, key);
+ break;
+
default:
sum = h->key_sum (h, key);
break;
@@ -312,6 +316,10 @@ key_equal1 (hash_t * h, uword key1, uword key2, uword e)
e = string_key_equal (h, key1, key2);
break;
+ case KEY_FUNC_MEM:
+ e = mem_key_equal (h, key1, key2);
+ break;
+
default:
e = h->key_equal (h, key1, key2);
break;
diff --git a/src/vppinfra/hash.h b/src/vppinfra/hash.h
index 21986ea774c..de155e6ac1c 100644
--- a/src/vppinfra/hash.h
+++ b/src/vppinfra/hash.h
@@ -77,6 +77,7 @@ typedef struct hash_header
#define KEY_FUNC_POINTER_UWORD (1) /*< sum = *(uword *) key */
#define KEY_FUNC_POINTER_U32 (2) /*< sum = *(u32 *) key */
#define KEY_FUNC_STRING (3) /*< sum = string_key_sum, etc. */
+#define KEY_FUNC_MEM (4) /*< sum = mem_key_sum */
/* key comparison function */
hash_key_equal_function_t *key_equal;
@@ -672,6 +673,20 @@ extern uword string_key_sum (hash_t * h, uword key);
extern uword string_key_equal (hash_t * h, uword key1, uword key2);
extern u8 *string_key_format_pair (u8 * s, va_list * args);
+/*
+ * Note: if you plan to put a hash into shared memory,
+ * the key sum and key equal functions MUST be set to magic constants!
+ * PIC means that whichever process sets up the hash won't have
+ * the actual key sum functions at the same place, leading to
+ * very hard-to-find bugs...
+ */
+
+#define hash_create_shmem(elts,key_bytes,value_bytes) \
+ hash_create2((elts),(key_bytes),(value_bytes), \
+ (hash_key_sum_function_t *) KEY_FUNC_MEM, \
+ (hash_key_equal_function_t *)KEY_FUNC_MEM, \
+ 0, 0)
+
#define hash_create_string(elts,value_bytes) \
hash_create2((elts),0,(value_bytes), \
(hash_key_sum_function_t *) KEY_FUNC_STRING, \
diff --git a/src/vppinfra/mheap.c b/src/vppinfra/mheap.c
index 4d27d419e64..fceca95ff7d 100644
--- a/src/vppinfra/mheap.c
+++ b/src/vppinfra/mheap.c
@@ -1512,7 +1512,7 @@ mheap_get_trace (void *v, uword offset, uword size)
if (!tm->trace_by_callers)
tm->trace_by_callers =
- hash_create_mem (0, sizeof (trace.callers), sizeof (uword));
+ hash_create_shmem (0, sizeof (trace.callers), sizeof (uword));
p = hash_get_mem (tm->trace_by_callers, &trace.callers);
if (p)
diff --git a/src/vppinfra/test_macros.c b/src/vppinfra/test_macros.c
index de8f2c49fc1..05299b38e3f 100644
--- a/src/vppinfra/test_macros.c
+++ b/src/vppinfra/test_macros.c
@@ -26,13 +26,14 @@ test_macros_main (unformat_input_t * input)
clib_macro_init (mm);
fformat (stdout, "hostname: %s\n",
- clib_macro_eval_dollar (mm, "hostname", 1 /* complain */ ));
+ clib_macro_eval_dollar (mm, (i8 *) "hostname", 1 /* complain */ ));
clib_macro_set_value (mm, "foo", "this is foo which contains $(bar)");
clib_macro_set_value (mm, "bar", "bar");
fformat (stdout, "evaluate: %s\n",
- clib_macro_eval (mm, "returns '$(foo)'", 1 /* complain */ ));
+ clib_macro_eval (mm, (i8 *) "returns '$(foo)'",
+ 1 /* complain */ ));
clib_macro_free (mm);