From 35723ae8eec286d357e6def1c2adec3638b4af2d Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sat, 13 Sep 2014 18:22:45 -0700 Subject: [Solver] Ensure shared memory allocation failures are reported as errors, not asserts. --- lib/Solver/Solver.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/Solver/Solver.cpp b/lib/Solver/Solver.cpp index 229fa234..d4e572cf 100644 --- a/lib/Solver/Solver.cpp +++ b/lib/Solver/Solver.cpp @@ -38,6 +38,7 @@ #include #include "llvm/Support/CommandLine.h" +#include "llvm/Support/ErrorHandling.h" llvm::cl::opt IgnoreSolverFailures("ignore-solver-failures", @@ -518,7 +519,7 @@ public: static unsigned char *shared_memory_ptr; static const unsigned shared_memory_size = 1<<20; -static int shared_memory_id; +static int shared_memory_id = 0; static void stp_error_handler(const char* err_msg) { fprintf(stderr, "error: STP Error: %s\n", err_msg); @@ -546,15 +547,23 @@ STPSolverImpl::STPSolverImpl(bool _useForkedSTP, bool _optimizeDivides) vc_registerErrorHandler(::stp_error_handler); if (useForkedSTP) { + assert(shared_memory_id == 0 && "shared memory id already allocated"); shared_memory_id = shmget(IPC_PRIVATE, shared_memory_size, IPC_CREAT | 0700); - assert(shared_memory_id>=0 && "shmget failed"); + if (shared_memory_id < 0) + llvm::report_fatal_error("unable to allocate shared memory region"); shared_memory_ptr = (unsigned char*) shmat(shared_memory_id, NULL, 0); - assert(shared_memory_ptr!=(void*)-1 && "shmat failed"); + if (shared_memory_ptr == (void*)-1) + llvm::report_fatal_error("unable to attach shared memory region"); shmctl(shared_memory_id, IPC_RMID, NULL); } } STPSolverImpl::~STPSolverImpl() { + // Detach the memory region. + shmdt(shared_memory_ptr); + shared_memory_ptr = 0; + shared_memory_id = 0; + delete builder; vc_Destroy(vc); @@ -678,7 +687,8 @@ static SolverImpl::SolverRunStatus runAndGetCexForked(::VC vc, for (std::vector::const_iterator it = objects.begin(), ie = objects.end(); it != ie; ++it) sum += (*it)->size; - assert(sum= shared_memory_size) + llvm::report_fatal_error("not enough shared memory for counterexample"); fflush(stdout); fflush(stderr); -- cgit 1.4.1