1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 00:11:17 +02:00

Fix memory corruption caused by GC-invisible coroutine stacks

Crucially this introduces BoehmGCStackAllocator, but it also
adds a bunch of wiring to avoid making libutil depend on bdw-gc.

Part of the solutions for #4178, #4200
This commit is contained in:
Robert Hensing 2020-10-30 20:55:53 +01:00
parent dc5696b84f
commit c4d903ddb0
4 changed files with 75 additions and 2 deletions

View file

@ -5,6 +5,7 @@
#include "types.hh"
#include "util.hh"
namespace boost::context { struct stack_context; }
namespace nix {
@ -497,5 +498,18 @@ struct FramedSink : nix::BufferedSink
};
};
/* Stack allocation strategy for sinkToSource.
Mutable to avoid a boehm gc dependency in libutil.
boost::context doesn't provide a virtual class, so we define our own.
*/
struct StackAllocator {
virtual boost::context::stack_context allocate() = 0;
virtual void deallocate(boost::context::stack_context sctx) = 0;
/* The stack allocator to use in sinkToSource and potentially elsewhere.
It is reassigned by the initGC() method in libexpr. */
static StackAllocator *defaultAllocator;
};
}