Commit Graph

54 Commits

Author SHA1 Message Date
John Thacker b5917d0182 wmem: Add a multimap
A number of protocols have IDs that can be reused that are used as
lookup keys. In most cases the frame number should be used as well
to differentiate repeat appearances of an ID. For response/request
matching, it is frequently useful to find the most recent frame number
(greatest value less than or equal to the current one) that contained
an ID.

We can achieve that by using a multimap that stores values with a given
ID in a tree keyed with the frame number. This works better than using
a map or a tree alone:

1) A map isn't ordered, so doesn't allow for less than or equal comparison.
2) Using a tree requires an ordering on all the ID components, and then
   having to test all the components other than the frame number separately
   for equality after retrieval.

Currently the multimap does not support inserting items without specifying
the tree key (and having the multimap generate a key), because the total
capacity of trees (including deleted nodes) is not tracked. If other use
cases are needed, this could be added later along with more generic
multimap support.

Use a multimap in ANSI MAP, ANSI TCAP, and GSM SMS, all of which need to
match lookup IDs that can be reused. Fix #7653.
2021-11-21 07:16:55 -05:00
João Valverde 133b0c583f Move epan/wmem/wmem_scopes.h to epan/
This header was installed incorrectly to epan/wmem_scopes.h.

Instead of creating additional installation rules for a single
header in a subfolder (kept for backward compatibility) just
rename the standard "epan/wmem/wmem.h" include to
"epan/wmem_scopes.h" and fix the documentation.

Now the header is installed *correctly* to epan/wmem_scopes.h.
2021-07-26 14:56:11 +00:00
Evan Huus d6d7dd1e56 First pass pinfo->pool conversion
Automated find/replace of wmem_packet_scope() with pinfo->pool in all
files where it didn't cause a build failure.

I also tweaked a few of the docs which got caught up.
2021-07-21 05:38:29 +00:00
Gerald Combs 58da452d22 Test: Remove the Bash test scripts.
They've been replaced by the Python scripts.

Change-Id: I8add9c9ea0a6bdd68b2fa3841977863c0ea9a761
Reviewed-on: https://code.wireshark.org/review/27243
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-05-02 04:09:26 +00:00
Dario Lombardo 37649c4d0f doc: fix typos.
Change-Id: Id34affcb33c00e224dafbccc347b1d91b9e74c8d
Reviewed-on: https://code.wireshark.org/review/16914
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-08-06 00:31:23 +00:00
Michael Mann 4d4190f127 Have wmem conform to checkAPIs.pl
Yes, the rename of structure members is a bit hacky.
Yes, catering to Windows since "GLib's v*printf routines are
surprisingly slow on Windows".
But it does pass checkAPIs.pl

Change-Id: I5b1552472c83aa2e159f17b5b7eb70b37d03eff9
Reviewed-on: https://code.wireshark.org/review/15404
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-05-13 16:00:58 +00:00
Evan Huus 66bea399cf Update README.wmem
It was getting stale in a few places, and I added a bunch of detail after
discussions on https://code.wireshark.org/review/15270.

Change-Id: Icd5ad954c4fbf592df0be63e6fb9440565a8efc1
Reviewed-on: https://code.wireshark.org/review/15280
Reviewed-by: Evan Huus <eapache@gmail.com>
2016-05-07 02:16:21 +00:00
Evan Huus febc842521 Update README.wmem, release notes for emem removal
Change-Id: Iac5066ff97d26de1660c38b9cd3f17781a521823
Reviewed-on: https://code.wireshark.org/review/6949
Reviewed-by: Evan Huus <eapache@gmail.com>
2015-02-04 15:03:45 +00:00
Hadriel Kaplan aec1bcf9a1 Lua can free tvbuffs too early
Lua-created tvbuffs should be kept around for the duration of pinfo's
lifetime, instead of only for the duration of frame dissection. So
instead of using the frame dissector's frame_end_routine, we'll register
a callback to wmem for pinfo pool's allocator.

Bug: 10888
Change-Id: I3e9db671c3f2a7cab9e258aca17f3be8acaf2417
Reviewed-on: https://code.wireshark.org/review/6768
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Hadriel Kaplan <hadrielk@yahoo.com>
2015-01-25 19:11:01 +00:00
Gerald Combs 175039128a Update the doc directory to use https://www.wireshark.org.
Change-Id: I9bfc57cb6b6ab6962b80ff58d98eb351d6f69829
Reviewed-on: https://code.wireshark.org/review/4140
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2014-09-17 00:12:26 +00:00
Evan Huus d7f1ac33f6 wmem documentation updates
Change-Id: Ief20460ed8ec1b4bd1286cc2a5490d9aeefdf98f
Reviewed-on: https://code.wireshark.org/review/1643
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-05-14 20:05:14 +00:00
Evan Huus df77e26485 Fix some wmem-related documentation.
Discovered while reviewing Ibd3efb92a203861f507ce71bc8d04d19d9d38a93

