Liking cljdoc? Tell your friends :D

clj-ebpf.utils

Utility functions for BPF programming using Panama FFI

Utility functions for BPF programming using Panama FFI
raw docstring

allocate-memoryclj

(allocate-memory size)

Allocate native memory of given size

Allocate native memory of given size
sourceraw docstring

amd64?clj

(amd64?)

Check if running on AMD64/x86_64 architecture.

Check if running on AMD64/x86_64 architecture.
sourceraw docstring

arch-infoclj

(arch-info)

Get comprehensive architecture information.

Returns map with:

  • :arch - Architecture keyword (:amd64, :arm64, etc.)
  • :arch-name - Human-readable name
  • :os-arch - OS property value
  • :os-name - Operating system name
  • :os-version - OS version
  • :pointer-size - Pointer size in bytes
  • :java-version - Java version
  • :endianness - Byte order (:little or :big)

Example: (arch-info) ; => {:arch :arm64 ; :arch-name "ARM64" ; :os-arch "aarch64" ; :os-name "Linux" ; :os-version "6.14.0-33-generic" ; :pointer-size 8 ; :java-version "17.0.9" ; :endianness :little}

Get comprehensive architecture information.

Returns map with:
- :arch - Architecture keyword (:amd64, :arm64, etc.)
- :arch-name - Human-readable name
- :os-arch - OS property value
- :os-name - Operating system name
- :os-version - OS version
- :pointer-size - Pointer size in bytes
- :java-version - Java version
- :endianness - Byte order (:little or :big)

Example:
  (arch-info)
  ; => {:arch :arm64
  ;     :arch-name "ARM64"
  ;     :os-arch "aarch64"
  ;     :os-name "Linux"
  ;     :os-version "6.14.0-33-generic"
  ;     :pointer-size 8
  ;     :java-version "17.0.9"
  ;     :endianness :little}
sourceraw docstring

arch-nameclj

(arch-name)

Get human-readable architecture name.

Example: (arch-name) ; => "AMD64" or "ARM64"

Get human-readable architecture name.

Example:
  (arch-name)  ; => "AMD64" or "ARM64"
sourceraw docstring

arm32?clj

(arm32?)

Check if running on 32-bit ARM architecture.

Check if running on 32-bit ARM architecture.
sourceraw docstring

arm64?clj

(arm64?)

Check if running on ARM64/aarch64 architecture.

Check if running on ARM64/aarch64 architecture.
sourceraw docstring

bpf-fs-mounted?clj

(bpf-fs-mounted?)

Check if BPF filesystem is mounted

Check if BPF filesystem is mounted
sourceraw docstring

bytes->intclj

(bytes->int bytes)

Convert byte array to 32-bit integer (little-endian)

Convert byte array to 32-bit integer (little-endian)
sourceraw docstring

bytes->longclj

(bytes->long bytes)

Convert byte array to 64-bit long (little-endian)

Convert byte array to 64-bit long (little-endian)
sourceraw docstring

bytes->percpu-valuesclj

(bytes->percpu-values bytes
                      value-deserializer
                      value-size
                      &
                      {:keys [num-cpus] :or {num-cpus (get-cpu-count)}})

Deserialize a flat byte array into a vector of per-CPU values.

Parameters:

  • bytes: Byte array of size (value-size * num-cpus)
  • value-deserializer: Function to deserialize bytes to value
  • value-size: Size of each value in bytes
  • num-cpus: Number of CPUs (defaults to system CPU count)

Returns a vector of values, one per CPU

Deserialize a flat byte array into a vector of per-CPU values.

Parameters:
- bytes: Byte array of size (value-size * num-cpus)
- value-deserializer: Function to deserialize bytes to value
- value-size: Size of each value in bytes
- num-cpus: Number of CPUs (defaults to system CPU count)

Returns a vector of values, one per CPU
sourceraw docstring

bytes->pointerclj

source

bytes->segmentclj

(bytes->segment bytes)

Write bytes to a newly allocated memory segment

Write bytes to a newly allocated memory segment
sourceraw docstring

bytes->shortclj

(bytes->short bytes)

Convert byte array to 16-bit short (little-endian)

Convert byte array to 16-bit short (little-endian)
sourceraw docstring

check-bpf-availableclj

(check-bpf-available)

Check if BPF is available and accessible

Check if BPF is available and accessible
sourceraw docstring

ensure-bpf-fsclj

(ensure-bpf-fs)

Ensure BPF filesystem is mounted, return path

Ensure BPF filesystem is mounted, return path
sourceraw docstring

file-exists?clj

(file-exists? path)

Check if file exists

Check if file exists
sourceraw docstring

get-archclj

(get-arch)

Get the current system architecture.

Returns one of:

  • :amd64 (x86_64)
  • :arm64 (aarch64)
  • :arm32 (armv7l, armv6l)
  • :unknown

Example: (get-arch) ; => :amd64 or :arm64

Get the current system architecture.

Returns one of:
- :amd64 (x86_64)
- :arm64 (aarch64)
- :arm32 (armv7l, armv6l)
- :unknown

Example:
  (get-arch)  ; => :amd64 or :arm64
sourceraw docstring

get-bpf-fs-pathclj

(get-bpf-fs-path)

Get BPF filesystem mount path

Get BPF filesystem mount path
sourceraw docstring

get-cpu-countclj

(get-cpu-count)

Get the number of CPUs available on the system.

This is used for per-CPU map operations, where each CPU has its own independent value for each key. Returns the number of available processors.

Get the number of CPUs available on the system.

This is used for per-CPU map operations, where each CPU has its own
independent value for each key. Returns the number of available processors.
sourceraw docstring

get-kernel-versionclj

(get-kernel-version)

Get current kernel version as integer

Get current kernel version as integer
sourceraw docstring

