You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/scripting.md
+24-2Lines changed: 24 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -364,7 +364,7 @@ Performance and safety notes:
364
364
365
365
- Comparisons are compiled into bounded, branch-light checks to be verifier-friendly on most kernels. Still, placing many string comparisons in a single probe or attaching at extremely hot sites may add CPU and verifier load.
366
366
- Prefer attaching at less-hot lines/functions if you only need occasional confirmation (e.g., update sites for a string field), or split multiple heavy comparisons into separate trace points.
367
-
- Builtins (`strncmp`/`starts_with`) cap read length to 64 bytes for safety (see `STRING_BUILTIN_READ_CAP` in `ghostscope-compiler/src/ebpf/expression.rs`).
367
+
- Builtins (`strncmp`/`starts_with`) cap read length by `ebpf.compare_cap` (default 64 bytes).
368
368
CString equality reads only `L+1` bytes (no extra cap beyond the literal length).
369
369
370
370
// Floats are not supported in GhostScope scripts.
- Does not require a terminating NUL within `n` bytes.
380
380
- `expr` may be a DWARF `char*`, `char[N]`, or a generic pointer expression; GhostScope performs a bounded user-memory read and compares bytes.
381
381
- Any read failure evaluates to `false`.
382
-
- Read length is capped at 64 bytes; if `n` exceeds the cap or the available array size, it is truncated. See `STRING_BUILTIN_READ_CAP` in `ghostscope-compiler/src/ebpf/expression.rs`.
382
+
- Read length is capped by configuration `ebpf.compare_cap` (default 64 bytes). If `n` exceeds the cap or the available array size, it is truncated.
383
383
384
384
- `starts_with(expr, "lit")`
385
385
- Equivalent to `strncmp(expr, "lit", len("lit"))`.
386
386
- Same failure and safety semantics as above.
387
387
388
+
- `memcmp(expr_a, expr_b, len)`
389
+
- Boolean variant: returns `true` iff the first `len` bytes at `expr_a` and `expr_b` are identical.
390
+
- Pointer vs pointer only; for literal comparisons against strings, use `strncmp`/`starts_with` instead.
391
+
- `len` can be a script integer expression; negative values clamp to 0, and a configurable cap (`ebpf.compare_cap`, default 64) applies. The effective compare length is `min(max(len,0), CAP)`.
392
+
- No NUL-terminator semantics; compares raw bytes only.
393
+
- Any read failure on either side evaluates to `false`.
394
+
- If `len == 0`, the result is `true` and no user-memory read is performed (fast-path).
395
+
- Implementation is verifier-friendly: reads are bounded and comparisons are accumulated without early exits.
396
+
388
397
Verifier friendliness and performance:
389
398
- Compiles to branch-light byte comparisons (e.g., XOR/OR accumulation) to avoid verifier state explosion.
390
399
- Avoid packing many large string checks into a single very hot probe; consider splitting trace points or using less-hot sites when possible.
0 commit comments