Change-Id: Ie4dfc1b9b7a99f14657148ed5a935bbb079c2b4e
Reviewed-on: https://code.wireshark.org/review/415
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-02-26 22:25:22 +00:00
Jeff Morriss b6a9b8494c Remove $Id$ and other Subversion leftovers from the doc files.
Change-Id: I28a376f7e0fd90971f65ae9c1105a3ec85221470
Reviewed-on: https://code.wireshark.org/review/204
Reviewed-by: Jeff Morriss <jeff.morriss.ws@gmail.com>
2014-02-14 01:33:14 +00:00
Bill Meier 8ab9c55618 From Ville Skyttä: Spelling Fixes
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9591


svn path=/trunk/; revision=54387
2013-12-23 15:53:13 +00:00
Evan Huus 828eae73ce Document that pinfo-scoped memory is also needed for anything passed to
add_new_data_source().

svn path=/trunk/; revision=50911
2013-07-26 13:06:50 +00:00
Evan Huus 037fc022da Add wmem queue 'implementation' by wrapping wmem_list and wmem_stack.
Also a bit of misc. refactoring of the stack while I was there, and doc tweaks.

svn path=/trunk/; revision=50769
2013-07-21 21:13:30 +00:00
Evan Huus 6635f5ef67 Replace wmem slist (singly-linked) with wmem list (doubly-linked).
The overhead is not large, and it makes append much faster (O(1) vs O(n)).

It also will make a queue easy to add, which I need for a dissector I'm
writing...

svn path=/trunk/; revision=50744
2013-07-20 20:33:38 +00:00
Evan Huus c574f7d1ea Simple growable array implementation for wmem.
svn path=/trunk/; revision=50400
2013-07-06 04:02:08 +00:00
Evan Huus 8e060a2ad5 Update READMEs.
svn path=/trunk/; revision=50020
2013-06-18 21:47:18 +00:00
Evan Huus 80c51f1df0 Update wmem README for the tree implementation.
svn path=/trunk/; revision=49967
2013-06-16 22:08:56 +00:00
Evan Huus a9c35aa4b6 First batch of doxygen for wmem. Remove some things from README.wmem now that
they're in doxygen instead.

svn path=/trunk/; revision=49583
2013-05-26 02:40:40 +00:00
Evan Huus 5426ba4e02 Minor refactor: make the framework responsible for allocating and freeing the
actual wmem_allocator_t structure. This simplifies the internal API and
deduplicates a few alloc/free calls in the individual allocator implementations.

I'd originally made the allocators responsible for this on purpose with the
idea that they'd be able to optimize something clever based on the type of
allocator, but that's clearly more work and complexity than it's worth given
the small number of allocators we create/destroy.

svn path=/trunk/; revision=49512
2013-05-22 15:42:12 +00:00
Evan Huus f2bdbd2b32 Use a readable name for the wmem callback test. Warn that reallocing memory
for which a callback is registered is also a fairly stupid thing to do.

svn path=/trunk/; revision=49354
2013-05-16 23:38:31 +00:00
Evan Huus d860a01aaf Round two of wmem cleanup callbacks. While the emem tree behaviour will require
recurring callbacks, I suspect most other potential uses will be once-only, so
make that possible, and improve the documentation on the remaining issues.

Also separate out the code into its own files and the testing into its own
test case.

svn path=/trunk/; revision=49209
2013-05-08 01:14:01 +00:00
Evan Huus 2e92c6dfde Add user callbacks to wmem. This feature is a generic way to transparently mimic
the behaviour emem has for seasonal trees, which is that the master tree
structure is not actually seasonal - it is permanent. When the seasonal memory
pool is cleared, the root node pointer in all of these permanent trees is set
to NULL, and the pool takes care of actually freeing the nodes.

Wmem can now mimic this by allocating the tree header struct in epan_scope(),
allocating any node structs in file_scope(), and registering a callback on
file_scope() that NULLs the pointer in the epan_scope() header. Yes, this is
confusing, but it seemed simpler than adding manual callback registrations to
every single dissector that currently uses seasonal trees.

The callbacks may also be useful for other things that need cleanup (I'm
thinking resource handles stored in wmem memory that need to be fclosed or
what-have-you before they the handle is lost).

As indicated by the number of caveats in README.wmem, the implementation
probably needs a bit of work to make it safer/saner/more-useful. Thoughts
(or patches!) in this direction are more than welcome.

svn path=/trunk/; revision=49205
2013-05-07 19:23:10 +00:00
Evan Huus f19efd05f7 Remove singly-linked list from the wmem TODO list. Now that it has append
all of the really important stuff is there, and emem doesn't provide it at all
so it's not blocking migration.

svn path=/trunk/; revision=49103
2013-05-01 01:09:57 +00:00
Evan Huus 5deac1e6e1 Wmem string-buffer improvements:
- better tests
- fix a bug caught by the better tests
- implement append_c and append_unichar, with tests

Wmem string-buffers now have feature parity with their emem equivalents, so
remove them from the TODO list.

