Utility functions for BPF programming using Panama FFI
Utility functions for BPF programming using Panama FFI
(allocate-memory size)Allocate native memory of given size
Allocate native memory of given size
(amd64?)Check if running on AMD64/x86_64 architecture.
Check if running on AMD64/x86_64 architecture.
(arch-info)Get comprehensive architecture information.
Returns map with:
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}(arch-name)Get human-readable architecture name.
Example: (arch-name) ; => "AMD64" or "ARM64"
Get human-readable architecture name. Example: (arch-name) ; => "AMD64" or "ARM64"
(arm32?)Check if running on 32-bit ARM architecture.
Check if running on 32-bit ARM architecture.
(arm64?)Check if running on ARM64/aarch64 architecture.
Check if running on ARM64/aarch64 architecture.
(bpf-fs-mounted?)Check if BPF filesystem is mounted
Check if BPF filesystem is mounted
(bytes->int bytes)Convert byte array to 32-bit integer (little-endian)
Convert byte array to 32-bit integer (little-endian)
(bytes->long bytes)Convert byte array to 64-bit long (little-endian)
Convert byte array to 64-bit long (little-endian)
(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:
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
(bytes->segment bytes)Write bytes to a newly allocated memory segment
Write bytes to a newly allocated memory segment
(bytes->short bytes)Convert byte array to 16-bit short (little-endian)
Convert byte array to 16-bit short (little-endian)
(check-bpf-available)Check if BPF is available and accessible
Check if BPF is available and accessible
(ensure-bpf-fs)Ensure BPF filesystem is mounted, return path
Ensure BPF filesystem is mounted, return path
(get-arch)Get the current system architecture.
Returns one of:
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
(get-bpf-fs-path)Get BPF filesystem mount path
Get BPF filesystem mount path
(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.
(get-kernel-version)Get current kernel version as integer
Get current kernel version as integer
(has-cap-bpf?)Check if process has CAP_BPF capability
Check if process has CAP_BPF capability
(hex-dump bytes & {:keys [offset limit] :or {offset 0 limit 256}})Create hex dump of bytes
Create hex dump of bytes
(host-endian?)Check if host is little-endian
Check if host is little-endian
(int->bytes n)Convert 32-bit integer to byte array (little-endian)
Convert 32-bit integer to byte array (little-endian)
(int->segment n)Convert integer to memory segment
Convert integer to memory segment
(long->bytes n)Convert 64-bit long to byte array (little-endian)
Convert 64-bit long to byte array (little-endian)
(long->segment n)Convert long to memory segment
Convert long to memory segment
(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
(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)
(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:
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)
(pointer-size)Get pointer size for current architecture in bytes.
Returns:
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
(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
(read-file-bytes path)Read entire file as byte array
Read entire file as byte array
(segment->bytes seg size)Read bytes from a memory segment
Read bytes from a memory segment
(segment->int seg)Read integer from memory segment
Read integer from memory segment
(segment->long seg)Read long from memory segment
Read long from memory segment
(segment->string seg max-len)Read null-terminated string from memory segment
Read null-terminated string from memory segment
(short->bytes n)Convert 16-bit short to byte array (little-endian)
Convert 16-bit short to byte array (little-endian)
(string->segment s)Convert string to null-terminated memory segment
Convert string to null-terminated memory segment
(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
(with-arena f)Execute function with a confined arena for memory allocations
Execute function with a confined arena for memory allocations
(with-fd [binding expr] & body)Ensure file descriptor is closed after use
Ensure file descriptor is closed after use
(with-memory [binding size] & body)Allocate memory and ensure it's cleaned up
Allocate memory and ensure it's cleaned up
(zero-memory seg size)Zero out memory segment
Zero out memory segment
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |