/* emem.h
- * Definitions for ethereal memory management and garbage collection
+ * Definitions for Wireshark memory management and garbage collection
* Ronnie Sahlberg 2005
*
* $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
/* Functions for handling memory allocation and garbage collection with
* a packet lifetime scope.
* These functions are used to allocate memory that will only remain persistent
- * until ethereal starts dissecting the next packet in the list.
- * Everytime ethereal starts decoding the next packet all memory allocated
+ * until Wireshark starts dissecting the next packet in the list.
+ * Everytime Wireshark starts decoding the next packet all memory allocated
* through these functions will be released back to the free pool.
*
* These functions are very fast and offer automatic garbage collection:
* the previous packet is freed.
*/
/* Initialize packet-lifetime memory allocation pool. This function is called
- * once when [t]ethereal is initialized to set up the required structures.
+ * once when [t]Wireshark is initialized to set up the required structures.
*/
void ep_init_chunk(void);
/* Functions for handling memory allocation and garbage collection with
* a capture lifetime scope.
* These functions are used to allocate memory that will only remain persistent
- * until ethereal opens a new capture or capture file.
- * Everytime ethereal starts a new capture or opens a new capture file
+ * until Wireshark opens a new capture or capture file.
+ * Everytime Wireshark starts a new capture or opens a new capture file
* all the data allocated through these functions will be released back
* to the free pool.
*
* These functions are very fast and offer automatic garbage collection.
*/
/* Initialize capture-lifetime memory allocation pool. This function is called
- * once when [t]ethereal is initialized to set up the required structures.
+ * once when [t]Wireshark is initialized to set up the required structures.
*/
void se_init_chunk(void);
/**************************************************************
- * binary trees with SE allocation
+ * binary trees
**************************************************************/
-#define SE_TREE_RB_COLOR_RED 0x00
-#define SE_TREE_RB_COLOR_BLACK 0x01
-typedef struct _se_tree_node_t {
- struct _se_tree_node_t *parent;
- struct _se_tree_node_t *left;
- struct _se_tree_node_t *right;
+#define EMEM_TREE_RB_COLOR_RED 0x00
+#define EMEM_TREE_RB_COLOR_BLACK 0x01
+typedef struct _emem_tree_node_t {
+ struct _emem_tree_node_t *parent;
+ struct _emem_tree_node_t *left;
+ struct _emem_tree_node_t *right;
union {
guint32 rb_color;
- };
+ } u;
guint32 key32;
void *data;
-} se_tree_node_t;
+} emem_tree_node_t;
-/* list of all se trees so they can all be reset automatically when
- * we free all se memory
- */
/* Right now we only do basic red/black trees but in the future we might want
* to try something different, such as a tree where each node keeps track
* of how many times it has been looked up, and letting often looked up
* nodes bubble upwards in the tree using rotate_right/left.
* That would probably be good for things like nfs filehandles
*/
-#define SE_TREE_TYPE_RED_BLACK 1
-typedef struct _se_tree_t {
- struct _se_tree_t *next;
+#define EMEM_TREE_TYPE_RED_BLACK 1
+typedef struct _emem_tree_t {
+ struct _emem_tree_t *next;
int type;
char *name; /* just a string to make debugging easier */
- se_tree_node_t *tree;
-} se_tree_t;
-extern se_tree_t *se_trees;
+ emem_tree_node_t *tree;
+ void *(*malloc)(size_t);
+} emem_tree_t;
+
+/* list of all trees with se allocation scope so that they can all be reset
+ * automatically when we free all se memory
+ */
+extern emem_tree_t *se_trees;
+/* *******************************************************************
+ * Tree functions for SE memory allocation scope
+ * ******************************************************************* */
/* This function is used to create a se based tree with monitoring.
* When the SE heap is released back to the system the pointer to the
* tree is automatically reset to NULL.
*
- * type is : SE_TREE_TYPE_RED_BLACK for a standard red/black tree.
- */
-se_tree_t *se_tree_create(int type, char *name);
-
-/* This function is used to insert a node indexed by a guint32 key value.
- * The data pointer should be allocated by SE allocators so that the
- * data will be released at the same time as the tree itself is destroyed.
+ * type is : EMEM_TREE_TYPE_RED_BLACK for a standard red/black tree.
*/
-void se_tree_insert32(se_tree_t *se_tree, guint32 key, void *data);
-
-/* This function will look up a node in the tree indexed by a guint32 integer
- * value.
- */
-void *se_tree_lookup32(se_tree_t *se_tree, guint32 key);
-
+emem_tree_t *se_tree_create(int type, char *name);
/* This function is similar to the se_tree_create() call but with the
* difference that when the se memory is release everything including the
* another structure that is also se allocated so that when the structure is
* released, the tree will be completely released as well.
*/
-se_tree_t *se_tree_create_non_persistent(int type, char *name);
+emem_tree_t *se_tree_create_non_persistent(int type, char *name);
+
+/* se_tree_insert32
+ * Insert data into the tree and key it by a 32bit integer value
+ */
+#define se_tree_insert32 emem_tree_insert32
+
+/* se_tree_lookup32
+ * Retreive the data at the search key. the search key is a 32bit integer value
+ */
+#define se_tree_lookup32 emem_tree_lookup32
+
+/* se_tree_lookup32_le
+ * Retreive the data for the largest key that is less than or equal
+ * to the search key.
+ */
+#define se_tree_lookup32_le emem_tree_lookup32_le
+
+/* se_tree_insert32_array
+ * Insert data into the tree and key it by a 32bit integer value
+ */
+#define se_tree_insert32_array emem_tree_insert32_array
+
+/* se_tree_lookup32_array
+ * Lookup data from the tree that is index by an array
+ */
+#define se_tree_lookup32_array emem_tree_lookup32_array
+
+
+
+/* Create a new string based hash table */
+#define se_tree_create_string() se_tree_create(SE_TREE_TYPE_RED_BLACK)
+
+/* Insert a new value under a string key */
+#define se_tree_insert_string emem_tree_insert_string
+
+/* Lookup the value under a string key */
+#define se_tree_lookup_string emem_tree_lookup_string
+
+
+/* *******************************************************************
+ * Tree functions for PE memory allocation scope
+ * ******************************************************************* */
+/* These trees have PErmanent allocation scope and will never be released
+ */
+emem_tree_t *pe_tree_create(int type, char *name);
+#define pe_tree_insert32 emem_tree_insert32
+#define pe_tree_lookup32 emem_tree_lookup32
+#define pe_tree_lookup32_le emem_tree_lookup32_le
+#define pe_tree_insert32_array emem_tree_insert32_array
+#define pe_tree_lookup32_array emem_tree_lookup32_array
+#define pe_tree_insert_string emem_tree_insert_string
+#define pe_tree_lookup_string emem_tree_lookup_string
+
+
+
+/* ******************************************************************
+ * Real tree functions
+ * ****************************************************************** */
+
+/* This function is used to insert a node indexed by a guint32 key value.
+ * The data pointer should be allocated by the appropriate storage scope
+ * so that it will be released at the same time as the tree itself is
+ * destroyed.
+ */
+void emem_tree_insert32(emem_tree_t *se_tree, guint32 key, void *data);
+
+/* This function will look up a node in the tree indexed by a guint32 integer
+ * value.
+ */
+void *emem_tree_lookup32(emem_tree_t *se_tree, guint32 key);
-typedef struct _se_tree_key_t {
+/* This function will look up a node in the tree indexed by a guint32 integer
+ * value.
+ * The function will return the node that has the largest key that is
+ * equal to or smaller than the search key, or NULL if no such key was
+ * found.
+ */
+void *emem_tree_lookup32_le(emem_tree_t *se_tree, guint32 key);
+
+typedef struct _emem_tree_key_t {
guint32 length; /*length in guint32 words */
guint32 *key;
-} se_tree_key_t;
+} emem_tree_key_t;
/* This function is used to insert a node indexed by a sequence of guint32
* key values.
* The NFS dissector handles this by providing a guint32 containing the length
* as the very first item in this vector :
*
- * se_tree_key_t fhkey[3];
+ * emem_tree_key_t fhkey[3];
*
* fhlen=nns->fh_length;
* fhkey[0].length=1;
* fhkey[1].key=nns->fh;
* fhkey[2].length=0;
*/
-void se_tree_insert32_array(se_tree_t *se_tree, se_tree_key_t *key, void *data);
+void emem_tree_insert32_array(emem_tree_t *se_tree, emem_tree_key_t *key, void *data);
/* This function will look up a node in the tree indexed by a sequence of
* guint32 integer values.
*/
-void *se_tree_lookup32_array(se_tree_t *se_tree, se_tree_key_t *key);
-
-/*
- * A hash table with string keys based on the red/black tree
- */
-typedef struct _se_tree_t se_string_hash_t;
-
-/* Create a new string based hash table */
-#define se_tree_create_string() se_tree_create(SE_TREE_TYPE_RED_BLACK)
+void *emem_tree_lookup32_array(emem_tree_t *se_tree, emem_tree_key_t *key);
/* Insert a new value under a string key */
-void se_tree_insert_string(se_string_hash_t* h, const gchar* k, void* v);
+void emem_tree_insert_string(emem_tree_t* h, const gchar* k, void* v);
/* Lookup the value under a string key */
-void* se_tree_lookup_string(se_string_hash_t* h, const gchar* k);
+void* emem_tree_lookup_string(emem_tree_t* h, const gchar* k);
+
+
+
+
+
+
+
#endif /* emem.h */