diff options
author | Evan Huus <eapache@gmail.com> | 2012-10-24 02:04:40 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2012-10-24 02:04:40 +0000 |
commit | 84cc3daa3b2a596660492b730fe4e27ebb595a5f (patch) | |
tree | c2f2354a4edd2562cadb75166967c4f997dea87d | |
parent | 7044125704da6d9ead243c2ead3e79eee70bc1be (diff) | |
download | wireshark-84cc3daa3b2a596660492b730fe4e27ebb595a5f.tar.gz |
Basic skeleton for wmem.
https://www.wireshark.org/lists/wireshark-dev/201210/msg00178.html
svn path=/trunk/; revision=45746
-rw-r--r-- | epan/CMakeLists.txt | 20 | ||||
-rw-r--r-- | epan/Makefile.am | 8 | ||||
-rw-r--r-- | epan/Makefile.nmake | 24 | ||||
-rw-r--r-- | epan/wmem/Makefile.am | 71 | ||||
-rw-r--r-- | epan/wmem/Makefile.common | 50 | ||||
-rw-r--r-- | epan/wmem/Makefile.nmake | 44 | ||||
-rw-r--r-- | epan/wmem/wmem.h | 45 | ||||
-rw-r--r-- | epan/wmem/wmem_allocator.h | 59 | ||||
-rw-r--r-- | epan/wmem/wmem_allocator_glib.c | 98 | ||||
-rw-r--r-- | epan/wmem/wmem_allocator_glib.h | 58 | ||||
-rw-r--r-- | epan/wmem/wmem_core.c | 64 | ||||
-rw-r--r-- | epan/wmem/wmem_core.h | 63 | ||||
-rw-r--r-- | epan/wmem/wmem_strutl.c | 78 | ||||
-rw-r--r-- | epan/wmem/wmem_strutl.h | 62 |
14 files changed, 735 insertions, 9 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index b2373d31e0..d4894146c1 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1340,6 +1340,12 @@ set(FTYPE_FILES ftypes/ftype-tvbuff.c ) +set(WMEM_FILES + wmem/wmem_core.c + wmem/wmem_allocator_glib.c + wmem/wmem_strutl.c +) + ADD_CUSTOM_COMMAND( OUTPUT sminmpec.c @@ -1478,6 +1484,7 @@ set(CLEAN_FILES # ${DISSECTOR_FILES } end ${DISSECTOR_SUPPORT_SRC} ${LIBWIRESHARK_ASM_FILES} + ${WMEM_FILES} ${WSLUA_FILES} ${WSPYTHON_FILES} ) @@ -1498,6 +1505,7 @@ add_library(epan ${LINK_MODE_LIB} ${CRYPT_FILES} ${DFILTER_FILES} ${FTYPE_FILES} + ${WMEM_FILES} ${WSLUA_FILES} ${WSPYTHON_FILES} ${DISSECTOR_FILES} @@ -1522,3 +1530,15 @@ if(NOT ${ENABLE_STATIC}) ) endif() +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 8 +# tab-width: 8 +# indent-tabs-mode: t +# End: +# +# vi: set shiftwidth=8 tabstop=8 noexpandtab: +# :indentSize=8:tabSize=8:noTabs=false: +# diff --git a/epan/Makefile.am b/epan/Makefile.am index 4de9a1a287..4bb1c1e107 100644 --- a/epan/Makefile.am +++ b/epan/Makefile.am @@ -47,7 +47,7 @@ wspython_dist_dir = wspython py_dissectors_dir = -DPYTHONDIR= endif -SUBDIRS = crypt ftypes dfilter dissectors $(wslua_dir) $(wspython_dir) +SUBDIRS = crypt ftypes dfilter dissectors wmem $(wslua_dir) $(wspython_dir) DIST_SUBDIRS = $(SUBDIRS) $(wslua_dist_dir) $(wspython_dist_dir) @@ -136,7 +136,7 @@ libwireshark_la_LIBADD = \ libwireshark_generated.la \ libwireshark_asmopt.la crypt/libairpdcap.la \ ftypes/libftypes.la dfilter/libdfilter.la dissectors/libdissectors.la \ - dissectors/libdirtydissectors.la $(wslua_lib) $(wspython_lib) @SOCKET_LIBS@ @NSL_LIBS@ \ + dissectors/libdirtydissectors.la wmem/libwmem.la $(wslua_lib) $(wspython_lib) @SOCKET_LIBS@ @NSL_LIBS@ \ @C_ARES_LIBS@ @ADNS_LIBS@ @LIBGCRYPT_LIBS@ @LIBGNUTLS_LIBS@ \ @KRB5_LIBS@ @SSL_LIBS@ @LIBSMI_LDFLAGS@ @GEOIP_LIBS@ \ ${top_builddir}/wiretap/libwiretap.la @GLIB_LIBS@ \ @@ -146,7 +146,7 @@ libwireshark_la_DEPENDENCIES = \ libwireshark_generated.la \ libwireshark_asmopt.la crypt/libairpdcap.la \ ftypes/libftypes.la dfilter/libdfilter.la dissectors/libdissectors.la \ - dissectors/libdirtydissectors.la $(wslua_lib) $(wspython_lib) \ + dissectors/libdirtydissectors.la wmem/libwmem.la $(wslua_lib) $(wspython_lib) \ ${top_builddir}/wsutil/libwsutil.la \ ${top_builddir}/wiretap/libwiretap.la \ libwireshark.sym @@ -328,6 +328,8 @@ dumpabi: all abi-descriptor.xml abi-check-headers/dissectors/packet-idmp.h mkdir abi-check-headers/ftypes cp ftypes/*.h abi-check-headers/ftypes + mkdir abi-check-headers/wmem + cp wmem/*.h abi-check-headers/wmem abi-compliance-checker -l libwireshark -v1 `ls .libs/libwireshark.so.?.?.?|sed 's/.*\.so\.//'` \ -relpath $(abs_srcdir) -dump-abi abi-descriptor.xml || \ cat logs/libwireshark/[0-9]*/log.txt diff --git a/epan/Makefile.nmake b/epan/Makefile.nmake index 95a3d49250..31b61cedc8 100644 --- a/epan/Makefile.nmake +++ b/epan/Makefile.nmake @@ -55,6 +55,7 @@ libwireshark_LIBS = \ crypt\airpdcap.lib \ ftypes\ftypes.lib \ dfilter\dfilter.lib \ + wmem\wmem.lib \ $(WSLUA_LIB) \ $(WSPYTHON_LIB) \ dissectors\dissectors.lib @@ -76,17 +77,17 @@ DOXYGEN_DEP=doxygen !ENDIF !IFDEF ENABLE_LIBWIRESHARK -all: crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.dll +all: crypt ftypes dfilter wmem $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.dll !ELSE -all: crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.lib +all: crypt ftypes dfilter wmem $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.lib !ENDIF # For use when making libwireshark.dll libwireshark.lib: libwireshark.dll libwireshark.exp: libwireshark.dll -libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ - crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib dissectors\dissectors.lib $(WSLUA_LIB) $(WSPYTHON_LIB) ..\image\libwireshark.res +libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crypt ftypes dfilter wmem $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ + crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib wmem/wmem.lib dissectors\dissectors.lib $(WSLUA_LIB) $(WSPYTHON_LIB) ..\image\libwireshark.res @echo Linking libwireshark.dll $(link) $(dlllflags) $(conlibsdll) shell32.lib \ $(LOCAL_LDFLAGS) $(DLL_LDFLAGS) \ @@ -96,8 +97,8 @@ libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crypt fty dissectors\register.obj \ $(EXTRA_OBJECTS) -libwireshark.lib : ..\config.h $(LIBWIRESHARK_OBJECTS) crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ - crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib $(WSLUA_LIB) $(WSPYTHON_LIB) dissectors\dissectors.lib +libwireshark.lib : ..\config.h $(LIBWIRESHARK_OBJECTS) crypt ftypes dfilter wmem $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ + crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib wmem/wmem.lib $(WSLUA_LIB) $(WSPYTHON_LIB) dissectors\dissectors.lib link /lib /out:libwireshark.lib $(LIBWIRESHARK_OBJECTS) \ $(EXTRA_OBJECTS) @@ -122,6 +123,8 @@ clean: clean-local $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean cd ../dissectors $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean + cd ../wmem + $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean cd ../wslua $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean cd ../wspython @@ -154,6 +157,8 @@ distclean: distclean-local $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean cd ../dissectors $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean + cd ../wmem + $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean cd ../wslua $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean cd ../wspython @@ -171,6 +176,8 @@ maintainer-clean: maintainer-clean-local $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean cd ../dissectors $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean + cd ../wmem + $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean cd ../wslua $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean cd ../wspython @@ -197,6 +204,11 @@ dissectors:: ..\config.h $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake cd .. +wmem:: ..\config.h + cd wmem + $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake + cd .. + wslua:: ..\config.h cd wslua $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake diff --git a/epan/wmem/Makefile.am b/epan/wmem/Makefile.am new file mode 100644 index 0000000000..7c803f1c1c --- /dev/null +++ b/epan/wmem/Makefile.am @@ -0,0 +1,71 @@ +# Makefile.am +# Automake file for Wireshark Memory Manager +# +# $Id$ +# +# 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 +# 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 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +INCLUDES = -I$(top_srcdir) + +include Makefile.common + +if HAVE_WARNINGS_AS_ERRORS +AM_CFLAGS = -Werror +endif + +AM_CPPFLAGS = $(LIBWMEM_CFLAGS) + +noinst_LTLIBRARIES = libwmem.la + +CLEANFILES = \ + libwmem.a \ + libwmem.la \ + *~ + +DISTCLEANFILES = + +MAINTAINERCLEANFILES = \ + Makefile.in + +libairpdcap_la_SOURCES = \ + $(LIBWMEM_SRC) \ + $(LIBWMEM_INCLUDES) + +EXTRA_DIST = \ + Custom.common \ + Makefile.common \ + Makefile.nmake + +checkapi: + $(PERL) ../../tools/checkAPIs.pl -g termoutput -build \ + $(LIBWMEM_SRC) + + +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 8 +# tab-width: 8 +# indent-tabs-mode: t +# End: +# +# vi: set shiftwidth=8 tabstop=8 noexpandtab: +# :indentSize=8:tabSize=8:noTabs=false: +# diff --git a/epan/wmem/Makefile.common b/epan/wmem/Makefile.common new file mode 100644 index 0000000000..f1b095101e --- /dev/null +++ b/epan/wmem/Makefile.common @@ -0,0 +1,50 @@ +# Makefile.common +# Contains the stuff from Makefile.am and Makefile.nmake that is +# a) common to both files and +# b) portable between both files +# +# $Id$ +# +# 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 +# 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 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +LIBWMEM_SRC = \ + wmem_core.c \ + wmem_allocator_glib.c \ + wmem_strutl.c + +LIBWMEM_INCLUDES = \ + wmem.h \ + wmem_core.h \ + wmem_allocator.h \ + wmem_allocator_glib.h \ + wmem_strutl.h + + +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 8 +# tab-width: 8 +# indent-tabs-mode: t +# End: +# +# vi: set shiftwidth=8 tabstop=8 noexpandtab: +# :indentSize=8:tabSize=8:noTabs=false: +# diff --git a/epan/wmem/Makefile.nmake b/epan/wmem/Makefile.nmake new file mode 100644 index 0000000000..0c512ebfe7 --- /dev/null +++ b/epan/wmem/Makefile.nmake @@ -0,0 +1,44 @@ +## Makefile for building wmem.lib with Microsoft C and nmake +## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake +# +# $Id$ + +include ..\..\config.nmake +include Makefile.common + +############### no need to modify below this line ######### + +CFLAGS=$(WARNINGS_ARE_ERRORS) $(STANDARD_CFLAGS) \ + /I../.. $(GLIB_CFLAGS) + +.c.obj:: + $(CC) $(CFLAGS) -Fd.\ -c $< + +WMEM_OBJECTS = $(LIBWMEM_SRC:.c=.obj) + +wmem.lib: $(WMEM_OBJECTS) + link /lib /out:wmem.lib $(WMEM_OBJECTS) + +clean: + rm -f $(WMEM_OBJECTS) wmem.lib *.pdb *.sbr + +distclean: clean + +maintainer-clean: distclean + +checkapi: + $(PERL) ../../tools/checkAPIs.pl -g termoutput -build \ + $(WMEM_SRC) + +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 8 +# tab-width: 8 +# indent-tabs-mode: t +# End: +# +# vi: set shiftwidth=8 tabstop=8 noexpandtab: +# :indentSize=8:tabSize=8:noTabs=false: +# diff --git a/epan/wmem/wmem.h b/epan/wmem/wmem.h new file mode 100644 index 0000000000..c6c906e850 --- /dev/null +++ b/epan/wmem/wmem.h @@ -0,0 +1,45 @@ +/* wmem.h + * Definitions for the Wireshark Memory Manager + * Copyright 2012, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * 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 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 Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WMEM_H__ +#define __WMEM_H__ + +#include "wmem_core.h" +#include "wmem_strutl.h" + +#endif /* __WMEM_H__ */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/wmem/wmem_allocator.h b/epan/wmem/wmem_allocator.h new file mode 100644 index 0000000000..6c9c931e34 --- /dev/null +++ b/epan/wmem/wmem_allocator.h @@ -0,0 +1,59 @@ +/* wmem_allocator.h + * Definitions for the Wireshark Memory Manager Allocator + * Copyright 2012, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * 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 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 Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WMEM_ALLOCATOR_H__ +#define __WMEM_ALLOCATOR_H__ + +#include <string.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct _wmem_allocator_t { + void *(*alloc)(void *private_data, size_t size); + void (*free_all)(void *private_data); + + void *private_data; +} wmem_allocator_t; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __WMEM_ALLOCATOR_H__ */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/wmem/wmem_allocator_glib.c b/epan/wmem/wmem_allocator_glib.c new file mode 100644 index 0000000000..01dbc6c570 --- /dev/null +++ b/epan/wmem/wmem_allocator_glib.c @@ -0,0 +1,98 @@ +/* wmem_allocator_glib.c + * Wireshark Memory Manager GLib-Based Allocator + * Copyright 2012, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * 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 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 Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <string.h> + +#include <glib.h> + +#include "wmem_allocator.h" + +/* In this trivial allocator, we just store a GSList of g_malloc()ed + * blocks in the private_data pointer. */ +typedef struct _wmem_glib_allocator_t { + GSList *block_list; +} wmem_glib_allocator_t; + +static void * +wmem_glib_alloc(void *private_data, size_t size) +{ + void *buf; + wmem_glib_allocator_t *allocator = (wmem_glib_allocator_t*) private_data; + + buf = g_malloc(size); + + allocator->block_list = g_slist_prepend(allocator->block_list, buf); + + return buf; +} + +static void +wmem_glib_free_all(void *private_data) +{ + wmem_glib_allocator_t *allocator = (wmem_glib_allocator_t*) private_data; + + g_slist_free_full(allocator->block_list, &g_free); + + allocator->block_list = NULL; +} + +wmem_allocator_t * +wmem_create_glib_allocator(void) +{ + wmem_allocator_t *allocator; + wmem_glib_allocator_t *glib_allocator; + + allocator = g_new(wmem_allocator_t, 1); + glib_allocator = g_new(wmem_glib_allocator_t, 1); + + allocator->alloc = &wmem_glib_alloc; + allocator->free_all = &wmem_glib_free_all; + allocator->private_data = (void*) glib_allocator; + + glib_allocator->block_list = NULL; + + return allocator; +} + +void +wmem_destroy_glib_allocator(wmem_allocator_t *allocator) +{ + allocator->free_all(allocator->private_data); + g_free(allocator->private_data); + g_free(allocator); +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/wmem/wmem_allocator_glib.h b/epan/wmem/wmem_allocator_glib.h new file mode 100644 index 0000000000..9831df7a3e --- /dev/null +++ b/epan/wmem/wmem_allocator_glib.h @@ -0,0 +1,58 @@ +/* wmem_allocator_glib.h + * Definitions for the Wireshark Memory Manager GLib-Based Allocator + * Copyright 2012, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * 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 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 Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WMEM_ALLOCATOR_GLIB_H__ +#define __WMEM_ALLOCATOR_GLIB_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct _wmem_allocator_t wmem_allocator_t; + +wmem_allocator_t * +wmem_create_glib_allocator(void); + +void +wmem_destroy_glib_allocator(wmem_allocator_t *allocator); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __WMEM_ALLOCATOR_GLIB_H__ */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/wmem/wmem_core.c b/epan/wmem/wmem_core.c new file mode 100644 index 0000000000..97180d8deb --- /dev/null +++ b/epan/wmem/wmem_core.c @@ -0,0 +1,64 @@ +/* wmem_core.c + * Wireshark Memory Manager Core + * Copyright 2012, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * 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 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 Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <string.h> + +#include "wmem_core.h" +#include "wmem_allocator.h" + +void * +wmem_alloc(wmem_allocator_t *allocator, size_t size) +{ + return allocator->alloc(allocator->private_data, size); +} + +void * +wmem_alloc0(wmem_allocator_t *allocator, size_t size) +{ + void *buf; + + buf = wmem_alloc(allocator, size); + + return memset(buf, 0, size); +} + +void +wmem_free_all(wmem_allocator_t *allocator) +{ + allocator->free_all(allocator->private_data); +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/wmem/wmem_core.h b/epan/wmem/wmem_core.h new file mode 100644 index 0000000000..ec44bf78bd --- /dev/null +++ b/epan/wmem/wmem_core.h @@ -0,0 +1,63 @@ +/* wmem_core.h + * Definitions for the Wireshark Memory Manager Core + * Copyright 2012, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * 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 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 Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WMEM_CORE_H__ +#define __WMEM_CORE_H__ + +#include <string.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct _wmem_allocator_t wmem_allocator_t; + +void * +wmem_alloc(wmem_allocator_t *allocator, size_t size); + +void * +wmem_alloc0(wmem_allocator_t *allocator, size_t size); + +void +wmem_free_all(wmem_allocator_t *allocator); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __WMEM_CORE_H__ */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/wmem/wmem_strutl.c b/epan/wmem/wmem_strutl.c new file mode 100644 index 0000000000..82dd481eb9 --- /dev/null +++ b/epan/wmem/wmem_strutl.c @@ -0,0 +1,78 @@ +/* wmem_strutl.c + * Wireshark Memory Manager String Utilities + * Copyright 2012, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * 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 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 Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <string.h> + +#include <glib.h> + +#include "wmem_core.h" +#include "wmem_allocator.h" +#include "wmem_strutl.h" + +gchar * +wmem_strdup(wmem_allocator_t *allocator, const gchar *src) +{ + size_t len; + + /* If the string is NULL, just return the string "<NULL>" so that the + * callers don't have to bother checking it. */ + if(!src) { + return "<NULL>"; + } + + len = strlen(src) + 1; /* +1 for the null-terminator */ + + return memcpy(wmem_alloc(allocator, len), src, len); +} + +gchar * +wmem_strndup(wmem_allocator_t *allocator, const gchar *src, size_t len) +{ + gchar *dst; + guint i; + + dst = wmem_alloc(allocator, len+1); + + for (i=0; (i < len) && src[i]; i++) { + dst[i] = src[i]; + } + + dst[i] = '\0'; + + return dst; +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/wmem/wmem_strutl.h b/epan/wmem/wmem_strutl.h new file mode 100644 index 0000000000..2b59dc4621 --- /dev/null +++ b/epan/wmem/wmem_strutl.h @@ -0,0 +1,62 @@ +/* wmem_strutl.h + * Definitions for the Wireshark Memory Manager String Utilities + * Copyright 2012, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * 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 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 Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WMEM_STRUTL_H__ +#define __WMEM_STRUTL_H__ + +#include <string.h> + +#include <glib.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct _wmem_allocator_t wmem_allocator_t; + +gchar * +wmem_strdup(wmem_allocator_t *allocator, const gchar *src); + +gchar * +wmem_strndup(wmem_allocator_t *allocator, const gchar *src, size_t len); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __WMEM_STRUTL_H__ */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ |