Skip to content

Commit

Permalink
add set_signal_chaining flag
Browse files Browse the repository at this point in the history
  • Loading branch information
koubaa authored and filmor committed Jan 3, 2023
1 parent 6e40f71 commit bf3b426
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions clr_loader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def get_mono(
jit_options: Optional[Sequence[str]] = None,
assembly_dir: Optional[str] = None,
config_dir: Optional[str] = None,
set_signal_chaining: bool = False
) -> Runtime:
"""Get a Mono runtime instance
Expand All @@ -54,6 +55,16 @@ def get_mono(
The base directory for assemblies, passed to ``mono_set_dirs``
:param config_dir:
The base directory for configuration files, passed to ``mono_set_dirs``
:param set_signal_chaining:
Whether to enable signal chaining, passed to ``mono_set_signal_chaining``.
If it is enabled, the runtime saves the original signal handlers before
installing its own, and calls the original ones in the following cases:
- SIGSEGV/SIGABRT while executing native code
- SIGPROF
- SIGFPE
- SIGQUIT
- SIGUSR2
This currently only works on POSIX platforms
"""
from .mono import Mono

Expand All @@ -70,6 +81,7 @@ def get_mono(
libmono=libmono,
assembly_dir=assembly_dir,
config_dir=config_dir,
set_signal_chaining=set_signal_chaining,
)
return impl

Expand Down
3 changes: 3 additions & 0 deletions clr_loader/ffi/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
void* mono_object_unbox(MonoObject *object);
void mono_set_dirs(const char *assembly_dir, const char* config_dir);
void mono_set_signal_chaining(bool chain_signals);
"""
)
8 changes: 7 additions & 1 deletion clr_loader/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(
global_config_file: Optional[Path] = None,
assembly_dir: Optional[str] = None,
config_dir: Optional[str] = None,
set_signal_chaining: bool = False,
):
self._assemblies: Dict[Path, Any] = {}

Expand All @@ -37,6 +38,7 @@ def __init__(
libmono=libmono,
assembly_dir=assembly_dir,
config_dir=config_dir,
set_signal_chaining=set_signal_chaining,
)

if domain is None:
Expand Down Expand Up @@ -126,7 +128,8 @@ def initialize(
config_file: Optional[str] = None,
global_config_file: Optional[str] = None,
assembly_dir: Optional[str] = None,
config_dir: Optional[str] = None
config_dir: Optional[str] = None,
set_signal_chaining: bool = False,
) -> str:
global _MONO, _ROOT_DOMAIN
if _MONO is None:
Expand All @@ -152,6 +155,9 @@ def initialize(
else:
options = []

if set_signal_chaining:
_MONO.mono_set_signal_chaining(True)

if debug:
_MONO.mono_debug_init(_MONO.MONO_DEBUG_FORMAT_MONO)

Expand Down

0 comments on commit bf3b426

Please sign in to comment.