Skip to content

Commit c70e068

Browse files
committed
rust/ffi: add minimal ThreadVars wrapper
Add a Rust wrapper around the raw ThreadVars pointer, intended for use in callbacks to control lifetime and provide safe accessors.
1 parent 2cb5790 commit c70e068

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

rust/ffi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod flow;
2525
pub mod jsonbuilder;
2626
pub mod packet;
2727
pub mod plugin;
28+
pub mod threadvars;
2829

2930
pub const IPPROTO_TCP: u8 = 6;
3031
pub const IPPROTO_UDP: u8 = 17;

rust/ffi/src/threadvars.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Copyright (C) 2026 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+
use std::marker::PhantomData;
19+
20+
use suricata_sys::sys;
21+
22+
pub struct ThreadVars<'a> {
23+
ptr: *const sys::ThreadVars,
24+
_marker: PhantomData<&'a sys::ThreadVars>,
25+
}
26+
27+
impl<'a> ThreadVars<'a> {
28+
pub fn from_ptr(ptr: *const sys::ThreadVars) -> Self {
29+
Self {
30+
ptr,
31+
_marker: PhantomData,
32+
}
33+
}
34+
35+
pub fn as_ptr(&self) -> *const sys::ThreadVars {
36+
self.ptr
37+
}
38+
}

0 commit comments

Comments
 (0)