···
+
{ lib, stdenv, fetchurl, python3, runCommand, makeWrapper, stress-ng }:
+
lib.fix (self: stdenv.mkDerivation rec {
pname = "graphene-hardened-malloc";
url = "https://github.com/GrapheneOS/hardened_malloc/archive/${version}.tar.gz";
+
sha256 = "0lipyd2pb1bmghkyv9zmg25jwcglj7m281f01zlh3ghz3xlfh0ym";
+
checkInputs = [ python3 ];
+
# these tests cover use as a build-time-linked library
+
install -Dm444 -t $out/include include/*
install -Dm444 -t $out/lib libhardened_malloc.so
···
separateDebugInfo = true;
+
ld-preload-tests = stdenv.mkDerivation {
+
name = "${self.name}-ld-preload-tests";
+
nativeBuildInputs = [ makeWrapper ];
+
# reuse the projects tests to cover use with LD_PRELOAD. we have
+
# to convince the test programs to build as though they're naive
+
# standalone executables. this includes disabling tests for
+
# malloc_object_size, which doesn't make sense to use via LD_PRELOAD.
+
pushd test/simple-memory-corruption
+
make LDLIBS= LDFLAGS=-Wl,--unresolved-symbols=ignore-all CXXFLAGS=-lstdc++
+
substituteInPlace test_smc.py \
+
--replace 'test_malloc_object_size' 'dont_test_malloc_object_size' \
+
--replace 'test_invalid_malloc_object_size' 'dont_test_invalid_malloc_object_size'
+
popd # test/simple-memory-corruption
+
cp -r test/simple-memory-corruption $out/test/simple-memory-corruption
+
makeWrapper ${python3.interpreter} $out/bin/run-tests \
+
--add-flags "-I -m unittest discover --start-directory $out/test/simple-memory-corruption"
+
ld-preload = runCommand "ld-preload-test-run" {} ''
+
${self}/bin/preload-hardened-malloc ${self.ld-preload-tests}/bin/run-tests
+
# to compensate for the lack of tests of correct normal malloc operation
+
stress = runCommand "stress-test-run" {} ''
+
${self}/bin/preload-hardened-malloc ${stress-ng}/bin/stress-ng \
homepage = "https://github.com/GrapheneOS/hardened_malloc";
···
maintainers = with maintainers; [ ris ];
platforms = [ "x86_64-linux" "aarch64-linux" ];