#!/bin/sh
# DF-1141 fix compile-validation build script.
#
# Context: amdgpu (sys/dev/drm/amd/amdgpu/ci_dpm.c) is NOT in the GENERIC
# kernel and cannot attach on this QEMU guest (no AMD GPU). The bug is a
# latent VBIOS-parsing OOB write. We cannot trigger it at runtime, so this
# "build" validates that the cited code is real AND that fix.diff compiles
# against the live kernel headers with -Werror.
#
# Run as root on the guest (with-src snapshot):
#   cd /usr/src && patch -p1 --forward < /root/df1141.diff   # apply fix
#   cd sys/dev/drm/amd/amdgpu && rm -f ci_dpm.o && make ci_dpm.o
#
# This script performs the apply + incremental compile of ci_dpm.c.
set -e
DIFF="${1:-fix.diff}"
cd /usr/src
patch -p1 --forward < "/root/$(basename "$DIFF")" || true
cd sys/dev/drm/amd/amdgpu
rm -f ci_dpm.o
make ci_dpm.o
echo "DF-1141 fix compiled clean (ci_dpm.o produced, -Werror)"
