threads: add threadvars allocator and free func

Mostly meant to help unittests and fuzz targets alloc the storage
correctly.
pull/15499/head
Victor Julien 2 months ago
parent b11aa94d42
commit ad1459df72

@ -1009,6 +1009,7 @@ libsuricata_c_a_SOURCES = \
thread-callbacks.c \
thread-storage.c \
threads.c \
threadvars.c \
tm-modules.c \
tm-queuehandlers.c \
tm-queues.c \

@ -0,0 +1,47 @@
/* Copyright (C) 2026 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* 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
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "suricata-common.h"
#include "threadvars.h"
#include "thread-storage.h"
/**
* \brief Allocate a new ThreadVars structure.
*
* \retval NULL if allocation failed.
* \retval Pointer to newly allocated ThreadVars structure.
*/
ThreadVars *ThreadVarsAlloc(void)
{
ThreadVars *tv = SCCalloc(1, sizeof(ThreadVars) + SCThreadStorageSize());
if (tv == NULL)
return NULL;
SC_ATOMIC_INIT(tv->flags);
return tv;
}
/**
* \brief Free a ThreadVars structure.
*
* \param tv Pointer to ThreadVars structure to be freed.
*/
void ThreadVarsFree(ThreadVars *tv)
{
if (tv == NULL)
return;
SCFree(tv);
}

@ -143,4 +143,19 @@ typedef struct ThreadVars_ {
#define THREAD_SET_PRIORITY 0x02 /** Real time priority */
#define THREAD_SET_AFFTYPE 0x04 /** Priority and affinity */
/**
* \brief Allocate a new ThreadVars structure.
*
* \retval NULL if allocation failed.
* \retval Pointer to newly allocated ThreadVars structure.
*/
ThreadVars *ThreadVarsAlloc(void);
/**
* \brief Free a ThreadVars structure.
*
* \param tv Pointer to ThreadVars structure to be freed.
*/
void ThreadVarsFree(ThreadVars *tv);
#endif /* SURICATA_THREADVARS_H */

Loading…
Cancel
Save