/src/suricata7/src/util-mpm-ac-queue.h
Line | Count | Source |
1 | | /* Copyright (C) 2025 Open Information Security Foundation |
2 | | * |
3 | | * You can copy, redistribute or modify this Program under the terms of |
4 | | * the GNU General Public License version 2 as published by the Free |
5 | | * Software Foundation. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * version 2 along with this program; if not, write to the Free Software |
14 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 | | * 02110-1301, USA. |
16 | | */ |
17 | | |
18 | | /** |
19 | | * \file |
20 | | * |
21 | | * \author Anoop Saldanha <anoopsaldanha@gmail.com> |
22 | | * |
23 | | */ |
24 | | |
25 | | #ifndef SURICATA_UTIL_MPM_AC_QUEUE_H |
26 | | #define SURICATA_UTIL_MPM_AC_QUEUE_H |
27 | | |
28 | 279k | #define STATE_QUEUE_CONTAINER_SIZE 65536 |
29 | | |
30 | | /** |
31 | | * \brief Helper structure used by AC during state table creation |
32 | | */ |
33 | | typedef struct StateQueue_ { |
34 | | uint32_t top; |
35 | | uint32_t bot; |
36 | | uint32_t size; |
37 | | int32_t *store; |
38 | | } StateQueue; |
39 | | |
40 | | StateQueue *SCACStateQueueAlloc(void); |
41 | | void SCACStateQueueFree(StateQueue *q); |
42 | | |
43 | | static inline int SCACStateQueueIsEmpty(StateQueue *q) |
44 | 4.71M | { |
45 | 4.71M | if (q->top == q->bot) |
46 | 279k | return 1; |
47 | 4.43M | else |
48 | 4.43M | return 0; |
49 | 4.71M | } util-mpm-ac.c:SCACStateQueueIsEmpty Line | Count | Source | 44 | 4.71M | { | 45 | 4.71M | if (q->top == q->bot) | 46 | 279k | return 1; | 47 | 4.43M | else | 48 | 4.43M | return 0; | 49 | 4.71M | } |
Unexecuted instantiation: util-mpm-ac-ks.c:SCACStateQueueIsEmpty Unexecuted instantiation: util-mpm-ac-queue.c:SCACStateQueueIsEmpty |
50 | | |
51 | | static inline void SCACEnqueue(StateQueue *q, int32_t state) |
52 | 4.43M | { |
53 | | /*if we already have this */ |
54 | 8.07M | for (uint32_t i = q->bot; i < q->top; i++) { |
55 | 3.64M | if (q->store[i] == state) |
56 | 0 | return; |
57 | 3.64M | } |
58 | | |
59 | 4.43M | q->store[q->top++] = state; |
60 | | |
61 | 4.43M | if (q->top == q->size) |
62 | 0 | q->top = 0; |
63 | | |
64 | 4.43M | if (q->top == q->bot) { |
65 | | // allocate a new store and copy + realign |
66 | 0 | int32_t *tmp = SCCalloc(q->size + STATE_QUEUE_CONTAINER_SIZE, sizeof(int32_t)); |
67 | 0 | if (tmp == NULL) { |
68 | 0 | FatalError("Error reallocating memory"); |
69 | 0 | } |
70 | 0 | memcpy(tmp, q->store + q->bot, (q->size - q->bot) * sizeof(int32_t)); |
71 | 0 | memcpy(tmp + (q->size - q->bot), q->store, q->top * sizeof(int32_t)); |
72 | 0 | SCFree(q->store); |
73 | 0 | q->store = tmp; |
74 | 0 | q->bot = 0; |
75 | 0 | q->top = q->size; |
76 | 0 | q->size += STATE_QUEUE_CONTAINER_SIZE; |
77 | 0 | } |
78 | 4.43M | } util-mpm-ac.c:SCACEnqueue Line | Count | Source | 52 | 4.43M | { | 53 | | /*if we already have this */ | 54 | 8.07M | for (uint32_t i = q->bot; i < q->top; i++) { | 55 | 3.64M | if (q->store[i] == state) | 56 | 0 | return; | 57 | 3.64M | } | 58 | | | 59 | 4.43M | q->store[q->top++] = state; | 60 | | | 61 | 4.43M | if (q->top == q->size) | 62 | 0 | q->top = 0; | 63 | | | 64 | 4.43M | if (q->top == q->bot) { | 65 | | // allocate a new store and copy + realign | 66 | 0 | int32_t *tmp = SCCalloc(q->size + STATE_QUEUE_CONTAINER_SIZE, sizeof(int32_t)); | 67 | 0 | if (tmp == NULL) { | 68 | 0 | FatalError("Error reallocating memory"); | 69 | 0 | } | 70 | 0 | memcpy(tmp, q->store + q->bot, (q->size - q->bot) * sizeof(int32_t)); | 71 | 0 | memcpy(tmp + (q->size - q->bot), q->store, q->top * sizeof(int32_t)); | 72 | 0 | SCFree(q->store); | 73 | 0 | q->store = tmp; | 74 | 0 | q->bot = 0; | 75 | 0 | q->top = q->size; | 76 | 0 | q->size += STATE_QUEUE_CONTAINER_SIZE; | 77 | 0 | } | 78 | 4.43M | } |
Unexecuted instantiation: util-mpm-ac-ks.c:SCACEnqueue Unexecuted instantiation: util-mpm-ac-queue.c:SCACEnqueue |
79 | | |
80 | | static inline int32_t SCACDequeue(StateQueue *q) |
81 | 4.43M | { |
82 | 4.43M | if (q->bot == q->size) |
83 | 0 | q->bot = 0; |
84 | | |
85 | 4.43M | if (q->bot == q->top) { |
86 | 0 | FatalError("StateQueue behaving weirdly. " |
87 | 0 | "Fatal Error. Exiting. Please file a bug report on this"); |
88 | 0 | } |
89 | | |
90 | 4.43M | return q->store[q->bot++]; |
91 | 4.43M | } util-mpm-ac.c:SCACDequeue Line | Count | Source | 81 | 4.43M | { | 82 | 4.43M | if (q->bot == q->size) | 83 | 0 | q->bot = 0; | 84 | | | 85 | 4.43M | if (q->bot == q->top) { | 86 | 0 | FatalError("StateQueue behaving weirdly. " | 87 | 0 | "Fatal Error. Exiting. Please file a bug report on this"); | 88 | 0 | } | 89 | | | 90 | 4.43M | return q->store[q->bot++]; | 91 | 4.43M | } |
Unexecuted instantiation: util-mpm-ac-ks.c:SCACDequeue Unexecuted instantiation: util-mpm-ac-queue.c:SCACDequeue |
92 | | |
93 | | #endif /* SURICATA_UTIL_MPM_AC_QUEUE_H */ |