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.9 KiB
Bash
Executable File
43 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
test_dir=$(mktemp -d)
|
|
trap 'rm -rf "$test_dir"' EXIT
|
|
flags=(-w -std=gnu11 -g -O1 -DDEBUG=1 -fsanitize=address,undefined
|
|
-fno-sanitize-recover=all -ffunction-sections -fdata-sections
|
|
-Ilinuxu/headers -Ilinuxu/tests)
|
|
heap=(-Dmalloc=dext_test_malloc -Dcalloc=dext_test_calloc
|
|
-Drealloc=dext_test_realloc -Daligned_alloc=dext_test_aligned_alloc
|
|
-Dfree=dext_test_free -Dstrdup=dext_test_strdup -Dstrndup=dext_test_strndup)
|
|
for mode in native driverkit; do
|
|
aliases=()
|
|
extra=()
|
|
definitions=()
|
|
if [[ "$mode" == driverkit ]]; then
|
|
aliases=("${heap[@]}")
|
|
definitions=(-DTEST_DRIVERKIT_HEAP)
|
|
clang "${flags[@]}" "${heap[@]}" -DLINUXU_DEXT_DK \
|
|
-c linuxu/src/shims/dext_alloc.c -o "$test_dir/heap.o"
|
|
clang "${flags[@]}" -c linuxu/tests/dext_heap_backend.c -o "$test_dir/backend.o"
|
|
extra=("$test_dir/heap.o" "$test_dir/backend.o")
|
|
fi
|
|
clang "${flags[@]}" "${aliases[@]}" -Dkmemcheck_untrack=zero_test_untrack \
|
|
-c linuxu/src/kmem/kmemalloc.c -o "$test_dir/kmemalloc.o"
|
|
clang "${flags[@]}" "${aliases[@]}" \
|
|
-c linuxu/src/kmem/kmemcheck.c -o "$test_dir/kmemcheck.o"
|
|
clang "${flags[@]}" "${aliases[@]}" \
|
|
-c linuxu/src/kmem/slab.c -o "$test_dir/slab.o"
|
|
# memdup_user and the copy helpers go through the uaccess backend.
|
|
uaccess=()
|
|
for src in linuxu/src/mm/uaccess.c linuxu/src/mm/mm.c linuxu/src/shims/task.c \
|
|
linuxu/src/rwsem.c linuxu/src/delay.c; do
|
|
clang "${flags[@]}" "${aliases[@]}" \
|
|
-c "$src" -o "$test_dir/uaccess-$(basename "$src" .c).o"
|
|
uaccess+=("$test_dir/uaccess-$(basename "$src" .c).o")
|
|
done
|
|
clang "${flags[@]}" "${definitions[@]}" linuxu/tests/test_zero_allocations.c \
|
|
"$test_dir/kmemalloc.o" "$test_dir/kmemcheck.o" "$test_dir/slab.o" \
|
|
"${uaccess[@]}" "${extra[@]}" -Wl,-dead_strip -lpthread -o "$test_dir/$mode"
|
|
"$test_dir/$mode"
|
|
done
|