This file is project-wide guidance for agents. Keep it short and focused on high-impact constraints.
- In Rust code, separate logical blocks and control-flow branches with blank lines for readability.
- Keep no blank line after
#[]attributes and no blank line betweenmatcharms. - Ignore the blank-line style rule when acting purely as a reviewer.
- Do not add unnecessary comments; only add comments that explain behavior or intent.
Pinchy is an eBPF-based syscall tracer intended as a lower-overhead alternative
to strace.
Crates:
pinchy-common: shared structs/helperspinchy-ebpf: eBPF programspinchy: userspace daemon and formatting/parsing
Supported architectures are aarch64 and x86_64.
- Do not rely on memory for
ayaandzbusAPIs. Verify current APIs in docs.rs before using them. - When adding a dependency, start with
cargo add <crate>(no pinned version) to discover the current stable version first.
-
Do not modify
pinchy-common/src/syscalls/aarch64.rsorpinchy-common/src/syscalls/x86_64.rsdirectly. Use them as references only. Outside these files, importpinchy_common::syscallsand usesyscalls::SYS_<name>. -
Classify each syscall as either trivial or complex:
- Trivial: no pointer args, or pointers printed as raw addresses only.
- Complex: any pointer data must be dereferenced/parsed.
-
Never treat a syscall as trivial just because its Rust signature uses
usize. -
Never handle the same syscall in both places:
- trivial handler (
syscall_exit_trivial+TRIVIAL_SYSCALLS), and - any consolidated category handler.
- trivial handler (
-
For eBPF user-memory reads:
- use
bpf_probe_read_user()for small structs, - use
bpf_probe_read_buf()for byte arrays/larger structs to avoid stack pressure by reading directly into compact payload ringbuf memory.
- use
-
Never use magic values in format helpers or tests. Prefer
libc::constants; declare named constants whenlibcdoes not provide one. -
Before adding new formatting logic, check and reuse existing
format_*helpers. In particular:- use
format_dirfd()fordfd/dirfd/olddirfd/newdirfd/from_dfd/to_dfd, - use
format_mode()for file modes.
- use
-
Ensure syscall return formatting is covered in
format_return_valueinpinchy/src/format_helpers.rs. -
For architecture-specific code in
pinchy-commonandpinchy-ebpf, use#[cfg(x86_64)]/#[cfg(aarch64)]feature-gated paths used by this project.
- Confirm
SYS_<name>exists in both arch syscall files. - Read the man page to understand pointer args and whether dereference is
required:
https://man7.org/linux/man-pages/man2/SYSCALL_NAME.2.html - Decide trivial vs complex.
- Wire eBPF handling:
- Trivial: add to
syscall_exit_trivialinpinchy-ebpf/src/main.rs. - Complex: add a case to the appropriate consolidated handler in
pinchy-ebpf/src/.
- Trivial: add to
- Register tailcalls in
pinchy/src/server.rs:TRIVIAL_SYSCALLSfor trivial,- matching category array for complex.
- Add/update
<Syscall>Datainpinchy-common/src/lib.rs. - Register payload size in
compact_payload_size()inpinchy-common/src/lib.rs. - Update parsing in
pinchy/src/events.rs, reusing existing format helpers. - Update
format_return_valuehandling inpinchy/src/format_helpers.rs. - Add tests for parsing and formatting behavior.
- If syscall category or complexity is ambiguous, ask for a decision.
- Build check: use
cargo check(avoid--workspacefor this project). - Add/adjust syscall parsing tests under
pinchy/src/tests/. - Run relevant integration test(s) when syscall behavior crosses userspace and eBPF boundaries.
Integration tests and helpers live in:
pinchy/tests/integration.rspinchy/tests/auto_quit.rspinchy/tests/common.rspinchy/src/bin/test-helper.rs
escaped_regex() markers used by tests:
| Marker | Matches |
|---|---|
@PID@ |
\d+ |
@ADDR@ |
0x[0-9a-f]+ |
@HEXNUMBER@ |
[0-9a-f]+ |
@SIGNEDNUMBER@ |
-?[0-9]+ |
@NUMBER@ |
[0-9]+ |
@MODE@ |
[rwx-]+ |
@ALPHANUM@ |
[^ "]+ |
@QUOTEDSTRING@ |
"[^"]*" |
@MAYBEITEM_@ |
([^ "]+ )? |
@MAYBETRUNCATED@ |
( ... (truncated))? |
@GROUPLIST@ |
[0-9, ]* |
@ANY@ |
.+ |
pinchy-ebpf/src/consolidated syscall handlerspinchy-ebpf/src/main.rstrivial handler entry pointspinchy-ebpf/src/util.rscompact payload helperspinchy/src/server.rstailcall registration arrayspinchy/src/events.rsuserspace event parsingpinchy/src/format_helpers.rsargument/return-value formattingpinchy/src/tests/mod.rs(syscall_test!macro)pinchy/tests/common.rsintegration helpers
- Keep guidance short, durable, and repo-wide.
- Prefer linking to canonical code over embedding long implementation examples.
- Remove duplicated or task-specific instructions.