From 7f9c1f5f92c131354fc8b2b88d473706786064c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Mon, 12 Jul 2021 21:22:05 +0100 Subject: [PATCH] Move wmem to wsutil This allows wmem to be used from other libraries, namely wsutil. It is often the case that a funtion exists in wsutil and cannot be used with a wmem scope, requiring some code duplication or extra memory allocations, or vice-versa, code in epan cannot be moved to wsutil because it has a wmem dependency. To this end wmem is moved to wsutil. Scope management remains part of epan because those scope semantics are specific to dissection. --- debian/libwireshark0.symbols | 108 +----------------- debian/libwsutil-dev.install | 1 + debian/libwsutil0.symbols | 106 +++++++++++++++++ epan/CMakeLists.txt | 5 +- epan/epan.c | 4 +- epan/oids_test.c | 4 +- epan/wmem/wmem.h | 20 +--- epan/wmem/wmem_scopes.c | 65 +++++------ epan/wmem/wmem_scopes.h | 6 +- wsutil/CMakeLists.txt | 3 + {epan => wsutil}/wmem/CMakeLists.txt | 6 +- {epan => wsutil}/wmem/wmem-int.h | 0 wsutil/wmem/wmem.h | 41 +++++++ {epan => wsutil}/wmem/wmem_allocator.h | 0 {epan => wsutil}/wmem/wmem_allocator_block.c | 0 {epan => wsutil}/wmem/wmem_allocator_block.h | 0 .../wmem/wmem_allocator_block_fast.c | 0 .../wmem/wmem_allocator_block_fast.h | 0 {epan => wsutil}/wmem/wmem_allocator_simple.c | 0 {epan => wsutil}/wmem/wmem_allocator_simple.h | 0 {epan => wsutil}/wmem/wmem_allocator_strict.c | 0 {epan => wsutil}/wmem/wmem_allocator_strict.h | 0 {epan => wsutil}/wmem/wmem_array.c | 0 {epan => wsutil}/wmem/wmem_array.h | 0 {epan => wsutil}/wmem/wmem_core.c | 23 +++- {epan => wsutil}/wmem/wmem_core.h | 12 ++ {epan => wsutil}/wmem/wmem_interval_tree.c | 0 {epan => wsutil}/wmem/wmem_interval_tree.h | 0 {epan => wsutil}/wmem/wmem_list.c | 0 {epan => wsutil}/wmem/wmem_list.h | 0 {epan => wsutil}/wmem/wmem_map.c | 0 {epan => wsutil}/wmem/wmem_map.h | 0 {epan => wsutil}/wmem/wmem_map_int.h | 0 {epan => wsutil}/wmem/wmem_miscutl.c | 0 {epan => wsutil}/wmem/wmem_miscutl.h | 0 {epan => wsutil}/wmem/wmem_queue.h | 0 {epan => wsutil}/wmem/wmem_stack.c | 0 {epan => wsutil}/wmem/wmem_stack.h | 0 {epan => wsutil}/wmem/wmem_strbuf.c | 0 {epan => wsutil}/wmem/wmem_strbuf.h | 0 {epan => wsutil}/wmem/wmem_strutl.c | 0 {epan => wsutil}/wmem/wmem_strutl.h | 0 {epan => wsutil}/wmem/wmem_test.c | 0 {epan => wsutil}/wmem/wmem_tree-int.h | 0 {epan => wsutil}/wmem/wmem_tree.c | 0 {epan => wsutil}/wmem/wmem_tree.h | 0 {epan => wsutil}/wmem/wmem_user_cb.c | 0 {epan => wsutil}/wmem/wmem_user_cb.h | 0 {epan => wsutil}/wmem/wmem_user_cb_int.h | 0 49 files changed, 237 insertions(+), 167 deletions(-) rename {epan => wsutil}/wmem/CMakeLists.txt (94%) rename {epan => wsutil}/wmem/wmem-int.h (100%) create mode 100644 wsutil/wmem/wmem.h rename {epan => wsutil}/wmem/wmem_allocator.h (100%) rename {epan => wsutil}/wmem/wmem_allocator_block.c (100%) rename {epan => wsutil}/wmem/wmem_allocator_block.h (100%) rename {epan => wsutil}/wmem/wmem_allocator_block_fast.c (100%) rename {epan => wsutil}/wmem/wmem_allocator_block_fast.h (100%) rename {epan => wsutil}/wmem/wmem_allocator_simple.c (100%) rename {epan => wsutil}/wmem/wmem_allocator_simple.h (100%) rename {epan => wsutil}/wmem/wmem_allocator_strict.c (100%) rename {epan => wsutil}/wmem/wmem_allocator_strict.h (100%) rename {epan => wsutil}/wmem/wmem_array.c (100%) rename {epan => wsutil}/wmem/wmem_array.h (100%) rename {epan => wsutil}/wmem/wmem_core.c (94%) rename {epan => wsutil}/wmem/wmem_core.h (97%) rename {epan => wsutil}/wmem/wmem_interval_tree.c (100%) rename {epan => wsutil}/wmem/wmem_interval_tree.h (100%) rename {epan => wsutil}/wmem/wmem_list.c (100%) rename {epan => wsutil}/wmem/wmem_list.h (100%) rename {epan => wsutil}/wmem/wmem_map.c (100%) rename {epan => wsutil}/wmem/wmem_map.h (100%) rename {epan => wsutil}/wmem/wmem_map_int.h (100%) rename {epan => wsutil}/wmem/wmem_miscutl.c (100%) rename {epan => wsutil}/wmem/wmem_miscutl.h (100%) rename {epan => wsutil}/wmem/wmem_queue.h (100%) rename {epan => wsutil}/wmem/wmem_stack.c (100%) rename {epan => wsutil}/wmem/wmem_stack.h (100%) rename {epan => wsutil}/wmem/wmem_strbuf.c (100%) rename {epan => wsutil}/wmem/wmem_strbuf.h (100%) rename {epan => wsutil}/wmem/wmem_strutl.c (100%) rename {epan => wsutil}/wmem/wmem_strutl.h (100%) rename {epan => wsutil}/wmem/wmem_test.c (100%) rename {epan => wsutil}/wmem/wmem_tree-int.h (100%) rename {epan => wsutil}/wmem/wmem_tree.c (100%) rename {epan => wsutil}/wmem/wmem_tree.h (100%) rename {epan => wsutil}/wmem/wmem_user_cb.c (100%) rename {epan => wsutil}/wmem/wmem_user_cb.h (100%) rename {epan => wsutil}/wmem/wmem_user_cb_int.h (100%) diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index cb41cfb0a3..54d7448713 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -1913,7 +1913,6 @@ libwireshark.so.0 libwireshark0 #MINVER# uat_update_record@Base 1.99.3 udp_dissect_pdus@Base 1.99.3 udp_port_to_display@Base 1.99.2 - uint64_compare@Base 3.5.0 uint_to_str_back@Base 2.1.0 union_of_tap_listener_flags@Base 1.9.1 unit_name_string_get_value@Base 2.3.0 @@ -2002,108 +2001,11 @@ libwireshark.so.0 libwireshark0 #MINVER# value_is_in_range@Base 1.9.1 value_string_ext_free@Base 1.12.0~rc1 value_string_ext_new@Base 1.9.1 - wmem_alloc0@Base 1.9.1 - wmem_alloc@Base 1.9.1 - wmem_allocator_new@Base 1.9.1 - wmem_array_append@Base 1.12.0~rc1 - wmem_array_bzero@Base 2.1.0 - wmem_array_get_count@Base 1.12.0~rc1 - wmem_array_get_raw@Base 1.12.0~rc1 - wmem_array_grow@Base 3.3.0 - wmem_array_index@Base 1.12.0~rc1 - wmem_array_new@Base 1.12.0~rc1 - wmem_array_set_null_terminator@Base 2.1.0 - wmem_array_sized_new@Base 1.12.0~rc1 - wmem_array_sort@Base 1.12.0~rc1 - wmem_array_try_index@Base 3.1.0 - wmem_ascii_strdown@Base 1.12.0~rc1 - wmem_cleanup@Base 1.12.0~rc1 - wmem_destroy_allocator@Base 1.9.1 - wmem_destroy_array@Base 3.3.0 - wmem_destroy_list@Base 1.12.0~rc1 - wmem_double_hash@Base 1.12.0~rc1 - wmem_epan_scope@Base 1.9.1 - wmem_file_scope@Base 1.9.1 - wmem_free@Base 1.9.1 - wmem_free_all@Base 1.9.1 - wmem_gc@Base 1.9.1 - wmem_init@Base 1.12.0~rc1 - wmem_int64_hash@Base 1.12.0~rc1 - wmem_itree_find_intervals@Base 2.1.0 - wmem_itree_insert@Base 2.1.0 - wmem_itree_is_empty@Base 2.1.0 - wmem_itree_new@Base 2.1.0 - wmem_list_append@Base 1.12.0~rc1 - wmem_list_count@Base 1.12.0~rc1 - wmem_list_find@Base 2.1.0 - wmem_list_find_custom@Base 2.3.0 - wmem_list_foreach@Base 2.1.0 - wmem_list_frame_data@Base 1.12.0~rc1 - wmem_list_frame_next@Base 1.12.0~rc1 - wmem_list_frame_prev@Base 1.12.0~rc1 - wmem_list_head@Base 1.12.0~rc1 - wmem_list_insert_sorted@Base 2.3.0 - wmem_list_new@Base 1.12.0~rc1 - wmem_list_prepend@Base 1.12.0~rc1 - wmem_list_remove@Base 1.12.0~rc1 - wmem_list_remove_frame@Base 1.12.0~rc1 - wmem_list_tail@Base 1.12.0~rc1 - wmem_map_contains@Base 2.5.1 - wmem_map_foreach@Base 2.1.0 - wmem_map_get_keys@Base 2.3.0 - wmem_map_insert@Base 1.12.0~rc1 - wmem_map_lookup@Base 1.12.0~rc1 - wmem_map_lookup_extended@Base 2.5.1 - wmem_map_new@Base 1.12.0~rc1 - wmem_map_new_autoreset@Base 2.3.0 - wmem_map_remove@Base 1.12.0~rc1 - wmem_map_size@Base 2.1.0 - wmem_map_steal@Base 2.3.0 - wmem_memdup@Base 1.12.0~rc1 - wmem_packet_scope@Base 1.9.1 - wmem_realloc@Base 1.9.1 - wmem_register_callback@Base 1.12.0~rc1 - wmem_stack_peek@Base 1.9.1 - wmem_stack_pop@Base 1.9.1 - wmem_str_hash@Base 1.12.0~rc1 - wmem_strbuf_append@Base 1.9.1 - wmem_strbuf_append_c@Base 1.12.0~rc1 - wmem_strbuf_append_len@Base 3.3.1 - wmem_strbuf_append_printf@Base 1.9.1 - wmem_strbuf_append_unichar@Base 1.12.0~rc1 - wmem_strbuf_append_vprintf@Base 3.1.1 - wmem_strbuf_finalize@Base 1.12.0~rc1 - wmem_strbuf_get_len@Base 1.9.1 - wmem_strbuf_get_str@Base 1.9.1 - wmem_strbuf_new@Base 1.9.1 - wmem_strbuf_sized_new@Base 1.9.1 - wmem_strbuf_truncate@Base 1.12.0~rc1 - wmem_strconcat@Base 1.12.0~rc1 - wmem_strdup@Base 1.9.1 - wmem_strdup_printf@Base 1.9.1 - wmem_strdup_vprintf@Base 1.9.1 - wmem_strjoin@Base 2.5.1 - wmem_strjoinv@Base 2.5.1 - wmem_strndup@Base 1.9.1 - wmem_strong_hash@Base 1.12.0~rc1 - wmem_strsplit@Base 1.12.0~rc1 - wmem_tree_count@Base 2.3.0 - wmem_tree_destroy@Base 2.3.0 - wmem_tree_foreach@Base 1.12.0~rc1 - wmem_tree_insert32@Base 1.12.0~rc1 - wmem_tree_insert32_array@Base 1.12.0~rc1 - wmem_tree_insert_string@Base 1.12.0~rc1 - wmem_tree_is_empty@Base 1.12.0~rc1 - wmem_tree_lookup32@Base 1.12.0~rc1 - wmem_tree_lookup32_array@Base 1.12.0~rc1 - wmem_tree_lookup32_array_le@Base 1.12.0~rc1 - wmem_tree_lookup32_le@Base 1.12.0~rc1 - wmem_tree_lookup_string@Base 1.12.0~rc1 - wmem_tree_new@Base 1.12.0~rc1 - wmem_tree_new_autoreset@Base 1.12.0~rc1 - wmem_tree_remove_string@Base 1.99.9 - wmem_tree_remove32@Base 2.3.0 - wmem_unregister_callback@Base 1.12.0~rc1 + wmem_cleanup_scopes@Base 3.5.0 + wmem_epan_scope@Base 3.5.0 + wmem_init_scopes@Base 3.5.0 + wmem_packet_scope@Base 3.5.0 + wmem_file_scope@Base 3.5.0 word_to_hex@Base 2.1.0 write_carrays_hex_data@Base 1.99.1 write_csv_column_titles@Base 1.99.1 diff --git a/debian/libwsutil-dev.install b/debian/libwsutil-dev.install index ef9f0d6527..2284dee2ea 100644 --- a/debian/libwsutil-dev.install +++ b/debian/libwsutil-dev.install @@ -4,3 +4,4 @@ ws_compiler_tests.h usr/include/wireshark ws_diag_control.h usr/include/wireshark ws_symbol_export.h usr/include/wireshark wsutil/*.h usr/include/wireshark/wsutil +wsutil/wmem/*.h usr/include/wireshark/wsutil/wmem diff --git a/debian/libwsutil0.symbols b/debian/libwsutil0.symbols index 5885cf0d90..9746c18ec0 100644 --- a/debian/libwsutil0.symbols +++ b/debian/libwsutil0.symbols @@ -195,10 +195,116 @@ libwsutil.so.0 libwsutil0 #MINVER# tm_is_valid@Base 3.5.0 type_util_gdouble_to_guint64@Base 1.10.0 type_util_guint64_to_gdouble@Base 1.10.0 + uint64_compare@Base 3.5.0 ulaw2linear@Base 1.12.0~rc1 unix_epoch_to_nstime@Base 3.5.0 update_adler32@Base 1.12.0~rc1 update_crc10_by_bytes@Base 1.10.0 + wmem_alloc0@Base 3.5.0 + wmem_alloc@Base 3.5.0 + wmem_allocator_new@Base 3.5.0 + wmem_array_append@Base 3.5.0 + wmem_array_bzero@Base 3.5.0 + wmem_array_get_count@Base 3.5.0 + wmem_array_get_raw@Base 3.5.0 + wmem_array_grow@Base 3.5.0 + wmem_array_index@Base 3.5.0 + wmem_array_new@Base 3.5.0 + wmem_array_set_null_terminator@Base 3.5.0 + wmem_array_sized_new@Base 3.5.0 + wmem_array_sort@Base 3.5.0 + wmem_array_try_index@Base 3.5.0 + wmem_ascii_strdown@Base 3.5.0 + wmem_cleanup@Base 3.5.0 + wmem_destroy_allocator@Base 3.5.0 + wmem_destroy_array@Base 3.5.0 + wmem_destroy_list@Base 3.5.0 + wmem_double_hash@Base 3.5.0 + wmem_enter_scope@Base 3.5.0 + wmem_epan_scope@Base 3.5.0 + wmem_file_scope@Base 3.5.0 + wmem_free@Base 3.5.0 + wmem_free_all@Base 3.5.0 + wmem_gc@Base 3.5.0 + wmem_in_scope@Base 3.5.0 + wmem_init@Base 3.5.0 + wmem_int64_hash@Base 3.5.0 + wmem_itree_find_intervals@Base 3.5.0 + wmem_itree_insert@Base 3.5.0 + wmem_itree_is_empty@Base 3.5.0 + wmem_itree_new@Base 3.5.0 + wmem_leave_scope@Base 3.5.0 + wmem_list_append@Base 3.5.0 + wmem_list_count@Base 3.5.0 + wmem_list_find@Base 3.5.0 + wmem_list_find_custom@Base 3.5.0 + wmem_list_foreach@Base 3.5.0 + wmem_list_frame_data@Base 3.5.0 + wmem_list_frame_next@Base 3.5.0 + wmem_list_frame_prev@Base 3.5.0 + wmem_list_head@Base 3.5.0 + wmem_list_insert_sorted@Base 3.5.0 + wmem_list_new@Base 3.5.0 + wmem_list_prepend@Base 3.5.0 + wmem_list_remove@Base 3.5.0 + wmem_list_remove_frame@Base 3.5.0 + wmem_list_tail@Base 3.5.0 + wmem_map_contains@Base 3.5.0 + wmem_map_foreach@Base 3.5.0 + wmem_map_get_keys@Base 3.5.0 + wmem_map_insert@Base 3.5.0 + wmem_map_lookup@Base 3.5.0 + wmem_map_lookup_extended@Base 3.5.0 + wmem_map_new@Base 3.5.0 + wmem_map_new_autoreset@Base 3.5.0 + wmem_map_remove@Base 3.5.0 + wmem_map_size@Base 3.5.0 + wmem_map_steal@Base 3.5.0 + wmem_memdup@Base 3.5.0 + wmem_packet_scope@Base 3.5.0 + wmem_realloc@Base 3.5.0 + wmem_register_callback@Base 3.5.0 + wmem_stack_peek@Base 3.5.0 + wmem_stack_pop@Base 3.5.0 + wmem_str_hash@Base 3.5.0 + wmem_strbuf_append@Base 3.5.0 + wmem_strbuf_append_c@Base 3.5.0 + wmem_strbuf_append_len@Base 3.5.0 + wmem_strbuf_append_printf@Base 3.5.0 + wmem_strbuf_append_unichar@Base 3.5.0 + wmem_strbuf_append_vprintf@Base 3.5.0 + wmem_strbuf_finalize@Base 3.5.0 + wmem_strbuf_get_len@Base 3.5.0 + wmem_strbuf_get_str@Base 3.5.0 + wmem_strbuf_new@Base 3.5.0 + wmem_strbuf_sized_new@Base 3.5.0 + wmem_strbuf_truncate@Base 3.5.0 + wmem_strconcat@Base 3.5.0 + wmem_strdup@Base 3.5.0 + wmem_strdup_printf@Base 3.5.0 + wmem_strdup_vprintf@Base 3.5.0 + wmem_strjoin@Base 3.5.0 + wmem_strjoinv@Base 3.5.0 + wmem_strndup@Base 3.5.0 + wmem_strong_hash@Base 3.5.0 + wmem_strsplit@Base 3.5.0 + wmem_tree_count@Base 3.5.0 + wmem_tree_destroy@Base 3.5.0 + wmem_tree_foreach@Base 3.5.0 + wmem_tree_insert32@Base 3.5.0 + wmem_tree_insert32_array@Base 3.5.0 + wmem_tree_insert_string@Base 3.5.0 + wmem_tree_is_empty@Base 3.5.0 + wmem_tree_lookup32@Base 3.5.0 + wmem_tree_lookup32_array@Base 3.5.0 + wmem_tree_lookup32_array_le@Base 3.5.0 + wmem_tree_lookup32_le@Base 3.5.0 + wmem_tree_lookup_string@Base 3.5.0 + wmem_tree_new@Base 3.5.0 + wmem_tree_new_autoreset@Base 3.5.0 + wmem_tree_remove_string@Base 3.5.0 + wmem_tree_remove32@Base 3.5.0 + wmem_unregister_callback@Base 3.5.0 write_file_binary_mode@Base 3.5.0 ws_add_crash_info@Base 1.10.0 ws_ascii_strnatcasecmp@Base 1.99.1 diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 027d0384b1..b8f00f352c 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -22,7 +22,6 @@ add_subdirectory(crypt) add_subdirectory(dfilter) add_subdirectory(dissectors) add_subdirectory(ftypes) -add_subdirectory(wmem) if(LUA_FOUND) add_subdirectory(wslua) @@ -161,6 +160,8 @@ set(LIBWIRESHARK_PUBLIC_HEADERS uat-int.h unit_strings.h value_string.h + wmem/wmem.h + wmem/wmem_scopes.h x264_prt_id.h xdlc.h ) @@ -258,6 +259,7 @@ set(LIBWIRESHARK_NONGENERATED_FILES uat.c value_string.c unit_strings.c + wmem/wmem_scopes.c xdlc.c protobuf-helper.c protobuf_lang_tree.c @@ -296,7 +298,6 @@ add_library(epan $ $ $ - $ $<$:$> ${CMAKE_BINARY_DIR}/image/libwireshark.rc ) diff --git a/epan/epan.c b/epan/epan.c index 1eea3d1906..ec0a5adbad 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -253,7 +253,7 @@ epan_init(register_cb cb, gpointer client_data, gboolean load_plugins) * invocation just in case. */ /* initialize memory allocation subsystem */ - wmem_init(); + wmem_init_scopes(); /* initialize the GUID to name mapping table */ guids_init(); @@ -425,7 +425,7 @@ epan_cleanup(void) pinfo_pool_cache = NULL; } - wmem_cleanup(); + wmem_cleanup_scopes(); } struct epan_session { diff --git a/epan/oids_test.c b/epan/oids_test.c index cc27955256..f8e2c2f547 100644 --- a/epan/oids_test.c +++ b/epan/oids_test.c @@ -510,13 +510,13 @@ main(int argc, char **argv) g_test_add_func("/oids/add/encoded", oids_test_add_encoded); g_test_add_func("/oids/add/string", oids_test_add_string); - wmem_init(); + wmem_init_scopes(); test_scope = wmem_allocator_new(WMEM_ALLOCATOR_STRICT); oids_init(); result = g_test_run(); oids_cleanup(); wmem_destroy_allocator(test_scope); - wmem_cleanup(); + wmem_cleanup_scopes(); return result; } diff --git a/epan/wmem/wmem.h b/epan/wmem/wmem.h index 2827301a6d..e09dd2a518 100644 --- a/epan/wmem/wmem.h +++ b/epan/wmem/wmem.h @@ -1,5 +1,5 @@ /* wmem.h - * Definitions for the Wireshark Memory Manager + * Definitions for the EPAN Memory Manager scopes * Copyright 2012, Evan Huus * * Wireshark - Network traffic analyzer @@ -9,24 +9,12 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef __WMEM_H__ -#define __WMEM_H__ +#ifndef __EPAN_WMEM_H__ +#define __EPAN_WMEM_H__ -#include "wmem_array.h" -#include "wmem_core.h" -#include "wmem_list.h" -#include "wmem_map.h" -#include "wmem_miscutl.h" -#include "wmem_queue.h" #include "wmem_scopes.h" -#include "wmem_stack.h" -#include "wmem_strbuf.h" -#include "wmem_strutl.h" -#include "wmem_tree.h" -#include "wmem_interval_tree.h" -#include "wmem_user_cb.h" -#endif /* __WMEM_H__ */ +#endif /* __EPAN_WMEM_H__ */ /* * Editor modelines - https://www.wireshark.org/tools/modelines.html diff --git a/epan/wmem/wmem_scopes.c b/epan/wmem/wmem_scopes.c index 0daddd56f9..d8385d74d6 100644 --- a/epan/wmem/wmem_scopes.c +++ b/epan/wmem/wmem_scopes.c @@ -11,10 +11,9 @@ #include -#include "wmem-int.h" -#include "wmem_core.h" #include "wmem_scopes.h" -#include "wmem_allocator.h" + +#include /* One of the supposed benefits of wmem over the old emem was going to be that * the scoping of the various memory pools would be obvious, since they would @@ -46,7 +45,7 @@ static wmem_allocator_t *epan_scope = NULL; wmem_allocator_t * wmem_packet_scope(void) { - ASSERT(packet_scope); + ws_assert(packet_scope); return packet_scope; } @@ -54,21 +53,20 @@ wmem_packet_scope(void) void wmem_enter_packet_scope(void) { - ASSERT(packet_scope); - ASSERT(file_scope->in_scope); - ASSERT(!packet_scope->in_scope); + ws_assert(packet_scope); + ws_assert(wmem_in_scope(file_scope)); + ws_assert(!wmem_in_scope(packet_scope)); - packet_scope->in_scope = TRUE; + wmem_enter_scope(packet_scope); } void wmem_leave_packet_scope(void) { - ASSERT(packet_scope); - ASSERT(packet_scope->in_scope); + ws_assert(packet_scope); + ws_assert(wmem_in_scope(packet_scope)); - wmem_free_all(packet_scope); - packet_scope->in_scope = FALSE; + wmem_leave_scope(packet_scope); } /* File Scope */ @@ -76,7 +74,7 @@ wmem_leave_packet_scope(void) wmem_allocator_t * wmem_file_scope(void) { - ASSERT(file_scope); + ws_assert(file_scope); return file_scope; } @@ -84,21 +82,20 @@ wmem_file_scope(void) void wmem_enter_file_scope(void) { - ASSERT(file_scope); - ASSERT(!file_scope->in_scope); + ws_assert(file_scope); + ws_assert(!wmem_in_scope(file_scope)); - file_scope->in_scope = TRUE; + wmem_enter_scope(file_scope); } void wmem_leave_file_scope(void) { - ASSERT(file_scope); - ASSERT(file_scope->in_scope); - ASSERT(!packet_scope->in_scope); + ws_assert(file_scope); + ws_assert(wmem_in_scope(file_scope)); + ws_assert(!wmem_in_scope(packet_scope)); - wmem_free_all(file_scope); - file_scope->in_scope = FALSE; + wmem_leave_scope(file_scope); /* this seems like a good time to do garbage collection */ wmem_gc(file_scope); @@ -110,7 +107,7 @@ wmem_leave_file_scope(void) wmem_allocator_t * wmem_epan_scope(void) { - ASSERT(epan_scope); + ws_assert(epan_scope); return epan_scope; } @@ -120,33 +117,37 @@ wmem_epan_scope(void) void wmem_init_scopes(void) { - ASSERT(packet_scope == NULL); - ASSERT(file_scope == NULL); - ASSERT(epan_scope == NULL); + ws_assert(packet_scope == NULL); + ws_assert(file_scope == NULL); + ws_assert(epan_scope == NULL); + + wmem_init(); packet_scope = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK_FAST); file_scope = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK); epan_scope = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK); /* Scopes are initialized to TRUE by default on creation */ - packet_scope->in_scope = FALSE; - file_scope->in_scope = FALSE; + wmem_leave_scope(packet_scope); + wmem_leave_scope(file_scope); } void wmem_cleanup_scopes(void) { - ASSERT(packet_scope); - ASSERT(file_scope); - ASSERT(epan_scope); + ws_assert(packet_scope); + ws_assert(file_scope); + ws_assert(epan_scope); - ASSERT(packet_scope->in_scope == FALSE); - ASSERT(file_scope->in_scope == FALSE); + ws_assert(!wmem_in_scope(packet_scope)); + ws_assert(!wmem_in_scope(file_scope)); wmem_destroy_allocator(packet_scope); wmem_destroy_allocator(file_scope); wmem_destroy_allocator(epan_scope); + wmem_cleanup(); + packet_scope = NULL; file_scope = NULL; epan_scope = NULL; diff --git a/epan/wmem/wmem_scopes.h b/epan/wmem/wmem_scopes.h index 5e3fb1cc2d..5980870b7f 100644 --- a/epan/wmem/wmem_scopes.h +++ b/epan/wmem/wmem_scopes.h @@ -12,7 +12,7 @@ #ifndef __WMEM_SCOPES_H__ #define __WMEM_SCOPES_H__ -#include "wmem_core.h" +#include #ifdef __cplusplus extern "C" { @@ -54,11 +54,11 @@ wmem_leave_file_scope(void); /* Scope Management */ -WS_DLL_LOCAL +WS_DLL_PUBLIC void wmem_init_scopes(void); -WS_DLL_LOCAL +WS_DLL_PUBLIC void wmem_cleanup_scopes(void); diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 9e9b62c89c..e636bb3196 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -11,6 +11,8 @@ add_definitions(-DPLUGIN_DIR=\"${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_LIBDIR}\ add_definitions(-DEXTCAP_DIR=\"${CMAKE_INSTALL_PREFIX}/${EXTCAP_INSTALL_LIBDIR}\") add_definitions(-DDATA_DIR=\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}\") +add_subdirectory(wmem) + set(WSUTIL_PUBLIC_HEADERS 802_11-utils.h adler32.h @@ -248,6 +250,7 @@ endif() add_library(wsutil ${WSUTIL_FILES} + $ ${CMAKE_BINARY_DIR}/image/libwsutil.rc ) diff --git a/epan/wmem/CMakeLists.txt b/wsutil/wmem/CMakeLists.txt similarity index 94% rename from epan/wmem/CMakeLists.txt rename to wsutil/wmem/CMakeLists.txt index fc58e5f781..d3d4e88db5 100644 --- a/epan/wmem/CMakeLists.txt +++ b/wsutil/wmem/CMakeLists.txt @@ -15,7 +15,6 @@ set(WMEM_PUBLIC_HEADERS wmem_map.h wmem_miscutl.h wmem_queue.h - wmem_scopes.h wmem_stack.h wmem_strbuf.h wmem_strutl.h @@ -48,7 +47,6 @@ set(WMEM_FILES wmem_list.c wmem_map.c wmem_miscutl.c - wmem_scopes.c wmem_stack.c wmem_strbuf.c wmem_strutl.c @@ -77,7 +75,7 @@ target_include_directories(wmem ) set_target_properties(wmem PROPERTIES - FOLDER "Libs/epan/wmem" + FOLDER "Libs/wsutil/wmem" COMPILE_DEFINITIONS "WS_BUILD_DLL" ) @@ -92,7 +90,7 @@ set_target_properties(wmem_test PROPERTIES ) install(FILES ${WMEM_PUBLIC_HEADERS} - DESTINATION "${PROJECT_INSTALL_INCLUDEDIR}/epan/wmem" + DESTINATION "${PROJECT_INSTALL_INCLUDEDIR}/wsutil/wmem" ) CHECKAPI( diff --git a/epan/wmem/wmem-int.h b/wsutil/wmem/wmem-int.h similarity index 100% rename from epan/wmem/wmem-int.h rename to wsutil/wmem/wmem-int.h diff --git a/wsutil/wmem/wmem.h b/wsutil/wmem/wmem.h new file mode 100644 index 0000000000..65f06fdc04 --- /dev/null +++ b/wsutil/wmem/wmem.h @@ -0,0 +1,41 @@ +/* wmem.h + * Definitions for the Wireshark Memory Manager + * Copyright 2012, Evan Huus + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __WMEM_H__ +#define __WMEM_H__ + +#include "wmem_array.h" +#include "wmem_core.h" +#include "wmem_list.h" +#include "wmem_map.h" +#include "wmem_miscutl.h" +#include "wmem_queue.h" +#include "wmem_stack.h" +#include "wmem_strbuf.h" +#include "wmem_strutl.h" +#include "wmem_tree.h" +#include "wmem_interval_tree.h" +#include "wmem_user_cb.h" + +#endif /* __WMEM_H__ */ + +/* + * Editor modelines - https://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/wsutil/wmem/wmem_allocator.h similarity index 100% rename from epan/wmem/wmem_allocator.h rename to wsutil/wmem/wmem_allocator.h diff --git a/epan/wmem/wmem_allocator_block.c b/wsutil/wmem/wmem_allocator_block.c similarity index 100% rename from epan/wmem/wmem_allocator_block.c rename to wsutil/wmem/wmem_allocator_block.c diff --git a/epan/wmem/wmem_allocator_block.h b/wsutil/wmem/wmem_allocator_block.h similarity index 100% rename from epan/wmem/wmem_allocator_block.h rename to wsutil/wmem/wmem_allocator_block.h diff --git a/epan/wmem/wmem_allocator_block_fast.c b/wsutil/wmem/wmem_allocator_block_fast.c similarity index 100% rename from epan/wmem/wmem_allocator_block_fast.c rename to wsutil/wmem/wmem_allocator_block_fast.c diff --git a/epan/wmem/wmem_allocator_block_fast.h b/wsutil/wmem/wmem_allocator_block_fast.h similarity index 100% rename from epan/wmem/wmem_allocator_block_fast.h rename to wsutil/wmem/wmem_allocator_block_fast.h diff --git a/epan/wmem/wmem_allocator_simple.c b/wsutil/wmem/wmem_allocator_simple.c similarity index 100% rename from epan/wmem/wmem_allocator_simple.c rename to wsutil/wmem/wmem_allocator_simple.c diff --git a/epan/wmem/wmem_allocator_simple.h b/wsutil/wmem/wmem_allocator_simple.h similarity index 100% rename from epan/wmem/wmem_allocator_simple.h rename to wsutil/wmem/wmem_allocator_simple.h diff --git a/epan/wmem/wmem_allocator_strict.c b/wsutil/wmem/wmem_allocator_strict.c similarity index 100% rename from epan/wmem/wmem_allocator_strict.c rename to wsutil/wmem/wmem_allocator_strict.c diff --git a/epan/wmem/wmem_allocator_strict.h b/wsutil/wmem/wmem_allocator_strict.h similarity index 100% rename from epan/wmem/wmem_allocator_strict.h rename to wsutil/wmem/wmem_allocator_strict.h diff --git a/epan/wmem/wmem_array.c b/wsutil/wmem/wmem_array.c similarity index 100% rename from epan/wmem/wmem_array.c rename to wsutil/wmem/wmem_array.c diff --git a/epan/wmem/wmem_array.h b/wsutil/wmem/wmem_array.h similarity index 100% rename from epan/wmem/wmem_array.h rename to wsutil/wmem/wmem_array.h diff --git a/epan/wmem/wmem_core.c b/wsutil/wmem/wmem_core.c similarity index 94% rename from epan/wmem/wmem_core.c rename to wsutil/wmem/wmem_core.c index 64b74fcc1d..a49730088d 100644 --- a/epan/wmem/wmem_core.c +++ b/wsutil/wmem/wmem_core.c @@ -15,7 +15,6 @@ #include "wmem-int.h" #include "wmem_core.h" -#include "wmem_scopes.h" #include "wmem_map_int.h" #include "wmem_user_cb_int.h" #include "wmem_allocator.h" @@ -199,16 +198,34 @@ wmem_init(void) } } - wmem_init_scopes(); wmem_init_hashing(); } void wmem_cleanup(void) { - wmem_cleanup_scopes(); } +void +wmem_enter_scope(wmem_allocator_t *allocator) +{ + allocator->in_scope = TRUE; +} + +void +wmem_leave_scope(wmem_allocator_t *allocator) +{ + wmem_free_all(allocator); + allocator->in_scope = FALSE; +} + +gboolean +wmem_in_scope(wmem_allocator_t *allocator) +{ + return allocator->in_scope; +} + + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/epan/wmem/wmem_core.h b/wsutil/wmem/wmem_core.h similarity index 97% rename from epan/wmem/wmem_core.h rename to wsutil/wmem/wmem_core.h index 8ad169bf03..70330375a6 100644 --- a/epan/wmem/wmem_core.h +++ b/wsutil/wmem/wmem_core.h @@ -210,6 +210,18 @@ WS_DLL_PUBLIC void wmem_cleanup(void); +WS_DLL_PUBLIC +void +wmem_enter_scope(wmem_allocator_t *allocator); + +WS_DLL_PUBLIC +void +wmem_leave_scope(wmem_allocator_t *allocator); + +WS_DLL_PUBLIC +gboolean +wmem_in_scope(wmem_allocator_t *allocator); + /** @} */ #ifdef __cplusplus diff --git a/epan/wmem/wmem_interval_tree.c b/wsutil/wmem/wmem_interval_tree.c similarity index 100% rename from epan/wmem/wmem_interval_tree.c rename to wsutil/wmem/wmem_interval_tree.c diff --git a/epan/wmem/wmem_interval_tree.h b/wsutil/wmem/wmem_interval_tree.h similarity index 100% rename from epan/wmem/wmem_interval_tree.h rename to wsutil/wmem/wmem_interval_tree.h diff --git a/epan/wmem/wmem_list.c b/wsutil/wmem/wmem_list.c similarity index 100% rename from epan/wmem/wmem_list.c rename to wsutil/wmem/wmem_list.c diff --git a/epan/wmem/wmem_list.h b/wsutil/wmem/wmem_list.h similarity index 100% rename from epan/wmem/wmem_list.h rename to wsutil/wmem/wmem_list.h diff --git a/epan/wmem/wmem_map.c b/wsutil/wmem/wmem_map.c similarity index 100% rename from epan/wmem/wmem_map.c rename to wsutil/wmem/wmem_map.c diff --git a/epan/wmem/wmem_map.h b/wsutil/wmem/wmem_map.h similarity index 100% rename from epan/wmem/wmem_map.h rename to wsutil/wmem/wmem_map.h diff --git a/epan/wmem/wmem_map_int.h b/wsutil/wmem/wmem_map_int.h similarity index 100% rename from epan/wmem/wmem_map_int.h rename to wsutil/wmem/wmem_map_int.h diff --git a/epan/wmem/wmem_miscutl.c b/wsutil/wmem/wmem_miscutl.c similarity index 100% rename from epan/wmem/wmem_miscutl.c rename to wsutil/wmem/wmem_miscutl.c diff --git a/epan/wmem/wmem_miscutl.h b/wsutil/wmem/wmem_miscutl.h similarity index 100% rename from epan/wmem/wmem_miscutl.h rename to wsutil/wmem/wmem_miscutl.h diff --git a/epan/wmem/wmem_queue.h b/wsutil/wmem/wmem_queue.h similarity index 100% rename from epan/wmem/wmem_queue.h rename to wsutil/wmem/wmem_queue.h diff --git a/epan/wmem/wmem_stack.c b/wsutil/wmem/wmem_stack.c similarity index 100% rename from epan/wmem/wmem_stack.c rename to wsutil/wmem/wmem_stack.c diff --git a/epan/wmem/wmem_stack.h b/wsutil/wmem/wmem_stack.h similarity index 100% rename from epan/wmem/wmem_stack.h rename to wsutil/wmem/wmem_stack.h diff --git a/epan/wmem/wmem_strbuf.c b/wsutil/wmem/wmem_strbuf.c similarity index 100% rename from epan/wmem/wmem_strbuf.c rename to wsutil/wmem/wmem_strbuf.c diff --git a/epan/wmem/wmem_strbuf.h b/wsutil/wmem/wmem_strbuf.h similarity index 100% rename from epan/wmem/wmem_strbuf.h rename to wsutil/wmem/wmem_strbuf.h diff --git a/epan/wmem/wmem_strutl.c b/wsutil/wmem/wmem_strutl.c similarity index 100% rename from epan/wmem/wmem_strutl.c rename to wsutil/wmem/wmem_strutl.c diff --git a/epan/wmem/wmem_strutl.h b/wsutil/wmem/wmem_strutl.h similarity index 100% rename from epan/wmem/wmem_strutl.h rename to wsutil/wmem/wmem_strutl.h diff --git a/epan/wmem/wmem_test.c b/wsutil/wmem/wmem_test.c similarity index 100% rename from epan/wmem/wmem_test.c rename to wsutil/wmem/wmem_test.c diff --git a/epan/wmem/wmem_tree-int.h b/wsutil/wmem/wmem_tree-int.h similarity index 100% rename from epan/wmem/wmem_tree-int.h rename to wsutil/wmem/wmem_tree-int.h diff --git a/epan/wmem/wmem_tree.c b/wsutil/wmem/wmem_tree.c similarity index 100% rename from epan/wmem/wmem_tree.c rename to wsutil/wmem/wmem_tree.c diff --git a/epan/wmem/wmem_tree.h b/wsutil/wmem/wmem_tree.h similarity index 100% rename from epan/wmem/wmem_tree.h rename to wsutil/wmem/wmem_tree.h diff --git a/epan/wmem/wmem_user_cb.c b/wsutil/wmem/wmem_user_cb.c similarity index 100% rename from epan/wmem/wmem_user_cb.c rename to wsutil/wmem/wmem_user_cb.c diff --git a/epan/wmem/wmem_user_cb.h b/wsutil/wmem/wmem_user_cb.h similarity index 100% rename from epan/wmem/wmem_user_cb.h rename to wsutil/wmem/wmem_user_cb.h diff --git a/epan/wmem/wmem_user_cb_int.h b/wsutil/wmem/wmem_user_cb_int.h similarity index 100% rename from epan/wmem/wmem_user_cb_int.h rename to wsutil/wmem/wmem_user_cb_int.h