Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fhilgers committed Jan 29, 2025
1 parent f20d35a commit b5454d0
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 13 deletions.
3 changes: 1 addition & 2 deletions rust/client/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use clap::Parser;
use clap::Subcommand;
use client::Client;
use client::ClientError;
use shared::config::GcConfig;
use shared::config::SysFdTrackingConfig;
use shared::config::{Configuration, SysSendmsgConfig, VfsWriteConfig, JniReferencesConfig, SysSigquitConfig};
use shared::config::{Configuration, SysSendmsgConfig, VfsWriteConfig, SysSigquitConfig};
use std::collections::HashMap;
use tokio_stream::StreamExt;

Expand Down
4 changes: 4 additions & 0 deletions rust/playground/ebpf-refactored/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2025 Felix Hilgers <[email protected]>
//
// SPDX-License-Identifier: MIT

use core::mem::MaybeUninit;

use aya_ebpf::{
Expand Down
15 changes: 15 additions & 0 deletions rust/playground/ebpf-refactored/src/event_local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2025 Felix Hilgers <[email protected]>
//
// SPDX-License-Identifier: MIT

use aya_ebpf::maps::HashMap;

#[repr(C)]
pub struct Args<T> {
pub args: [u64; 6],
pub extra: T,
}

pub struct EventLocal<T: 'static>(&'static HashMap<u64, Args<T>>);

impl<T> EventLocal<T> {}
4 changes: 4 additions & 0 deletions rust/playground/ebpf-refactored/src/events/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2025 Felix Hilgers <[email protected]>
//
// SPDX-License-Identifier: MIT

pub mod blocking;
pub mod fdtracking;
pub mod signal;
Expand Down
5 changes: 5 additions & 0 deletions rust/playground/ebpf-refactored/src/filter.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// SPDX-FileCopyrightText: 2025 Felix Hilgers <[email protected]>
//
// SPDX-License-Identifier: MIT

use aya_ebpf::maps::{Array, HashMap};
use ebpf_types::{
Equality, EventData, EventKind, FilterConfig, MissingBehavior,
};

#[repr(transparent)]
pub struct Filter<K: 'static, V: Matcher + 'static>(&'static HashMap<K, V>);

pub struct FilterConfigs {
config: &'static Array<FilterConfig>,
host_pid: &'static Array<u32>,
Expand Down
1 change: 1 addition & 0 deletions rust/playground/ebpf-refactored/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pub mod pipeline;
pub mod scratch;
pub mod syscalls;
pub mod task_ext;
pub mod event_local;
14 changes: 6 additions & 8 deletions rust/playground/ebpf-refactored/src/maps.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2025 Felix Hilgers <[email protected]>
//
// SPDX-License-Identifier: MIT

use aya_ebpf::{
macros::map,
maps::{Array, HashMap, LruHashMap, PerCpuArray, RingBuf},
Expand All @@ -6,10 +10,7 @@ use ebpf_relocation_helpers::TaskStruct;
use ebpf_types::{Equality, EventData, EventKind, FilterConfig, ProcessContext, TaskContext};

use crate::{
cache::{Cache, TryWithCache},
filter::{FilterConfigs, FilterEntry},
pipeline::RawEventData,
scratch::{ScratchSpace, ScratchValue},
event_local::Args, cache::{Cache, TryWithCache}, filter::{FilterConfigs, FilterEntry}, pipeline::RawEventData, scratch::{ScratchSpace, ScratchValue}
};

#[map]
Expand All @@ -31,10 +32,7 @@ static FILTER_CONFIG: Array<FilterConfig> = Array::with_max_entries(EventKind::M
static CONFIG: Array<u32> = Array::with_max_entries(1, 0);

#[map]
pub static EVENT_BUFFER: PerCpuArray<RawEventData> = PerCpuArray::with_max_entries(1, 0);

#[map]
pub static EVENT_BRIDGE: HashMap<u64, RawEventData> = HashMap::with_max_entries(10240, 0);
static ARG_BUFFER: HashMap<u64, Args<[u8; 1024]>> = HashMap::with_max_entries(10240, 0);

#[map]
pub static EVENTS: RingBuf = RingBuf::with_byte_size(8192 * 1024, 0);
Expand Down
10 changes: 7 additions & 3 deletions rust/playground/ebpf-refactored/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use core::{
marker::PhantomData,
ops::{Deref, DerefMut},
ops::{Deref, DerefMut}, ptr::null_mut,
};

use aya_ebpf::{
Expand All @@ -30,7 +30,7 @@ use crate::{
},
filter::FilterEntry,
maps::{
EventFilter, ProcessInfoCache, TaskInfoCache, EVENTS, EVENT_BRIDGE, EVENT_BUFFER,
EventFilter, ProcessInfoCache, TaskInfoCache, EVENTS,
GLOBAL_BLOCKING_THRESHOLD,
},
};
Expand Down Expand Up @@ -163,6 +163,7 @@ unsafe fn program_info_base<T: EventData>(

unsafe fn program_info<T: EventData>(task: TaskStruct) -> Option<ProgramInfo<'static, T>> {
let key = event_bridge_key::<T>(task)?;
/*
let raw_event_data = match EVENT_BRIDGE.get_ptr_mut(&key) {
Some(bridge) => bridge,
None => {
Expand All @@ -171,6 +172,8 @@ unsafe fn program_info<T: EventData>(task: TaskStruct) -> Option<ProgramInfo<'st
EVENT_BRIDGE.get_ptr_mut(&key)?
}
};
*/
let raw_event_data = null_mut();
let program_info = program_info_base::<T>(task, raw_event_data)?;
program_info.event_info.set_initialized(false);
Some(program_info)
Expand All @@ -180,7 +183,8 @@ unsafe fn program_info_intermediate<T: EventData>(
task: TaskStruct,
) -> Option<ProgramInfo<'static, T>> {
let key = event_bridge_key::<T>(task)?;
let raw_event_data = EVENT_BRIDGE.get_ptr_mut(&key)?;
//let raw_event_data = EVENT_BRIDGE.get_ptr_mut(&key)?;
let raw_event_data = null_mut();
let program_info = program_info_base::<T>(task, raw_event_data)?;
if !program_info.event_info.get_initialized() {
return None;
Expand Down
4 changes: 4 additions & 0 deletions rust/playground/ebpf-refactored/src/scratch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2025 Felix Hilgers <[email protected]>
//
// SPDX-License-Identifier: MIT

use core::{
mem::MaybeUninit,
ops::{Deref, DerefMut},
Expand Down

0 comments on commit b5454d0

Please sign in to comment.