KiCad PCB EDA Suite
Loading...
Searching...
No Matches
navlib_safe_init.cpp File Reference
#include <navlib_safe_init.h>
#include <wx/log.h>
#include <atomic>
#include <exception>
#include <mutex>
#include <signal.h>
#include <setjmp.h>

Go to the source code of this file.

Functions

static std::atomic< bool > s_driverCrashed (false)
 
static void navlibSigAbrtHandler (int aSignal)
 
bool SafeNavlibInit (const std::function< void()> &aInitFunc)
 Attempt to run the given function, recovering from both C++ exceptions and abort() calls triggered by buggy third-party drivers.
 
bool NavlibDriverCrashed ()
 Returns true if a previous SafeNavlibInit call detected a driver crash.
 

Variables

static std::mutex s_initMutex
 
static sigjmp_buf s_jumpBuffer
 
static struct sigaction s_savedSigAbrtAction
 

Function Documentation

◆ NavlibDriverCrashed()

bool NavlibDriverCrashed ( )

Returns true if a previous SafeNavlibInit call detected a driver crash.

Once the driver is known to be broken, all future SafeNavlibInit calls return false immediately without attempting initialization.

Definition at line 133 of file navlib_safe_init.cpp.

References s_driverCrashed().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), NL_3D_VIEWER_PLUGIN::NL_3D_VIEWER_PLUGIN(), NL_FOOTPRINT_PROPERTIES_PLUGIN::NL_FOOTPRINT_PROPERTIES_PLUGIN(), NL_GERBVIEW_PLUGIN::NL_GERBVIEW_PLUGIN(), NL_PCBNEW_PLUGIN::NL_PCBNEW_PLUGIN(), NL_PL_EDITOR_PLUGIN::NL_PL_EDITOR_PLUGIN(), and NL_SCHEMATIC_PLUGIN::NL_SCHEMATIC_PLUGIN().

◆ navlibSigAbrtHandler()

static void navlibSigAbrtHandler ( int aSignal)
static

Definition at line 44 of file navlib_safe_init.cpp.

References s_jumpBuffer.

Referenced by SafeNavlibInit().

◆ s_driverCrashed()

static std::atomic< bool > s_driverCrashed ( false )
static

◆ SafeNavlibInit()

bool SafeNavlibInit ( const std::function< void()> & aInitFunc)

Attempt to run the given function, recovering from both C++ exceptions and abort() calls triggered by buggy third-party drivers.

On macOS, temporarily installs a SIGABRT handler that uses siglongjmp to recover from abort(). On other platforms, wraps the call in a try/catch.

Parameters
aInitFuncthe initialization function to call
Returns
true if the function completed without error, false otherwise

Definition at line 52 of file navlib_safe_init.cpp.

References navlibSigAbrtHandler(), s_driverCrashed(), s_initMutex, s_jumpBuffer, and s_savedSigAbrtAction.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), NL_3D_VIEWER_PLUGIN_IMPL::Connect(), NL_PCBNEW_PLUGIN_IMPL::NL_PCBNEW_PLUGIN_IMPL(), NL_GERBVIEW_PLUGIN_IMPL::SetCanvas(), NL_PL_EDITOR_PLUGIN_IMPL::SetCanvas(), and NL_SCHEMATIC_PLUGIN_IMPL::SetCanvas().

Variable Documentation

◆ s_initMutex

std::mutex s_initMutex
static

Definition at line 40 of file navlib_safe_init.cpp.

Referenced by SafeNavlibInit().

◆ s_jumpBuffer

sigjmp_buf s_jumpBuffer
static

Definition at line 41 of file navlib_safe_init.cpp.

Referenced by navlibSigAbrtHandler(), and SafeNavlibInit().

◆ s_savedSigAbrtAction

struct sigaction s_savedSigAbrtAction
static

Definition at line 42 of file navlib_safe_init.cpp.

Referenced by SafeNavlibInit().