From 70e68e0ec604124bb248ea4d064307bbf96e7932 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 30 Jul 2013 23:25:37 +0200 Subject: Detect stack overflows Previously, if the Nix evaluator gets a stack overflow due to a deep or infinite recursion in the Nix expression, the user gets an unhelpful message ("Segmentation fault") that doesn't indicate that the problem is in the user's code rather than Nix itself. Now it prints: error: stack overflow (possible infinite recursion) This only works on x86_64-linux and i686-linux. Fixes #35. --- src/libmain/shared.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/libmain/shared.cc') diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 4796629dc..ee0dccc9d 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -13,6 +13,7 @@ #include #include #include +#include #if HAVE_BOEHMGC #include @@ -100,6 +101,9 @@ string getArg(const string & opt, } +void detectStackOverflow(); + + /* Initialize and reorder arguments, then call the actual argument processor. */ static void initAndRun(int argc, char * * argv) @@ -131,6 +135,9 @@ static void initAndRun(int argc, char * * argv) if (sigaction(SIGCHLD, &act, 0)) throw SysError("resetting SIGCHLD"); + /* Register a SIGSEGV handler to detect stack overflows. */ + detectStackOverflow(); + /* There is no privacy in the Nix system ;-) At least not for now. In particular, store objects should be readable by everybody. */ -- cgit v1.2.3