1 /*
2  *  Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
3  *  Copyright (C) 2008-2013 Sourcefire, Inc.
4  *
5  *  Authors: aCaB <acab@clamav.net>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *  MA 02110-1301, USA.
20  */
21 
22 #ifndef MPOOL_H
23 #define MPOOL_H
24 
25 #if HAVE_CONFIG_H
26 #include "clamav-config.h"
27 #endif
28 
29 #ifdef USE_MPOOL
30 
31 #include "clamav-types.h"
32 #include "readdb.h"
33 
34 typedef struct MP mpool_t;
35 struct cl_engine;
36 
37 mpool_t *mpool_create(void);
38 void mpool_destroy(mpool_t *mpool);
39 
40 void *mpool_malloc(mpool_t *mpool, size_t size);
41 void mpool_free(mpool_t *mpool, void *ptr);
42 void *mpool_calloc(mpool_t *mpool, size_t nmemb, size_t size);
43 void *mpool_realloc(mpool_t *mpool, void *ptr, size_t size);
44 void *mpool_realloc2(mpool_t *mpool, void *ptr, size_t size);
45 char *cli_mpool_hex2str(mpool_t *mpool, const char *src);
46 char *cli_mpool_strdup(mpool_t *mpool, const char *s);
47 char *cli_mpool_strndup(mpool_t *mpool, const char *s, size_t n);
48 char *cli_mpool_virname(mpool_t *mpool, const char *virname, unsigned int official);
49 uint16_t *cli_mpool_hex2ui(mpool_t *mpool, const char *hex);
50 void mpool_flush(mpool_t *mpool);
51 int mpool_getstats(const struct cl_engine *engine, size_t *used, size_t *total);
52 
53 #define MPOOL_MALLOC(a, b) mpool_malloc(a, b)
54 #define MPOOL_FREE(a, b) mpool_free(a, b)
55 #define MPOOL_CALLOC(a, b, c) mpool_calloc(a, b, c)
56 #define MPOOL_REALLOC(a, b, c) mpool_realloc(a, b, c)
57 #define MPOOL_REALLOC2(a, b, c) mpool_realloc2(a, b, c)
58 #define CLI_MPOOL_HEX2STR(mpool, src) cli_mpool_hex2str(mpool, src)
59 #define CLI_MPOOL_STRDUP(mpool, s) cli_mpool_strdup(mpool, s)
60 #define CLI_MPOOL_STRNDUP(mpool, s, n) cli_mpool_strndup(mpool, s, n)
61 #define CLI_MPOOL_VIRNAME(mpool, a, b) cli_mpool_virname(mpool, a, b)
62 #define CLI_MPOOL_HEX2UI(mpool, hex) cli_mpool_hex2ui(mpool, hex)
63 #define MPOOL_FLUSH(val) mpool_flush(val)
64 #define MPOOL_GETSTATS(mpool, used, total) mpool_getstats(mpool, used, total)
65 
66 #else /* USE_MPOOL */
67 
68 typedef void mpool_t;
69 
70 #define MPOOL_MALLOC(a, b) cli_malloc(b)
71 #define MPOOL_FREE(a, b) free(b)
72 #define MPOOL_CALLOC(a, b, c) cli_calloc(b, c)
73 #define MPOOL_REALLOC(a, b, c) cli_realloc(b, c)
74 #define MPOOL_REALLOC2(a, b, c) cli_realloc2(b, c)
75 #define CLI_MPOOL_HEX2STR(mpool, src) cli_hex2str(src)
76 #define CLI_MPOOL_STRDUP(mpool, s) cli_strdup(s)
77 #define CLI_MPOOL_STRNDUP(mpool, s, n) cli_strdup(s, n)
78 #define CLI_MPOOL_VIRNAME(mpool, a, b) cli_virname(a, b)
79 #define CLI_MPOOL_HEX2UI(mpool, hex) cli_hex2ui(hex)
80 #define MPOOL_FLUSH(val)
81 #define MPOOL_GETSTATS(mpool, used, total) -1
82 
83 #endif /* USE_MPOOL */
84 
85 #endif
86