has-cap-bpf?clj

(has-cap-bpf?)

Check if process has CAP_BPF capability

Check if process has CAP_BPF capability
sourceraw docstring

hex-dumpclj

(hex-dump bytes & {:keys [offset limit] :or {offset 0 limit 256}})

Create hex dump of bytes

Create hex dump of bytes
sourceraw docstring

host-endian?clj

(host-endian?)

Check if host is little-endian

Check if host is little-endian
sourceraw docstring

int->bytesclj

(int->bytes n)

Convert 32-bit integer to byte array (little-endian)

Convert 32-bit integer to byte array (little-endian)
sourceraw docstring

int->pointerclj

source

int->segmentclj

(int->segment n)

Convert integer to memory segment

Convert integer to memory segment
sourceraw docstring

long->bytesclj

(long->bytes n)

Convert 64-bit long to byte array (little-endian)

Convert 64-bit long to byte array (little-endian)
sourceraw docstring

long->pointerclj

source

long->segmentclj

(long->segment n)

Convert long to memory segment

Convert long to memory segment
sourceraw docstring

pack-structclj

(pack-struct spec)

Pack a struct definition into bytes Spec is a vector of [type value] pairs where type is :u8, :u16, :u32, :u64, :i8, :i16, :i32, :i64

Pack a struct definition into bytes
Spec is a vector of [type value] pairs where type is :u8, :u16, :u32, :u64, :i8, :i16, :i32, :i64
sourceraw docstring

parse-kernel-versionclj

(parse-kernel-version version-str)

Parse kernel version string into integer (e.g., '5.15.0' -> 0x050f00)

Parse kernel version string into integer (e.g., '5.15.0' -> 0x050f00)
sourceraw docstring

percpu-values->bytesclj

(percpu-values->bytes values
                      value-serializer
                      value-size
                      &
                      {:keys [num-cpus] :or {num-cpus (get-cpu-count)}})

Serialize a vector of per-CPU values into a flat byte array.

Parameters:

  • values: Vector of values, one per CPU (or single value to replicate to all CPUs)
  • value-serializer: Function to serialize each value to bytes
  • value-size: Size of each value in bytes
  • num-cpus: Number of CPUs (defaults to system CPU count)

Returns a byte array of size (value-size * num-cpus)

Serialize a vector of per-CPU values into a flat byte array.

Parameters:
- values: Vector of values, one per CPU (or single value to replicate to all CPUs)
- value-serializer: Function to serialize each value to bytes
- value-size: Size of each value in bytes
- num-cpus: Number of CPUs (defaults to system CPU count)

Returns a byte array of size (value-size * num-cpus)
sourceraw docstring

pointer->bytesclj

source

pointer->intclj

source

pointer->longclj

source

pointer->stringclj

source

pointer-sizeclj

(pointer-size)

Get pointer size for current architecture in bytes.

Returns:

  • 8 for 64-bit architectures (AMD64, ARM64)
  • 4 for 32-bit architectures (ARM32)

Example: (pointer-size) ; => 8 on 64-bit systems

Get pointer size for current architecture in bytes.

Returns:
- 8 for 64-bit architectures (AMD64, ARM64)
- 4 for 32-bit architectures (ARM32)

Example:
  (pointer-size)  ; => 8 on 64-bit systems
sourceraw docstring

(print-arch-info)

Print architecture information to stdout.

Example: (print-arch-info) ; Architecture: ARM64 (aarch64) ; OS: Linux 6.14.0-33-generic ; Java: 17.0.9 ; Pointer size: 8 bytes ; Endianness: little-endian

Print architecture information to stdout.

Example:
  (print-arch-info)
  ; Architecture: ARM64 (aarch64)
  ; OS: Linux 6.14.0-33-generic
  ; Java: 17.0.9
  ; Pointer size: 8 bytes
  ; Endianness: little-endian
sourceraw docstring

read-file-bytesclj

(read-file-bytes path)

Read entire file as byte array

Read entire file as byte array
sourceraw docstring

segment->bytesclj

(segment->bytes seg size)

Read bytes from a memory segment

Read bytes from a memory segment
sourceraw docstring

segment->intclj

(segment->int seg)

Read integer from memory segment

Read integer from memory segment
sourceraw docstring

segment->longclj

(segment->long seg)

Read long from memory segment

Read long from memory segment
sourceraw docstring

segment->stringclj

(segment->string seg max-len)

Read null-terminated string from memory segment

Read null-terminated string from memory segment
sourceraw docstring

short->bytesclj

(short->bytes n)

Convert 16-bit short to byte array (little-endian)

Convert 16-bit short to byte array (little-endian)
sourceraw docstring

string->pointerclj

source

string->segmentclj

(string->segment s)

Convert string to null-terminated memory segment

Convert string to null-terminated memory segment
sourceraw docstring

unpack-structclj

(unpack-struct bytes spec)

Unpack bytes into struct values according to spec Spec is a vector of types: :u8, :u16, :u32, :u64, :i8, :i16, :i32, :i64

Unpack bytes into struct values according to spec
Spec is a vector of types: :u8, :u16, :u32, :u64, :i8, :i16, :i32, :i64
sourceraw docstring

with-arenaclj

(with-arena f)

Execute function with a confined arena for memory allocations

Execute function with a confined arena for memory allocations
sourceraw docstring

with-fdcljmacro

(with-fd [binding expr] & body)

Ensure file descriptor is closed after use

Ensure file descriptor is closed after use
sourceraw docstring

with-memorycljmacro

(with-memory [binding size] & body)

Allocate memory and ensure it's cleaned up

Allocate memory and ensure it's cleaned up
sourceraw docstring

zero-memoryclj

(zero-memory seg size)

Zero out memory segment

Zero out memory segment
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