# alexforster/bpfjit-sys architecture

> Architecture diagram of the GitHub repository alexforster/bpfjit-sys, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexforster/bpfjit-sys
- Repository: https://github.com/alexforster/bpfjit-sys

## Overview

##### Main Components
- Rust Interface Layer (src/lib.rs)
- BPFJIT Core (src/bpfjit/)
- SLJIT Backend (src/sljit/)
- Platform-specific Native Code Generators

**┌─────────────────────────────┐**
- Rust Application        │ (User Code)
- ┬─────────────┘
- ↓
**┌─────────────────────────────┐**
- Rust Bindings (lib.rs)   │ (FFI Interface)
- ┬─────────────┘
- ↓
**┌─────────────────────────────┐**
- BPFJIT Core Engine       │ (BPF → IR)
- ┬─────────────┘
- ↓
**┌─────────────────────────────┐**
- SLJIT Backend           │ (IR → Native Code)
- ┬─────────────┘
- ↓
**┌─────────────────────────────┐**
- Platform-Specific Codegen  │
- ┘

##### Important Details to Highlight

a. Platform Support (branch from SLJIT):
- x86 (32/64-bit)
- ARM (32/64-bit)
- MIPS (32/64-bit)
- PPC (32/64-bit)
- SPARC
- S390X

b. Memory Management:
- Different allocator options (ProtExec, WXExec)
- JIT compilation memory regions

##### Additional Elements

**BPF Filter String → Parse → IR Generation → Platform-specific Optimization → Native Code Generation**

##### Interface Points
- Public API entry points (BpfJit::new, matches)
- FFI boundary between Rust and C
- Linktype configuration options

##### Testing Components
- Test harness integration
- Verification flow

Remember to:
- Use clear labeling for all components
- Notes about critical security considerations (JIT memory management)
- Version compatibility information
- Error handling paths

##### Filter matching execution path

Each component should include version information and license annotations where appropriate.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main Components
    subgraph Application
        UserCode[User Application]:::rust
    end

    subgraph Interface
        RustBindings["Rust Bindings"]:::rust
        click RustBindings "https://github.com/alexforster/bpfjit-sys/blob/master/src/lib.rs"
    end

    subgraph BPFCore
        BPFJIT["BPFJIT Core Engine"]:::c
        click BPFJIT "https://github.com/alexforster/bpfjit-sys/blob/master/src/bpfjit/bpfjit.c"
    end

    subgraph SLJITLayer
        SLJIT["SLJIT Backend"]:::c
        click SLJIT "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitLir.c"
        Config["SLJIT Config"]:::config
        click Config "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitConfig.h"
    end

    subgraph MemoryMgmt
        ProtExec["ProtExec Allocator"]:::memory
        click ProtExec "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitProtExecAllocator.c"
        WXExec["WXExec Allocator"]:::memory
        click WXExec "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitWXExecAllocator.c"
    end

    subgraph PlatformCodegen
        direction TB
        X86["x86 (32/64-bit)"]:::platform
        click X86 "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitNativeX86_common.c"
        ARM["ARM (32/64-bit)"]:::platform
        click ARM "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitNativeARM_32.c"
        MIPS["MIPS (32/64-bit)"]:::platform
        click MIPS "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitNativeMIPS_common.c"
        PPC["PPC (32/64-bit)"]:::platform
        click PPC "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitNativePPC_common.c"
        SPARC["SPARC"]:::platform
        click SPARC "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitNativeSPARC_common.c"
        S390X["S390X"]:::platform
        click S390X "https://github.com/alexforster/bpfjit-sys/blob/master/src/sljit/sljitNativeS390X.c"
    end

    subgraph Testing
        TestHarness["Test Harness"]:::test
        click TestHarness "https://github.com/alexforster/bpfjit-sys/blob/master/tests/tests.rs"
    end

    %% Connections
    UserCode --> RustBindings
    RustBindings --> BPFJIT
    BPFJIT --> SLJIT
    SLJIT --> Config
    SLJIT --> MemoryMgmt
    SLJIT --> PlatformCodegen
    ProtExec -.-> SLJIT
    WXExec -.-> SLJIT
    TestHarness -.-> RustBindings

    %% Styles
    classDef rust fill:#6b9bc3,stroke:#333,stroke-width:2px
    classDef c fill:#95c37b,stroke:#333,stroke-width:2px
    classDef platform fill:#f4a261,stroke:#333,stroke-width:2px
    classDef memory fill:#e76f51,stroke:#333,stroke-width:2px
    classDef config fill:#2a9d8f,stroke:#333,stroke-width:2px
    classDef test fill:#8338ec,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        direction TB
        L1["Rust Component"]:::rust
        L2["C Component"]:::c
        L3["Platform-Specific"]:::platform
        L4["Memory Management"]:::memory
        L5["Configuration"]:::config
        L6["Testing"]:::test
    end
```
