2012-10-24 02:04:40 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2012-12-19 00:43:36 +00:00
|
|
|
#include <stdlib.h>
|
2012-10-24 02:04:40 +00:00
|
|
|
#include <string.h>
|
2012-12-19 00:43:36 +00:00
|
|
|
#include <glib.h>
|
2012-10-24 02:04:40 +00:00
|
|
|
|
|
|
|
#include "wmem_core.h"
|
2012-11-03 15:49:15 +00:00
|
|
|
#include "wmem_scopes.h"
|
2012-10-24 02:04:40 +00:00
|
|
|
#include "wmem_allocator.h"
|
2012-12-19 00:43:36 +00:00
|
|
|
#include "wmem_allocator_simple.h"
|
|
|
|
#include "wmem_allocator_block.h"
|
2012-10-27 02:42:05 +00:00
|
|
|
|
2012-10-24 02:04:40 +00:00
|
|
|
void *
|
2012-11-08 23:18:26 +00:00
|
|
|
wmem_alloc(wmem_allocator_t *allocator, const size_t size)
|
2012-10-24 02:04:40 +00:00
|
|
|
{
|
|
|
|
return allocator->alloc(allocator->private_data, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2012-11-08 23:18:26 +00:00
|
|
|
wmem_alloc0(wmem_allocator_t *allocator, const size_t size)
|
2012-10-24 02:04:40 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-10-27 02:29:46 +00:00
|
|
|
void
|
|
|
|
wmem_destroy_allocator(wmem_allocator_t *allocator)
|
|
|
|
{
|
|
|
|
wmem_free_all(allocator);
|
|
|
|
allocator->destroy(allocator);
|
|
|
|
}
|
|
|
|
|
2012-12-19 00:43:36 +00:00
|
|
|
wmem_allocator_t *
|
|
|
|
wmem_allocator_new(const wmem_allocator_type_t type)
|
|
|
|
{
|
|
|
|
/* Our valgrind script uses this environment variable to override the
|
|
|
|
* usual allocator choice so that everything goes through system-level
|
|
|
|
* allocations that it understands and can track. Otherwise it will get
|
|
|
|
* confused by the block allocator etc. */
|
|
|
|
if (getenv("WIRESHARK_DEBUG_WMEM_SIMPLE")) {
|
|
|
|
return wmem_simple_allocator_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case WMEM_ALLOCATOR_SIMPLE:
|
|
|
|
return wmem_simple_allocator_new();
|
|
|
|
case WMEM_ALLOCATOR_BLOCK:
|
|
|
|
return wmem_block_allocator_new();
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2012-12-19 04:30:02 +00:00
|
|
|
/* This is necessary to squelch MSVC errors; is there
|
|
|
|
any way to tell it that g_assert_not_reached()
|
|
|
|
never returns? */
|
|
|
|
return NULL;
|
2012-12-19 00:43:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-10-27 02:42:05 +00:00
|
|
|
void
|
|
|
|
wmem_init(void)
|
|
|
|
{
|
2012-11-03 15:49:15 +00:00
|
|
|
wmem_init_scopes();
|
2012-10-27 02:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wmem_cleanup(void)
|
|
|
|
{
|
2012-11-03 15:49:15 +00:00
|
|
|
wmem_cleanup_scopes();
|
2012-10-27 02:42:05 +00:00
|
|
|
}
|
|
|
|
|
2012-10-24 02:04:40 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|