Liking cljdoc? Tell your friends :D

clj-ebpf.asm

BPF assembly utilities including label resolution.

Provides symbolic label support for BPF programs, eliminating the need for manual jump offset calculations.

Example: (require '[clj-ebpf.asm :as asm] '[clj-ebpf.dsl :as dsl])

(asm/assemble-with-labels [(dsl/mov :r0 0) (asm/jmp-imm :jeq :r1 0 :success) (dsl/mov :r0 -1) (asm/jmp :done) (asm/label :success) (dsl/mov :r0 1) (asm/label :done) (dsl/exit-insn)])

BPF assembly utilities including label resolution.

Provides symbolic label support for BPF programs, eliminating
the need for manual jump offset calculations.

Example:
  (require '[clj-ebpf.asm :as asm]
           '[clj-ebpf.dsl :as dsl])

  (asm/assemble-with-labels
    [(dsl/mov :r0 0)
     (asm/jmp-imm :jeq :r1 0 :success)
     (dsl/mov :r0 -1)
     (asm/jmp :done)
     (asm/label :success)
     (dsl/mov :r0 1)
     (asm/label :done)
     (dsl/exit-insn)])
raw docstring

assemble-with-labelsclj

(assemble-with-labels instructions)

Assemble instructions with automatic label resolution.

This is the main entry point for programs using symbolic labels. Handles mixed sequences of:

  • Label pseudo-instructions (created with label)
  • Symbolic jump instructions (created with jmp-imm, jmp-reg, jmp)
  • Regular DSL instructions (byte arrays)

Parameters:

  • instructions: Sequence of instructions

Returns: Assembled bytecode (byte array)

Example: (assemble-with-labels [(dsl/mov :r0 0) (jmp-imm :jeq :r1 0 :success) (dsl/mov :r0 -1) (jmp :done) (label :success) (dsl/mov :r0 1) (label :done) (dsl/exit-insn)])

Assemble instructions with automatic label resolution.

This is the main entry point for programs using symbolic labels.
Handles mixed sequences of:
- Label pseudo-instructions (created with `label`)
- Symbolic jump instructions (created with `jmp-imm`, `jmp-reg`, `jmp`)
- Regular DSL instructions (byte arrays)

Parameters:
- instructions: Sequence of instructions

Returns: Assembled bytecode (byte array)

Example:
  (assemble-with-labels
    [(dsl/mov :r0 0)
     (jmp-imm :jeq :r1 0 :success)
     (dsl/mov :r0 -1)
     (jmp :done)
     (label :success)
     (dsl/mov :r0 1)
     (label :done)
     (dsl/exit-insn)])
sourceraw docstring

check-boundsclj

(check-bounds data-reg data-end-reg offset fail-label scratch-reg)

Generate bounds check with symbolic label for failure.

Like net/check-bounds but accepts keyword labels.

Parameters:

  • data-reg: Register containing data pointer
  • data-end-reg: Register containing data_end pointer
  • offset: Number of bytes needed
  • fail-label: Label (keyword) or offset (number) to jump on failure
  • scratch-reg: Scratch register for calculation

Example: (check-bounds :r7 :r8 14 :pass :r9)

Generate bounds check with symbolic label for failure.

Like net/check-bounds but accepts keyword labels.

Parameters:
- data-reg: Register containing data pointer
- data-end-reg: Register containing data_end pointer
- offset: Number of bytes needed
- fail-label: Label (keyword) or offset (number) to jump on failure
- scratch-reg: Scratch register for calculation

Example:
  (check-bounds :r7 :r8 14 :pass :r9)
sourceraw docstring

check-bounds-dynamicclj

(check-bounds-dynamic data-reg data-end-reg offset-reg fail-label scratch-reg)

Generate bounds check with dynamic offset.

Parameters:

  • data-reg: Register containing data pointer
  • data-end-reg: Register containing data_end pointer
  • offset-reg: Register containing offset value
  • fail-label: Label (keyword) or offset (number) to jump on failure
  • scratch-reg: Scratch register for calculation
Generate bounds check with dynamic offset.

Parameters:
- data-reg: Register containing data pointer
- data-end-reg: Register containing data_end pointer
- offset-reg: Register containing offset value
- fail-label: Label (keyword) or offset (number) to jump on failure
- scratch-reg: Scratch register for calculation
sourceraw docstring

instruction-sizeclj

(instruction-size insn)

Return the size of an instruction in 8-byte units. Most instructions are 1, but lddw (64-bit immediate load) is 2.

Return the size of an instruction in 8-byte units.
Most instructions are 1, but lddw (64-bit immediate load) is 2.
sourceraw docstring

jaclj

source

jmpclj

(jmp target)

Unconditional jump to symbolic target.

Parameters:

  • target: Jump target - keyword label or numeric offset

Example: (jmp :done) ; symbolic (jmp 5) ; numeric

Unconditional jump to symbolic target.

Parameters:
- target: Jump target - keyword label or numeric offset

Example:
  (jmp :done)   ; symbolic
  (jmp 5)       ; numeric
sourceraw docstring

jmp-immclj

(jmp-imm op dst imm target)

Conditional jump with immediate operand and symbolic target.

Parameters:

  • op: Jump operation (:jeq, :jne, :jgt, :jge, :jlt, :jle, :jset, :jsgt, :jsge, :jslt, :jsle)
  • dst: Destination register
  • imm: Immediate value to compare
  • target: Jump target - keyword label or numeric offset

If target is a keyword, it will be resolved during assembly. If target is a number, works like dsl/jmp-imm.

Example: (jmp-imm :jeq :r0 0 :is-zero) ; symbolic (jmp-imm :jeq :r0 0 5) ; numeric (backwards compat)

Conditional jump with immediate operand and symbolic target.

Parameters:
- op: Jump operation (:jeq, :jne, :jgt, :jge, :jlt, :jle, :jset, :jsgt, :jsge, :jslt, :jsle)
- dst: Destination register
- imm: Immediate value to compare
- target: Jump target - keyword label or numeric offset

If target is a keyword, it will be resolved during assembly.
If target is a number, works like dsl/jmp-imm.

Example:
  (jmp-imm :jeq :r0 0 :is-zero)   ; symbolic
  (jmp-imm :jeq :r0 0 5)          ; numeric (backwards compat)
sourceraw docstring

jmp-regclj

(jmp-reg op dst src target)

Conditional jump with register operand and symbolic target.

Parameters:

  • op: Jump operation
  • dst: First register to compare
  • src: Second register to compare
  • target: Jump target - keyword label or numeric offset

Example: (jmp-reg :jgt :r0 :r1 :greater) ; symbolic (jmp-reg :jgt :r0 :r1 3) ; numeric

Conditional jump with register operand and symbolic target.

Parameters:
- op: Jump operation
- dst: First register to compare
- src: Second register to compare
- target: Jump target - keyword label or numeric offset

Example:
  (jmp-reg :jgt :r0 :r1 :greater)  ; symbolic
  (jmp-reg :jgt :r0 :r1 3)         ; numeric
sourceraw docstring

labelclj

(label name)

Create a label pseudo-instruction. Labels mark positions in the instruction stream for jump targets. They don't generate bytecode - they're resolved during assembly.

Parameters:

  • name: Keyword naming the label (e.g., :loop, :error, :done)

Example: (label :my-target)

Create a label pseudo-instruction.
Labels mark positions in the instruction stream for jump targets.
They don't generate bytecode - they're resolved during assembly.

Parameters:
- name: Keyword naming the label (e.g., :loop, :error, :done)

Example:
  (label :my-target)
sourceraw docstring

label?clj

(label? insn)

Check if instruction is a label pseudo-instruction.

Check if instruction is a label pseudo-instruction.
sourceraw docstring

real-instruction?clj

(real-instruction? insn)

Check if this counts as a real instruction (not a label). Used for position counting.

Check if this counts as a real instruction (not a label).
Used for position counting.
sourceraw docstring

resolve-labelsclj

(resolve-labels instructions)

Resolve symbolic labels to numeric offsets.

Two-pass algorithm:

  1. Collect all label positions
  2. Resolve jump targets and filter out labels

Parameters:

  • instructions: Sequence of instructions (may include labels and symbolic jumps)

Returns: Sequence of resolved instructions (byte arrays only, no labels)

Resolve symbolic labels to numeric offsets.

Two-pass algorithm:
1. Collect all label positions
2. Resolve jump targets and filter out labels

Parameters:
- instructions: Sequence of instructions (may include labels and symbolic jumps)

Returns: Sequence of resolved instructions (byte arrays only, no labels)
sourceraw docstring

symbolic-jump?clj

(symbolic-jump? insn)

Check if instruction is a symbolic jump (with keyword target).

Check if instruction is a symbolic jump (with keyword target).
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close