2005-07-22 07:46:58 +00:00
|
|
|
/* emem.h
|
2006-05-28 19:49:07 +00:00
|
|
|
* Definitions for Wireshark memory management and garbage collection
|
2005-07-22 07:46:58 +00:00
|
|
|
* Ronnie Sahlberg 2005
|
|
|
|
*
|
2005-07-22 17:55:47 +00:00
|
|
|
* $Id$
|
2005-07-22 07:46:58 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-07-22 07:46:58 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-07-22 07:46:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __EMEM_H__
|
|
|
|
#define __EMEM_H__
|
|
|
|
|
2013-03-28 21:19:58 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
#include "ws_symbol_export.h"
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Initialize all the memory allocation pools described below.
|
2009-10-20 17:43:05 +00:00
|
|
|
* This function must be called once when *shark initialize to set up the
|
|
|
|
* required structures.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2009-10-20 17:43:05 +00:00
|
|
|
void emem_init(void);
|
|
|
|
|
2009-09-20 09:28:55 +00:00
|
|
|
/* Functions for handling memory allocation and garbage collection with
|
2005-07-22 07:46:58 +00:00
|
|
|
* a packet lifetime scope.
|
|
|
|
* These functions are used to allocate memory that will only remain persistent
|
2006-05-28 19:49:07 +00:00
|
|
|
* until Wireshark starts dissecting the next packet in the list.
|
|
|
|
* Everytime Wireshark starts decoding the next packet all memory allocated
|
2005-07-22 07:46:58 +00:00
|
|
|
* through these functions will be released back to the free pool.
|
|
|
|
*
|
|
|
|
* These functions are very fast and offer automatic garbage collection:
|
|
|
|
* Everytime a new packet is dissected, all memory allocations done in
|
|
|
|
* the previous packet is freed.
|
|
|
|
*/
|
2005-07-24 00:29:57 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Allocate memory with a packet lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
void *ep_alloc(size_t size) G_GNUC_MALLOC;
|
2005-10-01 10:36:57 +00:00
|
|
|
#define ep_new(type) ((type*)ep_alloc(sizeof(type)))
|
2005-07-24 00:29:57 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Allocate memory with a packet lifetime scope and fill it with zeros*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
void* ep_alloc0(size_t size) G_GNUC_MALLOC;
|
2005-10-01 10:36:57 +00:00
|
|
|
#define ep_new0(type) ((type*)ep_alloc0(sizeof(type)))
|
2005-07-26 18:32:12 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Duplicate a string with a packet lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
gchar* ep_strdup(const gchar* src) G_GNUC_MALLOC;
|
2005-07-24 00:29:57 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Duplicate at most n characters of a string with a packet lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
gchar* ep_strndup(const gchar* src, size_t len) G_GNUC_MALLOC;
|
2005-07-24 00:29:57 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Duplicate a buffer with a packet lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
void* ep_memdup(const void* src, size_t len) G_GNUC_MALLOC;
|
2005-07-24 00:29:57 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Create a formatted string with a packet lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
gchar* ep_strdup_vprintf(const gchar* fmt, va_list ap) G_GNUC_MALLOC;
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2005-09-15 08:54:56 +00:00
|
|
|
gchar* ep_strdup_printf(const gchar* fmt, ...)
|
2010-01-25 13:20:53 +00:00
|
|
|
G_GNUC_MALLOC G_GNUC_PRINTF(1, 2);
|
2005-07-24 00:29:57 +00:00
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2011-03-26 02:39:04 +00:00
|
|
|
gchar *ep_strconcat(const gchar *string, ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** allocates with a packet lifetime scope an array of type made of num elements */
|
2005-07-26 18:32:12 +00:00
|
|
|
#define ep_alloc_array(type,num) (type*)ep_alloc(sizeof(type)*(num))
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** allocates with a packet lifetime scope an array of type made of num elements,
|
2007-03-26 20:17:05 +00:00
|
|
|
* initialised to zero.
|
|
|
|
*/
|
|
|
|
#define ep_alloc_array0(type,num) (type*)ep_alloc0(sizeof(type)*(num))
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/**
|
2005-07-26 18:32:12 +00:00
|
|
|
* Splits a string into a maximum of max_tokens pieces, using the given
|
|
|
|
* delimiter. If max_tokens is reached, the remainder of string is appended
|
2005-08-16 00:55:08 +00:00
|
|
|
* to the last token. Consecutive delimiters are treated as a single delimiter.
|
|
|
|
*
|
2010-04-16 15:05:42 +00:00
|
|
|
* The vector and all the strings are allocated with packet lifetime scope
|
2005-07-26 18:32:12 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2005-07-26 18:32:12 +00:00
|
|
|
gchar** ep_strsplit(const gchar* string, const gchar* delimiter, int max_tokens);
|
|
|
|
|
2012-10-10 19:05:30 +00:00
|
|
|
/** release all memory allocated in the previous packet dissection */
|
|
|
|
void ep_free_all(void);
|
|
|
|
|
2005-08-12 08:51:08 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** a stack implemented using ephemeral allocators */
|
2005-08-12 08:51:08 +00:00
|
|
|
|
2005-10-01 10:36:57 +00:00
|
|
|
typedef struct _ep_stack_frame_t** ep_stack_t;
|
|
|
|
|
|
|
|
struct _ep_stack_frame_t {
|
|
|
|
void* payload;
|
|
|
|
struct _ep_stack_frame_t* below;
|
|
|
|
struct _ep_stack_frame_t* above;
|
|
|
|
};
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/**
|
2005-10-01 10:36:57 +00:00
|
|
|
* creates an empty stack with a packet lifetime scope
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
ep_stack_t ep_stack_new(void) G_GNUC_MALLOC;
|
2005-10-01 10:36:57 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/**
|
2005-10-01 10:36:57 +00:00
|
|
|
* pushes item into stack, returns item
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2005-10-01 10:36:57 +00:00
|
|
|
void* ep_stack_push(ep_stack_t stack, void* item);
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/**
|
2005-10-01 10:36:57 +00:00
|
|
|
* pops an item from the stack
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2005-10-01 10:36:57 +00:00
|
|
|
void* ep_stack_pop(ep_stack_t stack);
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/**
|
2005-10-01 10:36:57 +00:00
|
|
|
* returns the item on top of the stack without popping it
|
|
|
|
*/
|
|
|
|
#define ep_stack_peek(stack) ((*(stack))->payload)
|
2005-08-12 08:51:08 +00:00
|
|
|
|
|
|
|
|
2009-09-20 09:28:55 +00:00
|
|
|
/* Functions for handling memory allocation and garbage collection with
|
2005-08-12 08:51:08 +00:00
|
|
|
* a capture lifetime scope.
|
|
|
|
* These functions are used to allocate memory that will only remain persistent
|
2006-05-28 19:49:07 +00:00
|
|
|
* until Wireshark opens a new capture or capture file.
|
|
|
|
* Everytime Wireshark starts a new capture or opens a new capture file
|
2009-09-20 09:28:55 +00:00
|
|
|
* all the data allocated through these functions will be released back
|
2005-08-12 08:51:08 +00:00
|
|
|
* to the free pool.
|
|
|
|
*
|
|
|
|
* These functions are very fast and offer automatic garbage collection.
|
|
|
|
*/
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Allocate memory with a capture lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
void *se_alloc(size_t size) G_GNUC_MALLOC;
|
2011-11-20 12:43:04 +00:00
|
|
|
#define se_new(type) ((type*)se_alloc(sizeof(type)))
|
2005-08-12 08:51:08 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Allocate memory with a capture lifetime scope and fill it with zeros*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
void* se_alloc0(size_t size) G_GNUC_MALLOC;
|
2011-11-20 12:43:04 +00:00
|
|
|
#define se_new0(type) ((type*)se_alloc0(sizeof(type)))
|
2005-08-16 00:55:08 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Duplicate a string with a capture lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
gchar* se_strdup(const gchar* src) G_GNUC_MALLOC;
|
2005-08-16 00:55:08 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Duplicate at most n characters of a string with a capture lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
gchar* se_strndup(const gchar* src, size_t len) G_GNUC_MALLOC;
|
2005-08-16 00:55:08 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Duplicate a buffer with a capture lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
void* se_memdup(const void* src, size_t len) G_GNUC_MALLOC;
|
2005-08-16 00:55:08 +00:00
|
|
|
|
2005-10-10 08:24:56 +00:00
|
|
|
/* Create a formatted string with a capture lifetime scope */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
gchar* se_strdup_vprintf(const gchar* fmt, va_list ap) G_GNUC_MALLOC;
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2005-09-15 08:54:56 +00:00
|
|
|
gchar* se_strdup_printf(const gchar* fmt, ...)
|
2010-01-25 13:20:53 +00:00
|
|
|
G_GNUC_MALLOC G_GNUC_PRINTF(1, 2);
|
2005-08-16 00:55:08 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** allocates with a capture lifetime scope an array of type made of num elements */
|
2005-08-16 01:01:17 +00:00
|
|
|
#define se_alloc_array(type,num) (type*)se_alloc(sizeof(type)*(num))
|
2005-08-16 00:55:08 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** release all memory allocated */
|
2005-08-12 08:51:08 +00:00
|
|
|
void se_free_all(void);
|
|
|
|
|
2011-05-09 08:55:35 +00:00
|
|
|
/**************************************************************
|
|
|
|
* slab allocator
|
|
|
|
**************************************************************/
|
|
|
|
struct _emem_chunk_t;
|
2005-08-12 08:51:08 +00:00
|
|
|
|
2012-05-04 21:56:32 +00:00
|
|
|
/* G_MEM_ALIGN is not always enough: http://mail.gnome.org/archives/gtk-devel-list/2004-December/msg00091.html
|
|
|
|
* So, we check (in configure) if we need 8-byte alignment. (Windows
|
|
|
|
* shouldn't need such a check until someone trys running it 32-bit on a CPU
|
|
|
|
* with more stringent alignment requirements than i386.)
|
|
|
|
*
|
|
|
|
* Yes, this ignores the possibility of needing 16-byte alignment for long doubles.
|
|
|
|
*/
|
|
|
|
#if defined(NEED_8_BYTE_ALIGNMENT) && (G_MEM_ALIGN < 8)
|
|
|
|
#define WS_MEM_ALIGN 8
|
|
|
|
#else
|
|
|
|
#define WS_MEM_ALIGN G_MEM_ALIGN
|
|
|
|
#endif
|
|
|
|
|
2006-03-05 04:01:34 +00:00
|
|
|
/**************************************************************
|
2009-09-20 09:28:55 +00:00
|
|
|
* binary trees
|
2006-03-05 04:01:34 +00:00
|
|
|
**************************************************************/
|
2006-08-14 08:29:29 +00:00
|
|
|
typedef struct _emem_tree_node_t {
|
|
|
|
struct _emem_tree_node_t *parent;
|
|
|
|
struct _emem_tree_node_t *left;
|
|
|
|
struct _emem_tree_node_t *right;
|
2007-12-04 01:44:05 +00:00
|
|
|
struct {
|
|
|
|
#define EMEM_TREE_RB_COLOR_RED 0
|
|
|
|
#define EMEM_TREE_RB_COLOR_BLACK 1
|
|
|
|
guint32 rb_color:1;
|
|
|
|
#define EMEM_TREE_NODE_IS_DATA 0
|
|
|
|
#define EMEM_TREE_NODE_IS_SUBTREE 1
|
|
|
|
guint32 is_subtree:1;
|
2006-05-02 18:02:08 +00:00
|
|
|
} u;
|
2006-03-05 04:01:34 +00:00
|
|
|
guint32 key32;
|
|
|
|
void *data;
|
2006-08-14 08:29:29 +00:00
|
|
|
} emem_tree_node_t;
|
2006-03-05 04:01:34 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Right now we only do basic red/black trees but in the future we might want
|
2006-03-05 04:01:34 +00:00
|
|
|
* 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.
|
2009-09-20 09:28:55 +00:00
|
|
|
* That would probably be good for things like nfs filehandles
|
2006-03-05 04:01:34 +00:00
|
|
|
*/
|
2006-08-14 08:29:29 +00:00
|
|
|
#define EMEM_TREE_TYPE_RED_BLACK 1
|
|
|
|
typedef struct _emem_tree_t {
|
|
|
|
struct _emem_tree_t *next;
|
2006-03-05 04:01:34 +00:00
|
|
|
int type;
|
2010-08-29 10:47:38 +00:00
|
|
|
const char *name; /**< just a string to make debugging easier */
|
2006-08-14 08:29:29 +00:00
|
|
|
emem_tree_node_t *tree;
|
2006-08-12 23:27:22 +00:00
|
|
|
void *(*malloc)(size_t);
|
2006-08-14 08:29:29 +00:00
|
|
|
} emem_tree_t;
|
2006-08-12 23:27:22 +00:00
|
|
|
|
2006-08-14 09:36:15 +00:00
|
|
|
/* *******************************************************************
|
|
|
|
* Tree functions for SE memory allocation scope
|
|
|
|
* ******************************************************************* */
|
2010-08-29 10:47:38 +00:00
|
|
|
/** This function is used to create a se based tree with monitoring.
|
2009-09-20 09:28:55 +00:00
|
|
|
* When the SE heap is released back to the system the pointer to the
|
add helper to build (red/black) trees from a key that is a vector of guin32 arrays.
test this functionality by calling these vector insert/lookup tree functions from the nfs dissector for when filehandles are used as a key.
these vector functions could also be used to efficiently store conversations :
se_tree_key_t[6] = {
{ addr_len/4, &src_addr },
{ addr_len/4, &dst_addr },
{ 1, &src_port32 },
{ 1, &dst_port32 },
{ 1, &protocol32 },
{ 0, NULL }
}
(the nfs dissector needs a LOT of work. It is very painful to work with
very large nfs traces with all the memory it wastes (and eats) as well as how slow all the tables make it)
svn path=/trunk/; revision=17477
2006-03-06 10:25:19 +00:00
|
|
|
* tree is automatically reset to NULL.
|
|
|
|
*
|
2006-08-14 08:29:29 +00:00
|
|
|
* type is : EMEM_TREE_TYPE_RED_BLACK for a standard red/black tree.
|
add helper to build (red/black) trees from a key that is a vector of guin32 arrays.
test this functionality by calling these vector insert/lookup tree functions from the nfs dissector for when filehandles are used as a key.
these vector functions could also be used to efficiently store conversations :
se_tree_key_t[6] = {
{ addr_len/4, &src_addr },
{ addr_len/4, &dst_addr },
{ 1, &src_port32 },
{ 1, &dst_port32 },
{ 1, &protocol32 },
{ 0, NULL }
}
(the nfs dissector needs a LOT of work. It is very painful to work with
very large nfs traces with all the memory it wastes (and eats) as well as how slow all the tables make it)
svn path=/trunk/; revision=17477
2006-03-06 10:25:19 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
emem_tree_t *se_tree_create(int type, const char *name) G_GNUC_MALLOC;
|
add helper to build (red/black) trees from a key that is a vector of guin32 arrays.
test this functionality by calling these vector insert/lookup tree functions from the nfs dissector for when filehandles are used as a key.
these vector functions could also be used to efficiently store conversations :
se_tree_key_t[6] = {
{ addr_len/4, &src_addr },
{ addr_len/4, &dst_addr },
{ 1, &src_port32 },
{ 1, &dst_port32 },
{ 1, &protocol32 },
{ 0, NULL }
}
(the nfs dissector needs a LOT of work. It is very painful to work with
very large nfs traces with all the memory it wastes (and eats) as well as how slow all the tables make it)
svn path=/trunk/; revision=17477
2006-03-06 10:25:19 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** se_tree_insert32
|
2006-08-14 09:36:15 +00:00
|
|
|
* Insert data into the tree and key it by a 32bit integer value
|
|
|
|
*/
|
|
|
|
#define se_tree_insert32 emem_tree_insert32
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** se_tree_lookup32
|
2010-04-16 15:05:42 +00:00
|
|
|
* Retrieve the data at the search key. The search key is a 32bit integer value
|
2006-08-14 09:36:15 +00:00
|
|
|
*/
|
|
|
|
#define se_tree_lookup32 emem_tree_lookup32
|
|
|
|
|
|
|
|
/* ******************************************************************
|
|
|
|
* Real tree functions
|
|
|
|
* ****************************************************************** */
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** This function is used to insert a node indexed by a guint32 key value.
|
2006-08-14 09:36:15 +00:00
|
|
|
* The data pointer should be allocated by the appropriate storage scope
|
2009-09-20 09:28:55 +00:00
|
|
|
* so that it will be released at the same time as the tree itself is
|
2006-08-14 09:36:15 +00:00
|
|
|
* destroyed.
|
add helper to build (red/black) trees from a key that is a vector of guin32 arrays.
test this functionality by calling these vector insert/lookup tree functions from the nfs dissector for when filehandles are used as a key.
these vector functions could also be used to efficiently store conversations :
se_tree_key_t[6] = {
{ addr_len/4, &src_addr },
{ addr_len/4, &dst_addr },
{ 1, &src_port32 },
{ 1, &dst_port32 },
{ 1, &protocol32 },
{ 0, NULL }
}
(the nfs dissector needs a LOT of work. It is very painful to work with
very large nfs traces with all the memory it wastes (and eats) as well as how slow all the tables make it)
svn path=/trunk/; revision=17477
2006-03-06 10:25:19 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2006-08-14 09:36:15 +00:00
|
|
|
void emem_tree_insert32(emem_tree_t *se_tree, guint32 key, void *data);
|
add helper to build (red/black) trees from a key that is a vector of guin32 arrays.
test this functionality by calling these vector insert/lookup tree functions from the nfs dissector for when filehandles are used as a key.
these vector functions could also be used to efficiently store conversations :
se_tree_key_t[6] = {
{ addr_len/4, &src_addr },
{ addr_len/4, &dst_addr },
{ 1, &src_port32 },
{ 1, &dst_port32 },
{ 1, &protocol32 },
{ 0, NULL }
}
(the nfs dissector needs a LOT of work. It is very painful to work with
very large nfs traces with all the memory it wastes (and eats) as well as how slow all the tables make it)
svn path=/trunk/; revision=17477
2006-03-06 10:25:19 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** This function will look up a node in the tree indexed by a guint32 integer
|
add helper to build (red/black) trees from a key that is a vector of guin32 arrays.
test this functionality by calling these vector insert/lookup tree functions from the nfs dissector for when filehandles are used as a key.
these vector functions could also be used to efficiently store conversations :
se_tree_key_t[6] = {
{ addr_len/4, &src_addr },
{ addr_len/4, &dst_addr },
{ 1, &src_port32 },
{ 1, &dst_port32 },
{ 1, &protocol32 },
{ 0, NULL }
}
(the nfs dissector needs a LOT of work. It is very painful to work with
very large nfs traces with all the memory it wastes (and eats) as well as how slow all the tables make it)
svn path=/trunk/; revision=17477
2006-03-06 10:25:19 +00:00
|
|
|
* value.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2006-08-14 09:36:15 +00:00
|
|
|
void *emem_tree_lookup32(emem_tree_t *se_tree, guint32 key);
|
2006-03-05 04:01:34 +00:00
|
|
|
|
2006-08-14 08:29:29 +00:00
|
|
|
typedef struct _emem_tree_key_t {
|
2010-08-29 10:47:38 +00:00
|
|
|
guint32 length; /**< length in guint32 words */
|
add helper to build (red/black) trees from a key that is a vector of guin32 arrays.
test this functionality by calling these vector insert/lookup tree functions from the nfs dissector for when filehandles are used as a key.
these vector functions could also be used to efficiently store conversations :
se_tree_key_t[6] = {
{ addr_len/4, &src_addr },
{ addr_len/4, &dst_addr },
{ 1, &src_port32 },
{ 1, &dst_port32 },
{ 1, &protocol32 },
{ 0, NULL }
}
(the nfs dissector needs a LOT of work. It is very painful to work with
very large nfs traces with all the memory it wastes (and eats) as well as how slow all the tables make it)
svn path=/trunk/; revision=17477
2006-03-06 10:25:19 +00:00
|
|
|
guint32 *key;
|
2006-08-14 08:29:29 +00:00
|
|
|
} emem_tree_key_t;
|
add helper to build (red/black) trees from a key that is a vector of guin32 arrays.
test this functionality by calling these vector insert/lookup tree functions from the nfs dissector for when filehandles are used as a key.
these vector functions could also be used to efficiently store conversations :
se_tree_key_t[6] = {
{ addr_len/4, &src_addr },
{ addr_len/4, &dst_addr },
{ 1, &src_port32 },
{ 1, &dst_port32 },
{ 1, &protocol32 },
{ 0, NULL }
}
(the nfs dissector needs a LOT of work. It is very painful to work with
very large nfs traces with all the memory it wastes (and eats) as well as how slow all the tables make it)
svn path=/trunk/; revision=17477
2006-03-06 10:25:19 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** traverse a tree. if the callback returns TRUE the traversal will end */
|
2007-12-03 22:47:23 +00:00
|
|
|
typedef gboolean (*tree_foreach_func)(void *value, void *userdata);
|
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2007-12-04 01:44:05 +00:00
|
|
|
gboolean emem_tree_foreach(emem_tree_t* emem_tree, tree_foreach_func callback, void *user_data);
|
2007-12-03 22:47:23 +00:00
|
|
|
|
2006-08-14 09:36:15 +00:00
|
|
|
|
2009-03-27 23:05:37 +00:00
|
|
|
/* ******************************************************************
|
|
|
|
* String buffers - Growable strings similar to GStrings
|
|
|
|
* ****************************************************************** */
|
|
|
|
|
|
|
|
typedef struct _emem_strbuf_t {
|
2010-08-29 10:47:38 +00:00
|
|
|
gchar *str; /**< Points to the character data. It may move as text is */
|
2010-04-16 15:05:42 +00:00
|
|
|
/* added. The str field is null-terminated and so can */
|
2009-04-14 14:08:19 +00:00
|
|
|
/* be used as an ordinary C string. */
|
2010-08-29 10:47:38 +00:00
|
|
|
gsize len; /**< strlen: ie: length of str not including trailing '\0' */
|
|
|
|
gsize alloc_len; /**< num bytes curently allocated for str: 1 .. MAX_STRBUF_LEN */
|
|
|
|
gsize max_alloc_len; /**< max num bytes to allocate for str: 1 .. MAX_STRBUF_LEN */
|
2009-03-27 23:05:37 +00:00
|
|
|
} emem_strbuf_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The maximum length is limited to 64K. If you need something bigger, you
|
|
|
|
* should probably use an actual GString or GByteArray.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate an ephemeral string buffer with "unlimited" size.
|
|
|
|
*
|
2009-04-14 14:08:19 +00:00
|
|
|
* @param init The initial string for the buffer, or NULL to allocate an initial zero-length string.
|
2009-03-27 23:05:37 +00:00
|
|
|
*
|
|
|
|
* @return A newly-allocated string buffer.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
emem_strbuf_t *ep_strbuf_new(const gchar *init) G_GNUC_MALLOC;
|
2009-03-27 23:05:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate an ephemeral string buffer suitable for the protocol tree.
|
|
|
|
* The string will never grow beyond the maximum tree item length.
|
|
|
|
*
|
2009-04-14 14:08:19 +00:00
|
|
|
* @param init The initial string for the buffer, or NULL to allocate an initial zero-length string.
|
2009-03-27 23:05:37 +00:00
|
|
|
*
|
|
|
|
* @return A newly-allocated string buffer.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
emem_strbuf_t *ep_strbuf_new_label(const gchar *init) G_GNUC_MALLOC;
|
2009-03-27 23:05:37 +00:00
|
|
|
|
|
|
|
/**
|
2010-08-26 15:24:49 +00:00
|
|
|
* Allocate an ephemeral string buffer with enough initial space for alloc_len bytes
|
|
|
|
* and a maximum of max_alloc_len bytes.
|
2009-03-27 23:05:37 +00:00
|
|
|
*
|
2009-04-14 14:08:19 +00:00
|
|
|
* @param alloc_len The initial size of the buffer. This value can be 0, but a nonzero
|
2009-03-27 23:05:37 +00:00
|
|
|
* value is recommended.
|
2009-04-14 14:08:19 +00:00
|
|
|
* @param max_alloc_len The maximum size of the buffer. 0 means "unlimited" (within
|
2009-03-27 23:05:37 +00:00
|
|
|
* reason).
|
|
|
|
*
|
2010-08-26 15:24:49 +00:00
|
|
|
* @return A newly-allocated string buffer. str will be empty.
|
2009-03-27 23:05:37 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2010-01-25 12:50:42 +00:00
|
|
|
emem_strbuf_t *ep_strbuf_sized_new(gsize alloc_len, gsize max_alloc_len) G_GNUC_MALLOC;
|
2009-03-27 23:05:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append vprintf-style formatted text to a string buffer.
|
|
|
|
*
|
|
|
|
* @param strbuf The ep_strbuf-allocated string buffer to append to.
|
|
|
|
* @param format A printf-style string format.
|
2010-08-26 15:24:49 +00:00
|
|
|
* @param ap The list of arguments to append.
|
2009-03-27 23:05:37 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2009-03-27 23:05:37 +00:00
|
|
|
void ep_strbuf_append_vprintf(emem_strbuf_t *strbuf, const gchar *format, va_list ap);
|
|
|
|
|
2009-03-28 00:27:03 +00:00
|
|
|
/**
|
|
|
|
* Apply printf-style formatted text to a string buffer.
|
|
|
|
*
|
|
|
|
* @param strbuf The ep_strbuf-allocated string buffer to set to.
|
|
|
|
* @param format A printf-style string format.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2009-03-28 00:27:03 +00:00
|
|
|
void ep_strbuf_printf(emem_strbuf_t *strbuf, const gchar *format, ...)
|
2010-01-25 13:20:53 +00:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2009-03-28 00:27:03 +00:00
|
|
|
|
2009-03-27 23:05:37 +00:00
|
|
|
/**
|
|
|
|
* Append printf-style formatted text to a string buffer.
|
|
|
|
*
|
|
|
|
* @param strbuf The ep_strbuf-allocated string buffer to append to.
|
|
|
|
* @param format A printf-style string format.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2009-03-27 23:05:37 +00:00
|
|
|
void ep_strbuf_append_printf(emem_strbuf_t *strbuf, const gchar *format, ...)
|
2010-01-25 13:20:53 +00:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2009-03-27 23:05:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append a string to a string buffer.
|
|
|
|
*
|
|
|
|
* @param strbuf The ep_strbuf-allocated string buffer to append to.
|
|
|
|
* @param str A null-terminated string.
|
2009-04-14 14:08:19 +00:00
|
|
|
*
|
|
|
|
* @return strbuf
|
2009-03-27 23:05:37 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2009-04-14 14:08:19 +00:00
|
|
|
emem_strbuf_t *ep_strbuf_append(emem_strbuf_t *strbuf, const gchar *str);
|
2009-03-27 23:05:37 +00:00
|
|
|
|
2009-03-28 00:27:03 +00:00
|
|
|
/**
|
|
|
|
* Append a character to a string buffer.
|
|
|
|
*
|
|
|
|
* @param strbuf The ep_strbuf-allocated string buffer to append to.
|
|
|
|
* @param c The character to append.
|
2009-04-14 14:08:19 +00:00
|
|
|
*
|
|
|
|
* @return strbuf
|
2009-03-28 00:27:03 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2009-04-14 14:08:19 +00:00
|
|
|
emem_strbuf_t *ep_strbuf_append_c(emem_strbuf_t *strbuf, const gchar c);
|
2009-03-28 00:27:03 +00:00
|
|
|
|
2012-08-18 19:20:31 +00:00
|
|
|
/**
|
|
|
|
* Append a Unicode characeter converted to UTF-8 to a string buffer.
|
|
|
|
*
|
|
|
|
* @param strbuf The ep_strbuf-allocated string buffer to append to.
|
|
|
|
* @param c The Unicode character to append.
|
|
|
|
*
|
|
|
|
* @return strbuf
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2012-08-18 19:20:31 +00:00
|
|
|
emem_strbuf_t *ep_strbuf_append_unichar(emem_strbuf_t *strbuf, const gunichar c);
|
|
|
|
|
2009-03-27 23:05:37 +00:00
|
|
|
/**
|
|
|
|
* Chop off the end of a string buffer.
|
|
|
|
*
|
|
|
|
* @param strbuf The ep_strbuf-allocated string buffer to append to.
|
|
|
|
* @param len The new string length.
|
2009-04-14 14:08:19 +00:00
|
|
|
*
|
|
|
|
* @return strbuf
|
2009-03-27 23:05:37 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2009-04-14 14:08:19 +00:00
|
|
|
emem_strbuf_t *ep_strbuf_truncate(emem_strbuf_t *strbuf, gsize len);
|
2009-03-27 23:05:37 +00:00
|
|
|
|
2012-10-06 14:35:59 +00:00
|
|
|
/**
|
|
|
|
* Dump the whole tree (of trees) to stdout.
|
|
|
|
*
|
|
|
|
* @param emem_tree The tree to dump to standard output.
|
|
|
|
*
|
2013-08-10 21:27:52 +00:00
|
|
|
*
|
2012-10-06 14:35:59 +00:00
|
|
|
*/
|
2009-09-20 12:02:40 +00:00
|
|
|
void emem_print_tree(emem_tree_t* emem_tree);
|
2006-08-14 09:36:15 +00:00
|
|
|
|
2008-08-05 02:23:35 +00:00
|
|
|
/* #define DEBUG_INTENSE_CANARY_CHECKS */
|
2009-10-11 06:22:55 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** Helper to troubleshoot ep memory corruption.
|
2010-04-16 15:05:42 +00:00
|
|
|
* If compiled and the environment variable WIRESHARK_DEBUG_EP_INTENSE_CANARY exists
|
2008-08-05 02:23:35 +00:00
|
|
|
* it will check the canaries and when found corrupt stop there in the hope
|
|
|
|
* the corruptor is still there in the stack.
|
2009-09-20 09:28:55 +00:00
|
|
|
* Some checkpoints are already set in packet.c in strategic points
|
2008-08-05 02:23:35 +00:00
|
|
|
* before and after dissection of a frame or a dissector call.
|
|
|
|
*/
|
2006-08-14 09:36:15 +00:00
|
|
|
|
2008-08-05 02:23:35 +00:00
|
|
|
#ifdef DEBUG_INTENSE_CANARY_CHECKS
|
2009-10-11 06:22:55 +00:00
|
|
|
void ep_check_canary_integrity(const char* fmt, ...)
|
2010-01-25 13:20:53 +00:00
|
|
|
G_GNUC_PRINTF(1, 2);
|
2009-10-11 06:22:55 +00:00
|
|
|
#define EP_CHECK_CANARY(args) ep_check_canary_integrity args
|
2008-08-05 02:23:35 +00:00
|
|
|
#else
|
2009-10-11 06:22:55 +00:00
|
|
|
#define EP_CHECK_CANARY(args)
|
2008-08-05 02:23:35 +00:00
|
|
|
#endif
|
2009-09-20 09:28:55 +00:00
|
|
|
|
2009-09-20 12:02:40 +00:00
|
|
|
/**
|
2010-08-29 10:47:38 +00:00
|
|
|
* Verify that the given pointer is of ephemeral type.
|
2009-09-20 12:02:40 +00:00
|
|
|
*
|
|
|
|
* @param ptr The pointer to verify
|
|
|
|
*
|
2010-08-29 10:47:38 +00:00
|
|
|
* @return TRUE if the pointer belongs to the ephemeral pool.
|
2009-09-20 12:02:40 +00:00
|
|
|
*/
|
|
|
|
gboolean ep_verify_pointer(const void *ptr);
|
2010-08-29 10:47:38 +00:00
|
|
|
/**
|
|
|
|
* Verify that the given pointer is of seasonal type.
|
|
|
|
*
|
|
|
|
* @param ptr The pointer to verify
|
|
|
|
*
|
|
|
|
* @return TRUE if the pointer belongs to the seasonal pool.
|
|
|
|
*/
|
2009-09-20 12:02:40 +00:00
|
|
|
gboolean se_verify_pointer(const void *ptr);
|
2006-03-07 01:15:29 +00:00
|
|
|
|
2005-07-22 07:46:58 +00:00
|
|
|
#endif /* emem.h */
|