Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust ffi ints/v1 #12009

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions etc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@
},
"type": {
"type": "string"
},
"code": {
"type": "integer"
}
},
"additionalProperties": false
Expand Down
2 changes: 1 addition & 1 deletion rust/derive/src/applayerevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn derive_app_layer_event(input: TokenStream) -> TokenStream {
event_id: std::os::raw::c_int,
event_name: *mut *const std::os::raw::c_char,
event_type: *mut #crate_id::core::AppLayerEventType,
) -> i8 {
) -> std::os::raw::c_int {
#crate_id::applayer::get_event_info_by_id::<#name>(event_id, event_name, event_type)
}

Expand Down
6 changes: 3 additions & 3 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ pub type StateGetTxFn = unsafe extern "C" fn (*mut c_void, u64) -> *m
pub type StateGetTxCntFn = unsafe extern "C" fn (*mut c_void) -> u64;
pub type StateGetProgressFn = unsafe extern "C" fn (*mut c_void, u8) -> c_int;
pub type GetEventInfoFn = unsafe extern "C" fn (*const c_char, *mut c_int, *mut AppLayerEventType) -> c_int;
pub type GetEventInfoByIdFn = unsafe extern "C" fn (c_int, *mut *const c_char, *mut AppLayerEventType) -> i8;
pub type GetEventInfoByIdFn = unsafe extern "C" fn (c_int, *mut *const c_char, *mut AppLayerEventType) -> c_int;
Copy link
Member Author

@jasonish jasonish Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That we also use uint8_t and int for the event_type (first argument) in C, while not breaking anything right now, could be a source for error.

pub type LocalStorageNewFn = extern "C" fn () -> *mut c_void;
pub type LocalStorageFreeFn = extern "C" fn (*mut c_void);
pub type GetTxFilesFn = unsafe extern "C" fn (*mut c_void, u8) -> AppLayerGetFileState;
Expand Down Expand Up @@ -590,7 +590,7 @@ pub trait AppLayerEvent {
event_id: std::os::raw::c_int,
event_name: *mut *const std::os::raw::c_char,
event_type: *mut core::AppLayerEventType,
) -> i8;
) -> std::os::raw::c_int;
}

/// Generic `get_info_info` implementation for enums implementing
Expand Down Expand Up @@ -634,7 +634,7 @@ pub unsafe fn get_event_info_by_id<T: AppLayerEvent>(
event_id: std::os::raw::c_int,
event_name: *mut *const std::os::raw::c_char,
event_type: *mut core::AppLayerEventType,
) -> i8 {
) -> std::os::raw::c_int {
if let Some(e) = T::from_id(event_id) {
*event_name = e.to_cstring().as_ptr() as *const std::os::raw::c_char;
*event_type = core::AppLayerEventType::APP_LAYER_EVENT_TYPE_TRANSACTION;
Expand Down
2 changes: 1 addition & 1 deletion rust/src/smb/smb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ pub unsafe extern "C" fn rs_smb_state_get_event_info_by_id(
event_id: std::os::raw::c_int,
event_name: *mut *const std::os::raw::c_char,
event_type: *mut AppLayerEventType,
) -> i8 {
) -> std::os::raw::c_int {
SMBEvent::get_event_info_by_id(event_id, event_name, event_type)
}

Expand Down
Loading