summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/hash.h
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-06-04 22:27:49 +0200
committerDave Barach <openvpp@barachs.net>2018-06-05 14:30:01 +0000
commit73710c7da2f8deaea83dbbbfce8737c9c6cd2949 (patch)
tree7d9cc75fe38de525a5b78634317e94b83880534a /src/vppinfra/hash.h
parent0b061112f73fda45084671120411a6484d9c11d2 (diff)
VPP API: Memory trace
if you plan to put a hash into shared memory, the key sum and key equal functions MUST be set to constants such as KEY_FUNC_STRING, KEY_FUNC_MEM, etc. -lvppinfra is PIC, which means that the process which set up the hash won't have the same idea where the key sum and key compare functions live in other processes. Change-Id: Ib3b5963a0d2fb467b91e1f16274df66ac74009e9 Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Dave Barach <dave@barachs.net> Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vppinfra/hash.h')
-rw-r--r--src/vppinfra/hash.h15
1 files changed, 15 insertions, 0 deletions
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, \