mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
kmemcheck painted canaries around every kmalloc and recorded it in a table under a global lock, and checked both on kfree: a cost on every allocation of the driver. It is a heap debugging aid, so it now compiles only with DEBUG defined. A release build keeps a small header (the payload's size for ksize, and the allocation to free) and goes straight to the allocator: no canaries, no tracking, no lock. kmemcheck_enabled() returns 0 and the checks find nothing. km_clear_sensitive (the wipe in kfree_sensitive) is unchanged. The define reaches only linuxu sources, never upstream objects: the dext's linuxu objects include a generated build/gen/mlg_build_mode.h that `make lib-dext DEBUG=1` fills in (rewritten only when the mode changes, so they rebuild), and Xcode's Debug configuration defines DEBUG=1 and passes it to that make. The host library the offline tests link is always a debug build, and the tests whose leak or corruption checks rely on kmemcheck build its sources with DEBUG=1. make check-release builds lib-dext in release and fails if it carries kmemcheck's symbols (scripts/check-release.sh, whose patterns are first checked against a debug build), then runs test_kmem_release in both modes: sizes, alignment, zeroing, ksize, kmemdup and caches behave the same, and only the debug build reports a write past an object.
43 lines
1.5 KiB
Bash
Executable File
43 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# scripts/check-release.sh FILE... — fail if a release build carries
|
|
# kmemcheck (make check-release passes the dext's library).
|
|
#
|
|
# kmemcheck (canaries and a table of every kmalloc, linuxu/src/kmem) is
|
|
# compiled in only with DEBUG defined (make DEBUG=1, Xcode's Debug
|
|
# configuration). Each FILE (an archive, object or dylib) must contain none
|
|
# of its symbols. First the patterns are checked against a debug build of
|
|
# kmemcheck, so a pattern that stopped matching fails here instead of
|
|
# passing silently.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
symbols='_kmemcheck_track|_kmemcheck_untrack|_kmemcheck_scan|_kmemcheck_recs|_kmemcheck_free_slots|_kmemcheck_pattern'
|
|
|
|
found() { # FILE -> prints the matching symbols
|
|
nm -a "$1" 2>/dev/null | awk '{print $NF}' | grep -E "^($symbols)$" | sort -u || true
|
|
}
|
|
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT
|
|
clang -std=gnu11 -w -g -DDEBUG=1 -D__KERNEL__ -include linux/autoconf.h -Ilinuxu/headers \
|
|
-c linuxu/src/kmem/kmemcheck.c -o "$work/kmemcheck.o"
|
|
if [ -z "$(found "$work/kmemcheck.o")" ]; then
|
|
echo "check-release: the patterns do not match a debug build of kmemcheck; update them" >&2
|
|
exit 1
|
|
fi
|
|
|
|
status=0
|
|
for file in "$@"; do
|
|
[ -f "$file" ] || { echo "check-release: $file is missing" >&2; status=1; continue; }
|
|
hits=$(found "$file")
|
|
if [ -n "$hits" ]; then
|
|
echo "check-release: $file carries kmemcheck:" >&2
|
|
printf ' %s\n' $hits >&2
|
|
status=1
|
|
else
|
|
echo "check-release: $file: no kmemcheck"
|
|
fi
|
|
done
|
|
exit $status
|