Skip to content

Commit 2cf85c1

Browse files
committed
Adds CLI argument handling and usage info to kret tool
Signed-off-by: Godones <chenlinfeng25@outlook.com>
1 parent 3f522d4 commit 2cf85c1

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

api/src/syscall/fs/fd_ops.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ fn add_to_fd(result: OpenResult, flags: u32) -> AxResult<i32> {
108108
add_file_like(f, flags & O_CLOEXEC != 0)
109109
}
110110

111-
// WARN: We need to ensure that the fields in TP_STRUCT__entry are not
112-
// rearranged.
113111
tracepoint::define_event_trace!(
114112
sys_enter_openat,
115113
TP_lock(crate::lock_api::KSpinNoPreempt<()>),

arceos

docs/eBPF for Starry.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ ln -s /lib/ld-musl-loongarch64.so.1 /lib64/ld-musl-loongarch-lp64d.so.1
200200

201201
在aarch64架构下, 使用musl工具链不像其它架构一样会默认进行动态链接,而是默认进行静态链接。如果需要动态链接,需要指定 `rustflags = ["-C", "target-feature=-crt-static"]`
202202

203+
## 其它信息
204+
205+
内核处理用户态的break异常路径:
206+
```
207+
int3
208+
→ #BP
209+
→ 内核
210+
├─ 如果是 uprobe:
211+
│ → 执行 eBPF
212+
│ → 模拟原指令
213+
│ → 返回用户态(无 SIGTRAP)
214+
215+
└─ 如果不是:
216+
→ 发送 SIGTRAP
217+
```
218+
203219
## 参考与源码入口
204220

205221
- `core/src/probe_aux.rs`:地址权限调整、可执行页分配、retprobe 实例管理。

user/musl/.cargo/config.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
[target.riscv64gc-unknown-linux-musl]
2-
# rustflags = ["-C", "target-feature=+crt-static"]
32
linker = "riscv64-linux-musl-cc"
43

54
[target.loongarch64-unknown-linux-musl]
6-
# rustflags = ["-C", "target-feature=+crt-static"]
75
linker = "loongarch64-linux-musl-cc"
86

97
[target.aarch64-unknown-linux-musl]
10-
rustflags = ["-C", "target-feature=-crt-static"]
118
linker = "aarch64-linux-musl-cc"

user/musl/kret/kret/src/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ use tokio::signal;
55

66
#[tokio::main]
77
async fn main() -> anyhow::Result<()> {
8+
9+
let args_num = std::env::args().len();
10+
if args_num != 2 {
11+
println!("Usage: kret {{mangled_func_name}}");
12+
println!(
13+
"You can get the mangled function name by running `cat /proc/kallsyms | grep -m 1 sys_getpid`"
14+
);
15+
return Ok(());
16+
}
17+
let args: Vec<String> = std::env::args().collect();
18+
let target_syscall_entry = &args[1];
19+
820
env_logger::builder()
921
.filter_level(log::LevelFilter::Info)
1022
.format_timestamp(None)
@@ -48,7 +60,8 @@ async fn main() -> anyhow::Result<()> {
4860
}
4961
let program: &mut KProbe = ebpf.program_mut("kret").unwrap().try_into()?;
5062
program.load()?;
51-
program.attach("starry_api::syscall::task::thread::sys_getpid", 0)?;
63+
// TODO: support mangled symbol name
64+
program.attach(target_syscall_entry, 0)?;
5265

5366
let ctrl_c = signal::ctrl_c();
5467
println!("Waiting for Ctrl-C...");

0 commit comments

Comments
 (0)