# tiann/kernelsu architecture

> Architecture diagram of the GitHub repository tiann/kernelsu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tiann/kernelsu
- Repository: https://github.com/tiann/kernelsu

## Overview

KernelSU is an Android kernel-based root solution, with an Android manager and a companion userspace daemon. The main flow is a manager or privileged app requesting root or configuration through the shared ioctl interface; kernel dispatch applies access policy and performs the requested operation. The repository also documents metamodules and app profiles, and includes boot/init integration, SELinux controls, and a superuser log. Edges reflect README statements or relationships named in sampled files; unsampled feature wiring is left unverified.

Main entry points: [`kernel/supercall/dispatch.c`](https://github.com/tiann/kernelsu/blob/main/kernel/supercall/dispatch.c) (Supercall dispatch), [`kernel/core/init.c`](https://github.com/tiann/kernelsu/blob/main/kernel/core/init.c) (Kernel init), [`userspace/ksud/src/main.rs`](https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/main.rs) (Daemon entry), [`kernel/runtime/ksud_integration.c`](https://github.com/tiann/kernelsu/blob/main/kernel/runtime/ksud_integration.c) (Boot integration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_kernel["Kernel runtime"]
  node_kernel_init["Kernel init<br/>[init.c]"]
  node_syscall_hooks["Syscall hooks"]
  node_supercall["Supercall dispatch<br/>[dispatch.c]"]
  node_allowlist["Root policy<br/>[allowlist.c]"]
  node_boot_integration["Boot integration<br/>[ksud_integration.c]"]
  node_uapi["Kernel API<br/>[supercall.h]"]
end

subgraph group_daemon["Userspace daemon"]
  node_daemon_cli["Daemon CLI<br/>[cli.rs]"]
  node_daemon_entry["Daemon entry<br/>[main.rs]"]
end

subgraph group_manager["Android manager"]
  node_manager_app["Manager app<br/>[MainActivity.kt]"]
  node_native_bridge["Native bridge<br/>[jni.cc]"]
  node_manager_service["Manager service<br/>[KsuService.kt]"]
  node_webui["Web interface<br/>[WebUIScreen.kt]"]
end

subgraph group_domain["Root capabilities"]
  node_metamodules["Metamodules<br/>[metamodule.rs]"]
  node_module_system["Module system<br/>[module.rs]"]
  node_app_profiles["App profiles<br/>[app_profile.c]"]
  node_selinux["SELinux controls<br/>[sepolicy.c]"]
  node_selinux_hide["SELinux hiding<br/>[selinux_hide.c]"]
  node_sulog["Superuser log<br/>[event.c]"]
end

node_user(("Android user"))

node_user -->|"manages root"| node_manager_app
node_manager_app -.->|"uses bridge"| node_native_bridge
node_native_bridge -.->|"requests operations"| node_uapi
node_daemon_entry -->|"dispatches"| node_daemon_cli
node_daemon_cli -.->|"issues commands"| node_uapi
node_kernel_init -->|"initializes"| node_syscall_hooks
node_kernel_init -->|"initializes"| node_supercall
node_supercall -->|"checks policy"| node_allowlist
node_supercall -->|"handles profiles"| node_app_profiles
node_supercall -->|"sets policy"| node_selinux
node_supercall -->|"installs log fd"| node_sulog
node_kernel_init -->|"references controls"| node_selinux
node_kernel_init -->|"initializes"| node_boot_integration
node_boot_integration -->|"uses feature"| node_selinux_hide
node_daemon_entry -->|"includes subsystem"| node_metamodules
node_daemon_entry -->|"includes subsystem"| node_module_system
node_user -.->|"uses root service"| node_manager_service
node_user -.->|"opens interface"| node_webui

click node_manager_app "https://github.com/tiann/kernelsu/blob/main/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt"
click node_native_bridge "https://github.com/tiann/kernelsu/blob/main/manager/app/src/main/cpp/jni.cc"
click node_daemon_cli "https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/cli.rs"
click node_daemon_entry "https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/main.rs"
click node_metamodules "https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/metamodule.rs"
click node_module_system "https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/module.rs"
click node_app_profiles "https://github.com/tiann/kernelsu/blob/main/kernel/policy/app_profile.c"
click node_kernel_init "https://github.com/tiann/kernelsu/blob/main/kernel/core/init.c"
click node_syscall_hooks "https://github.com/tiann/kernelsu/blob/main/kernel/hook/syscall_hook_manager.c"
click node_supercall "https://github.com/tiann/kernelsu/blob/main/kernel/supercall/dispatch.c"
click node_allowlist "https://github.com/tiann/kernelsu/blob/main/kernel/policy/allowlist.c"
click node_selinux "https://github.com/tiann/kernelsu/blob/main/kernel/selinux/sepolicy.c"
click node_selinux_hide "https://github.com/tiann/kernelsu/blob/main/kernel/feature/selinux_hide.c"
click node_boot_integration "https://github.com/tiann/kernelsu/blob/main/kernel/runtime/ksud_integration.c"
click node_sulog "https://github.com/tiann/kernelsu/blob/main/kernel/sulog/event.c"
click node_uapi "https://github.com/tiann/kernelsu/blob/main/uapi/supercall.h"
click node_manager_service "https://github.com/tiann/kernelsu/blob/main/manager/app/src/main/java/me/weishu/kernelsu/ui/KsuService.kt"
click node_webui "https://github.com/tiann/kernelsu/blob/main/manager/app/src/main/java/me/weishu/kernelsu/ui/webui/WebUIScreen.kt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_kernel_init,node_syscall_hooks,node_supercall,node_allowlist,node_boot_integration,node_uapi,node_user toneBlue
class node_daemon_cli,node_daemon_entry toneAmber
class node_manager_app,node_native_bridge,node_manager_service,node_webui toneMint
class node_metamodules,node_module_system,node_app_profiles,node_selinux,node_selinux_hide,node_sulog toneRose
```

## Components

### Kernel runtime

- [Kernel init](https://github.com/tiann/kernelsu/blob/main/kernel/core/init.c): `kernel/core/init.c`
- [Syscall hooks](https://github.com/tiann/kernelsu/blob/main/kernel/hook/syscall_hook_manager.c): `kernel/hook/syscall_hook_manager.c`
- [Supercall dispatch](https://github.com/tiann/kernelsu/blob/main/kernel/supercall/dispatch.c): `kernel/supercall/dispatch.c`
- [Root policy](https://github.com/tiann/kernelsu/blob/main/kernel/policy/allowlist.c): `kernel/policy/allowlist.c`
- [Boot integration](https://github.com/tiann/kernelsu/blob/main/kernel/runtime/ksud_integration.c): `kernel/runtime/ksud_integration.c`
- [Kernel API](https://github.com/tiann/kernelsu/blob/main/uapi/supercall.h): `uapi/supercall.h`

### Userspace daemon

- [Daemon CLI](https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/cli.rs): `userspace/ksud/src/cli.rs`
- [Daemon entry](https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/main.rs): `userspace/ksud/src/main.rs`

### Android manager

- [Manager app](https://github.com/tiann/kernelsu/blob/main/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt): `manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt`
- [Native bridge](https://github.com/tiann/kernelsu/blob/main/manager/app/src/main/cpp/jni.cc): `manager/app/src/main/cpp/jni.cc`
- [Manager service](https://github.com/tiann/kernelsu/blob/main/manager/app/src/main/java/me/weishu/kernelsu/ui/KsuService.kt): `manager/app/src/main/java/me/weishu/kernelsu/ui/KsuService.kt`
- [Web interface](https://github.com/tiann/kernelsu/blob/main/manager/app/src/main/java/me/weishu/kernelsu/ui/webui/WebUIScreen.kt): `manager/app/src/main/java/me/weishu/kernelsu/ui/webui/WebUIScreen.kt`

### Root capabilities

- [Metamodules](https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/metamodule.rs): `userspace/ksud/src/metamodule.rs`
- [Module system](https://github.com/tiann/kernelsu/blob/main/userspace/ksud/src/module.rs): `userspace/ksud/src/module.rs`
- [App profiles](https://github.com/tiann/kernelsu/blob/main/kernel/policy/app_profile.c): `kernel/policy/app_profile.c`
- [SELinux controls](https://github.com/tiann/kernelsu/blob/main/kernel/selinux/sepolicy.c): `kernel/selinux/sepolicy.c`
- [SELinux hiding](https://github.com/tiann/kernelsu/blob/main/kernel/feature/selinux_hide.c): `kernel/feature/selinux_hide.c`
- [Superuser log](https://github.com/tiann/kernelsu/blob/main/kernel/sulog/event.c): `kernel/sulog/event.c`

### Other components

- **Android user**

## Connections

- Android user → Manager app: manages root
- Manager app → Native bridge: uses bridge
- Native bridge → Kernel API: requests operations
- Daemon entry → Daemon CLI: dispatches (evidence: `userspace/ksud/src/main.rs`)
- Daemon CLI → Kernel API: issues commands
- Kernel init → Syscall hooks: initializes (evidence: `kernel/core/init.c`)
- Kernel init → Supercall dispatch: initializes (evidence: `kernel/core/init.c`)
- Supercall dispatch → Root policy: checks policy (evidence: `kernel/supercall/dispatch.c`)
- Supercall dispatch → App profiles: handles profiles (evidence: `kernel/supercall/dispatch.c`)
- Supercall dispatch → SELinux controls: sets policy (evidence: `kernel/supercall/dispatch.c`)
- Supercall dispatch → Superuser log: installs log fd (evidence: `kernel/supercall/dispatch.c`)
- Kernel init → SELinux controls: references controls (evidence: `kernel/core/init.c`)
- Kernel init → Boot integration: initializes (evidence: `kernel/core/init.c`)
- Boot integration → SELinux hiding: uses feature (evidence: `kernel/runtime/ksud_integration.c`)
- Daemon entry → Metamodules: includes subsystem (evidence: `userspace/ksud/src/main.rs`)
- Daemon entry → Module system: includes subsystem (evidence: `userspace/ksud/src/main.rs`)
- Android user → Manager service: uses root service
- Android user → Web interface: opens interface