svn path=/trunk/; revision=49060
2013-04-26 21:30:24 +00:00
Evan Huus e8fc503c21 Summarize the API listing in the wmem README. Doxygen in the header files will
be much easier to keep in sync with the actual code.

svn path=/trunk/; revision=49040
2013-04-25 22:29:48 +00:00
Evan Huus 2a50c31800 Add a section to the wmem README about testing.
svn path=/trunk/; revision=48990
2013-04-22 21:29:57 +00:00
Evan Huus 8de4b82fcd Document the wmem override environment variable in the man pages, and improve
README.wmem in a couple of places.

svn path=/trunk/; revision=48251
2013-03-11 19:17:26 +00:00
Evan Huus aafe8b18e9 Remove the wmem slab. It was an optimization mimicking the emem slab
(removed in r48218) which did nothing particularly useful. Also lets us remove
another debugging environment variable.

svn path=/trunk/; revision=48219
2013-03-09 20:16:33 +00:00
Evan Huus 63313f0c70 Update wmem docs
svn path=/trunk/; revision=47549
2013-02-08 01:50:35 +00:00
Evan Huus 681a3ad5a2 Handle NULL-pointers and 0-lengths in a much simpler allocator-agnostic way,
and document the fact that allocator authors don't have to care.

svn path=/trunk/; revision=47220
2013-01-23 01:11:36 +00:00
Evan Huus 669b98bb5f Rewrite wmem_allocator_simple to track allocations using a GHashTable instead of
a GSList. This permits it to implement the new realloc and free functions. Also
fill in an empty gc function, since there isn't much it can do as far as
garbage-collection goes.

svn path=/trunk/; revision=47169
2013-01-19 19:56:20 +00:00
Evan Huus 21453d5db6 Add three more slots to the wmem allocater definition (not yet implemented
by any particular allocator) and better document the entire structure.

svn path=/trunk/; revision=47163
2013-01-19 16:15:32 +00:00
Evan Huus d0b774d0ea Minor documentation tweaks. Add a hash table to the wishlist.
svn path=/trunk/; revision=47101
2013-01-15 18:29:27 +00:00
Evan Huus bab105d094 Add convenience macros wmem_new and wmem_new0
svn path=/trunk/; revision=46941
2013-01-04 22:11:13 +00:00
Evan Huus a19980c23d Replace another instance of emem in README.developer with wmem.
svn path=/trunk/; revision=46847
2012-12-29 20:41:12 +00:00
Evan Huus 5eacf33f1f Update wmem documentation for the new allocator.
Use the strict allocator when fuzzing (at least until the fuzz-bot starts
running everything under valgrind).

svn path=/trunk/; revision=46829
2012-12-28 17:09:07 +00:00
Evan Huus 439eaf4aa5 Add documentation about the environment variable.
svn path=/trunk/; revision=46817
2012-12-27 22:57:05 +00:00
Evan Huus f88d8e48c1 Update wmem docs to include new type field.
svn path=/trunk/; revision=46815
2012-12-27 22:38:48 +00:00
Evan Huus 5ca70369a0 Add missing wmem strbuf routine to the documentation.
svn path=/trunk/; revision=46625
2012-12-19 23:12:58 +00:00
Evan Huus 3739c083bf Implement a basic singly-linked for wmem.
Re-implement the stack as a wrapper for that.

svn path=/trunk/; revision=46607
2012-12-19 01:37:28 +00:00
Evan Huus 5cf858ec52 Dispatch all allocator creations through a single function using an enum to
determine the desired type. This has two advantages over the old way:
 - just one environment variable for valgrind to override in order to guarantee
   that ALL allocators use memory it can track, and just one place to check that
   variable
 - allocator owners no longer have to include headers specific to their
   allocator, allowing them to change allocators without adjusting all their
   #includes

svn path=/trunk/; revision=46604
2012-12-19 00:43:36 +00:00
Evan Huus 8b69e3ee22 Use 'new' instead of 'create' a consistent manner.
svn path=/trunk/; revision=46601
2012-12-18 23:25:11 +00:00
Evan Huus 7f23c2f8b7 Recommend wmem over emem in the READMEs where possible.
svn path=/trunk/; revision=46472
2012-12-08 21:57:05 +00:00
Evan Huus d4261b289f Document the new pinfo pool, add a TODO list.
svn path=/trunk/; revision=46332
2012-12-02 17:16:09 +00:00
Evan Huus f4a786638b Add strdup_printf and strdup_vprintf to the wmem string utilities.
svn path=/trunk/; revision=46177
2012-11-25 14:16:50 +00:00
Evan Huus 0d1f86c33e Allocate wmem memory in blocks of 8MB, not 10, because powers of two are nice.
svn path=/trunk/; revision=46175
2012-11-25 13:58:06 +00:00
Evan Huus 67ea470cc8 Add the block allocator to the documentation.
svn path=/trunk/; revision=46169
2012-11-24 18:49:52 +00:00