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
|
|
|
|
*
|
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"
|
|
|
|
|
Add a Qt I/O Graph dialog.
For each graph you can set:
- Its visibility
- A name
- A display filter
- Color, from a fixed list
- Plot style: Line, Impulse, Bar, Stacked Bar, Dot, Square, Diamond
- Basic Y Axes (packets/s, bytes/s, bits/s)
- Computed Y Axes (SUM, MIN, AVG, MAX)
- Smoothing
You can pan and zoom using the mouse and keyboard. Clicking on a graph
selects the last packet for that interval. If all graphs have the same Y
axis a single label is shown, otherwise a legend is shown.
The time scale (X axis) can be toggled between relative seconds and the
time of day.
Graphs can be saved as PDF, PNG, BMP, and JPEG. Settings are "sticky"
via the io_graphs UAT.
To do:
- Minimize graph drawing delays.
- Figure out why smoothing differs from GTK+
- Everything else at the top of io_graph_dialog.cpp
- Fix empty resets.
A fair amount of code was copied from TCPStreamDialog. We might want to
subclass QCustomPlot and place the shared code there.
Move common syntax checking to SyntaxLineEdit.
Move some common code from ui/gtk/io_stat.c to ui/io_graph_item.[ch] and
use it in both GTK+ and Qt.
Make the io_graph_item_t array allocation in io_stat.c static. The
behavior should be identical and this gives us additional compile-time
checks.
Change-Id: I9a3d544469b7048f0761fdbf7bcf20f44ae76577
Reviewed-on: https://code.wireshark.org/review/435
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Tested-by: Gerald Combs <gerald@wireshark.org>
2014-02-12 00:07:10 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
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-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
|
2014-07-06 13:34:38 +00:00
|
|
|
gchar* ep_strdup_vprintf(const gchar* fmt, va_list ap)
|
|
|
|
G_GNUC_MALLOC G_GNUC_PRINTF(1, 0);
|
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, ...)
|
2014-07-06 13:34:38 +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;
|
|
|
|
|
2012-10-10 19:05:30 +00:00
|
|
|
/** release all memory allocated in the previous packet dissection */
|
|
|
|
void ep_free_all(void);
|
|
|
|
|
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
|
|
|
/** 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
|
|
|
|
**************************************************************/
|
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
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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);
|
2006-03-07 01:15:29 +00:00
|
|
|
|
Add a Qt I/O Graph dialog.
For each graph you can set:
- Its visibility
- A name
- A display filter
- Color, from a fixed list
- Plot style: Line, Impulse, Bar, Stacked Bar, Dot, Square, Diamond
- Basic Y Axes (packets/s, bytes/s, bits/s)
- Computed Y Axes (SUM, MIN, AVG, MAX)
- Smoothing
You can pan and zoom using the mouse and keyboard. Clicking on a graph
selects the last packet for that interval. If all graphs have the same Y
axis a single label is shown, otherwise a legend is shown.
The time scale (X axis) can be toggled between relative seconds and the
time of day.
Graphs can be saved as PDF, PNG, BMP, and JPEG. Settings are "sticky"
via the io_graphs UAT.
To do:
- Minimize graph drawing delays.
- Figure out why smoothing differs from GTK+
- Everything else at the top of io_graph_dialog.cpp
- Fix empty resets.
A fair amount of code was copied from TCPStreamDialog. We might want to
subclass QCustomPlot and place the shared code there.
Move common syntax checking to SyntaxLineEdit.
Move some common code from ui/gtk/io_stat.c to ui/io_graph_item.[ch] and
use it in both GTK+ and Qt.
Make the io_graph_item_t array allocation in io_stat.c static. The
behavior should be identical and this gives us additional compile-time
checks.
Change-Id: I9a3d544469b7048f0761fdbf7bcf20f44ae76577
Reviewed-on: https://code.wireshark.org/review/435
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Tested-by: Gerald Combs <gerald@wireshark.org>
2014-02-12 00:07:10 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2005-07-22 07:46:58 +00:00
|
|
|
#endif /* emem.h */
|