Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cppcheck-suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ unmatchedSuppression
# Suppress preprocessor errors in kernel headers (configuration issues)
preprocessorErrorDirective:*/linux/bitops.h
preprocessorErrorDirective:*/linux/*.h
noValidConfiguration:src/elf_det.c
noValidConfiguration:src/elf_det.mod.c
noValidConfiguration:src/proclens_module.c
noValidConfiguration:src/proclens_module.mod.c
26 changes: 13 additions & 13 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Project Overview

This is a Linux kernel module project that provides process information through `/proc/elf_det/`. The module displays detailed process information including memory mappings, CPU usage, memory pressure statistics, and ELF binary details.
This is a Linux kernel module project that provides process information through `/proc/proclens_module/`. The module displays detailed process information including memory mappings, CPU usage, memory pressure statistics, and ELF binary details.

Current output includes memory pressure/layout, brief network stats, open sockets,
per-process I/O statistics, and thread information.
Expand Down Expand Up @@ -48,10 +48,10 @@ The pre-commit hook automatically runs format-check and cppcheck.

### Source Files (`src/`)

- `elf_det.c` / `elf_det.h` - Main kernel module and shared helpers
- `elf_det_tests.c` - Unit tests for elf_det helpers
- `proc_elf_ctrl.c` / `proc_elf_ctrl.h` - Control utility and helpers
- `proc_elf_ctrl_tests.c` - Unit tests for proc_elf_ctrl helpers
- `proclens_module.c` / `proclens_module.h` - Main kernel module and shared helpers
- `proclens_module_tests.c` - Unit tests for proclens_module helpers
- `proclens.c` / `proclens.h` - Control utility and helpers
- `proclens_tests.c` - Unit tests for proclens helpers
- `test_multithread.c` - Multi-threaded test application

### Documentation (`docs/`)
Expand Down Expand Up @@ -87,7 +87,7 @@ The pre-commit hook automatically runs format-check and cppcheck.

### Header Files

- `elf_det.h` contains helper functions that work in BOTH kernel and userspace
- `proclens_module.h` contains helper functions that work in BOTH kernel and userspace
- Use `#ifdef __KERNEL__` to separate kernel-only code
- Keep helpers pure (no side effects) for testability
- Add comprehensive documentation comments for public functions
Expand Down Expand Up @@ -119,7 +119,7 @@ When adding new helper functions to headers:

### Adding New Statistics

1. Add calculation helper to header file (e.g., `elf_det.h`)
1. Add calculation helper to header file (e.g., `proclens_module.h`)
2. Add unit tests for the helper
3. Call helper in kernel module print function
4. Update `e2e/qemu-test.sh` to validate output
Expand Down Expand Up @@ -147,10 +147,10 @@ Current implementation includes:
`avg_write_bytes_per_syscall`, `io_intensity`)

When extending I/O output:
1. Add or update helper functions in `elf_det.h`
1. Add or update helper functions in `proclens_module.h`
2. Keep division-by-zero handling explicit in helper logic
3. Update `e2e/qemu-test.sh` checks for new fields
4. Keep `proc_elf_ctrl` view filtering in sync (section key `4` for I/O)
4. Keep `proclens` view filtering in sync (section key `4` for I/O)

## Build System (Makefile)

Expand Down Expand Up @@ -234,18 +234,18 @@ Tests validate actual kernel module behavior in isolated environment.

## Key Functions Reference

### Kernel Module (`elf_det.c`)
### Kernel Module (`proclens_module.c`)

- `print_memory_pressure()` - Display memory pressure metrics
- `print_memory_layout()` - Show heap, stack, code segments
- `print_memory_layout_visualization()` - Show proportional memory map bars
- `print_io_stats()` - Display per-process I/O counters and derived metrics
- `print_network_stats()` - Display brief per-process network statistics
- `print_sockets()` - Display open sockets and endpoint details
- `elfdet_show()` - Main process information output handler
- `elfdet_threads_show()` - Thread listing output handler
- `proclens_module_show()` - Main process information output handler
- `proclens_module_threads_show()` - Thread listing output handler

### Helpers (`elf_det.h`)
### Helpers (`proclens_module.h`)

- `calculate_rss_pages()` - Compute resident set size from mm counters
- `pages_to_kb()` - Convert pages to kilobytes
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
- name: Verify build artifacts
run: |
ls -la build/
file build/elf_det.ko
file build/proc_elf_ctrl
file build/proclens_module.ko
file build/proclens
echo "Build artifacts verified successfully!"

- name: Upload build artifacts
Expand Down
215 changes: 184 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,19 @@ jobs:
printf '\n---\n'
printf '**Version**: %s | **Type**: %s\n\n' "$VERSION" "$BUMP_TYPE"
printf '## Binary package includes\n\n'
printf -- '- `amd64/elf_det.ko`\n'
printf -- '- `amd64/proc_elf_ctrl`\n'
printf -- '- `arm64/elf_det.ko`\n'
printf -- '- `arm64/proc_elf_ctrl`\n'
printf -- '- `amd64/proclens_module.ko`\n'
printf -- '- `amd64/proclens`\n'
printf -- '- `arm64/proclens_module.ko`\n'
printf -- '- `arm64/proclens`\n'
printf -- '- `install.sh`\n'
printf -- '- `uninstall.sh`\n'
printf -- '- `README-QUICKSTART.md`\n\n'
printf 'Quick Start summary:\n\n'
printf -- '- Supports Linux kernel `%s.x`\n' "${TARGET_KERNEL_BASE}"
printf -- '- Includes binaries for `amd64` (`x86_64`) and `arm64` (`aarch64`)\n'
printf -- '- Install module: `sudo insmod <arch>/elf_det.ko`\n'
printf -- '- Run user tool: `sudo ./<arch>/proc_elf_ctrl`\n'
printf -- '- Unload module: `sudo rmmod elf_det`\n'
printf -- '- Install or update: `sudo ./install.sh`\n'
printf -- '- Run user tool: `sudo proclens`\n'
printf -- '- Uninstall: `sudo ./uninstall.sh`\n'
} > /tmp/release_notes.md
else
# Manual workflow dispatch
Expand All @@ -166,17 +168,19 @@ jobs:
printf -- '- Manual release triggered via workflow dispatch.\n\n'
printf '**Version**: %s | **Type**: %s\n\n' "$VERSION" "$BUMP_TYPE"
printf '## Binary package includes\n\n'
printf -- '- `amd64/elf_det.ko`\n'
printf -- '- `amd64/proc_elf_ctrl`\n'
printf -- '- `arm64/elf_det.ko`\n'
printf -- '- `arm64/proc_elf_ctrl`\n'
printf -- '- `amd64/proclens_module.ko`\n'
printf -- '- `amd64/proclens`\n'
printf -- '- `arm64/proclens_module.ko`\n'
printf -- '- `arm64/proclens`\n'
printf -- '- `install.sh`\n'
printf -- '- `uninstall.sh`\n'
printf -- '- `README-QUICKSTART.md`\n\n'
printf 'Quick Start summary:\n\n'
printf -- '- Supports Linux kernel `%s.x`\n' "${TARGET_KERNEL_BASE}"
printf -- '- Includes binaries for `amd64` (`x86_64`) and `arm64` (`aarch64`)\n'
printf -- '- Install module: `sudo insmod <arch>/elf_det.ko`\n'
printf -- '- Run user tool: `sudo ./<arch>/proc_elf_ctrl`\n'
printf -- '- Unload module: `sudo rmmod elf_det`\n'
printf -- '- Install or update: `sudo ./install.sh`\n'
printf -- '- Run user tool: `sudo proclens`\n'
printf -- '- Uninstall: `sudo ./uninstall.sh`\n'
} > /tmp/release_notes.md
fi

Expand Down Expand Up @@ -215,6 +219,7 @@ jobs:
- name: Build binaries for target kernel
env:
TARGET_ARCH: ${{ matrix.arch }}
RELEASE_TAG: ${{ needs.prepare_release.outputs.release_tag }}
run: |
set -euo pipefail

Expand All @@ -228,13 +233,13 @@ jobs:

echo "Using kernel headers: $KDIR"

make KDIR="$KDIR" clean
make KDIR="$KDIR" module
make user
make KDIR="$KDIR" PROCLENS_VERSION="$RELEASE_TAG" clean
make KDIR="$KDIR" PROCLENS_VERSION="$RELEASE_TAG" module
make PROCLENS_VERSION="$RELEASE_TAG" user

mkdir -p "out/${TARGET_ARCH}"
cp build/elf_det.ko "out/${TARGET_ARCH}/elf_det.ko"
cp build/proc_elf_ctrl "out/${TARGET_ARCH}/proc_elf_ctrl"
cp build/proclens_module.ko "out/${TARGET_ARCH}/proclens_module.ko"
cp build/proclens "out/${TARGET_ARCH}/proclens"

- name: Upload architecture binaries
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -276,18 +281,152 @@ jobs:
run: |
set -euo pipefail

PKG_NAME="elf_det-binaries-${RELEASE_TAG}-linux-${TARGET_KERNEL_BASE}"
PKG_NAME="proclens_module-binaries-${RELEASE_TAG}-linux-${TARGET_KERNEL_BASE}"
PKG_DIR="dist/${PKG_NAME}"
ARCHIVE_PATH="dist/${PKG_NAME}.tar.gz"

mkdir -p "$PKG_DIR/amd64" "$PKG_DIR/arm64"

cp dist/artifacts/binaries-amd64/elf_det.ko "$PKG_DIR/amd64/"
cp dist/artifacts/binaries-amd64/proc_elf_ctrl "$PKG_DIR/amd64/"
cp dist/artifacts/binaries-arm64/elf_det.ko "$PKG_DIR/arm64/"
cp dist/artifacts/binaries-arm64/proc_elf_ctrl "$PKG_DIR/arm64/"
cp dist/artifacts/binaries-amd64/proclens_module.ko "$PKG_DIR/amd64/"
cp dist/artifacts/binaries-amd64/proclens "$PKG_DIR/amd64/"
cp dist/artifacts/binaries-arm64/proclens_module.ko "$PKG_DIR/arm64/"
cp dist/artifacts/binaries-arm64/proclens "$PKG_DIR/arm64/"

chmod +x "$PKG_DIR/amd64/proclens" "$PKG_DIR/arm64/proclens"

cat > "$PKG_DIR/install.sh" << 'EOF'
#!/usr/bin/env bash
set -euo pipefail

usage() {
cat << 'USAGE'
Usage: sudo ./install.sh [--arch amd64|arm64]

Installs or updates both components:
- Kernel module: /lib/modules/$(uname -r)/extra/proclens_module.ko
- User binary: /usr/local/bin/proclens

Behavior:
- Detects architecture automatically (x86_64 -> amd64, aarch64 -> arm64)
- If module is already loaded, unloads it first
- Replaces previously installed binaries (update-in-place)
- Runs depmod and loads module with modprobe (fallback: insmod)
USAGE
}

if [[ "${EUID}" -ne 0 ]]; then
echo "Please run as root: sudo ./install.sh"
exit 1
fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

ARCH=""
if [[ $# -gt 0 ]]; then
case "$1" in
--arch)
ARCH="${2:-}"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1"
usage
exit 1
;;
esac
fi

if [[ -z "$ARCH" ]]; then
case "$(uname -m)" in
x86_64)
ARCH="amd64"
;;
aarch64|arm64)
ARCH="arm64"
;;
*)
echo "Unsupported architecture: $(uname -m)"
echo "Use --arch amd64|arm64"
exit 1
;;
esac
fi

if [[ "$ARCH" != "amd64" && "$ARCH" != "arm64" ]]; then
echo "Invalid --arch value: $ARCH"
echo "Use amd64 or arm64"
exit 1
fi

SRC_MOD="$SCRIPT_DIR/$ARCH/proclens_module.ko"
SRC_BIN="$SCRIPT_DIR/$ARCH/proclens"

chmod +x "$PKG_DIR/amd64/proc_elf_ctrl" "$PKG_DIR/arm64/proc_elf_ctrl"
if [[ ! -f "$SRC_MOD" || ! -f "$SRC_BIN" ]]; then
echo "Missing release binaries for arch '$ARCH'"
exit 1
fi

KREL="$(uname -r)"
MOD_DIR="/lib/modules/$KREL/extra"
MOD_DST="$MOD_DIR/proclens_module.ko"
BIN_DST="/usr/local/bin/proclens"

echo "Installing ProcLens binaries for arch: $ARCH"
echo "Kernel release: $KREL"

if lsmod | grep -q '^proclens_module '; then
echo "Module is currently loaded; unloading old version..."
modprobe -r proclens_module || rmmod proclens_module
fi

mkdir -p "$MOD_DIR"
install -m 0644 "$SRC_MOD" "$MOD_DST"
install -m 0755 "$SRC_BIN" "$BIN_DST"

depmod "$KREL"

if ! insmod "$MOD_DST"; then
echo "insmod failed; trying modprobe..."
modprobe proclens_module
fi

echo "Install/update complete."
echo "User binary: $BIN_DST"
echo "Module file: $MOD_DST"
echo "Check module version: cat /sys/module/proclens_module/version"
echo "Check user version: sudo proclens --version"
EOF

cat > "$PKG_DIR/uninstall.sh" << 'EOF'
#!/usr/bin/env bash
set -euo pipefail

if [[ "${EUID}" -ne 0 ]]; then
echo "Please run as root: sudo ./uninstall.sh"
exit 1
fi

KREL="$(uname -r)"
MOD_DST="/lib/modules/$KREL/extra/proclens_module.ko"
BIN_DST="/usr/local/bin/proclens"

if lsmod | grep -q '^proclens_module '; then
echo "Unloading proclens_module module..."
modprobe -r proclens_module || rmmod proclens_module || true
fi

rm -f "$MOD_DST"
rm -f "$BIN_DST"
depmod "$KREL"

echo "Uninstall complete."
EOF

chmod +x "$PKG_DIR/install.sh" "$PKG_DIR/uninstall.sh"

cat > "$PKG_DIR/README-QUICKSTART.md" << 'EOF'
# Quick Start (Linux kernel __TARGET_KERNEL_BASE__.x)
Expand All @@ -310,25 +449,39 @@ jobs:
- `amd64/` for `x86_64`
- `arm64/` for `aarch64`

## 2) Install kernel module
## 2) Install or update

```bash
sudo ./install.sh
```

The installer:
- Installs/updates `proclens` to `/usr/local/bin/proclens`
- Installs/updates `proclens_module.ko` to `/lib/modules/$(uname -r)/extra/proclens_module.ko`
- Unloads an already-loaded `proclens_module` before update
- Runs `depmod` and loads the module

Optional (override architecture selection):

```bash
sudo insmod <arch>/elf_det.ko
lsmod | grep elf_det
sudo ./install.sh --arch amd64
# or
sudo ./install.sh --arch arm64
```

If Secure Boot is enabled, module signing may be required.

## 3) Run user program

```bash
sudo ./<arch>/proc_elf_ctrl
sudo proclens --version
sudo proclens
```

## 4) Unload module
## 4) Uninstall

```bash
sudo rmmod elf_det
sudo ./uninstall.sh
```
EOF

Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ modules.order
*.dSYM/

# Compiled user programs
proc_elf_ctrl
elf_det_ctrl
proclens

# Core dumps
core
Expand Down
Loading
Loading