|
|
@ -2,7 +2,7 @@
|
|
|
|
#![no_main]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
|
|
|
|
use aya_ebpf::{
|
|
|
|
use aya_ebpf::{
|
|
|
|
cty::{c_int, c_long},
|
|
|
|
cty::c_long,
|
|
|
|
macros::{map, uprobe},
|
|
|
|
macros::{map, uprobe},
|
|
|
|
maps::{Array, Queue},
|
|
|
|
maps::{Array, Queue},
|
|
|
|
programs::ProbeContext,
|
|
|
|
programs::ProbeContext,
|
|
|
@ -14,33 +14,33 @@ const PEEK_INDEX: u32 = 0;
|
|
|
|
const POP_INDEX: u32 = 1;
|
|
|
|
const POP_INDEX: u32 = 1;
|
|
|
|
|
|
|
|
|
|
|
|
#[map]
|
|
|
|
#[map]
|
|
|
|
static RESULT: Array<c_int> = Array::<c_int>::with_max_entries(10, 0);
|
|
|
|
static RESULT: Array<u64> = Array::<u64>::with_max_entries(2, 0);
|
|
|
|
|
|
|
|
|
|
|
|
#[map]
|
|
|
|
#[map]
|
|
|
|
static TEST_QUEUE: Queue<c_int> = Queue::with_max_entries(10, 0);
|
|
|
|
static TEST_QUEUE: Queue<u64> = Queue::with_max_entries(10, 0);
|
|
|
|
|
|
|
|
|
|
|
|
#[uprobe]
|
|
|
|
#[uprobe]
|
|
|
|
pub fn test_queue_push(ctx: ProbeContext) -> Result<(), c_long> {
|
|
|
|
pub fn test_queue_push(ctx: ProbeContext) -> Result<(), c_long> {
|
|
|
|
let value: c_int = ctx.arg(0).ok_or(-2)?;
|
|
|
|
let value = ctx.arg(0).ok_or(-1)?;
|
|
|
|
TEST_QUEUE.push(&value, 0)?;
|
|
|
|
TEST_QUEUE.push(&value, 0)?;
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[uprobe]
|
|
|
|
#[uprobe]
|
|
|
|
pub fn test_queue_peek(_: ProbeContext) -> Result<(), c_long> {
|
|
|
|
pub fn test_queue_pop(_: ProbeContext) -> Result<(), c_long> {
|
|
|
|
let value = TEST_QUEUE.peek().unwrap_or(-1);
|
|
|
|
let value = TEST_QUEUE.pop().ok_or(-1)?;
|
|
|
|
result_set(PEEK_INDEX, value)?;
|
|
|
|
result_set(POP_INDEX, value)?;
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[uprobe]
|
|
|
|
#[uprobe]
|
|
|
|
pub fn test_queue_pop(_: ProbeContext) -> Result<(), c_long> {
|
|
|
|
pub fn test_queue_peek(_: ProbeContext) -> Result<(), c_long> {
|
|
|
|
let value = TEST_QUEUE.pop().unwrap_or(-1);
|
|
|
|
let value = TEST_QUEUE.peek().ok_or(-1)?;
|
|
|
|
result_set(POP_INDEX, value)?;
|
|
|
|
result_set(PEEK_INDEX, value)?;
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn result_set(index: u32, value: c_int) -> Result<(), c_long> {
|
|
|
|
fn result_set(index: u32, value: u64) -> Result<(), c_long> {
|
|
|
|
let ptr = RESULT.get_ptr_mut(index).ok_or(-1)?;
|
|
|
|
let ptr = RESULT.get_ptr_mut(index).ok_or(-1)?;
|
|
|
|
let dst = unsafe { ptr.as_mut() };
|
|
|
|
let dst = unsafe { ptr.as_mut() };
|
|
|
|
let dst_res = dst.ok_or(-1)?;
|
|
|
|
let dst_res = dst.ok_or(-1)?;
|
|
|
|