Skip to content

Commit 717e797

Browse files
authored
Add support for mono_set_dirs (#43)
* add support for mono_set_dirs * add set_signal_chaining flag * add tests
1 parent c6b4649 commit 717e797

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

clr_loader/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def get_mono(
3030
sgen: bool = True,
3131
debug: bool = False,
3232
jit_options: Optional[Sequence[str]] = None,
33+
assembly_dir: Optional[str] = None,
34+
config_dir: Optional[str] = None,
35+
set_signal_chaining: bool = False
3336
) -> Runtime:
3437
"""Get a Mono runtime instance
3538
@@ -48,6 +51,20 @@ def get_mono(
4851
Whether to initialise Mono debugging
4952
:param jit_options:
5053
"Command line options" passed to Mono's ``mono_jit_parse_options``
54+
:param assembly_dir:
55+
The base directory for assemblies, passed to ``mono_set_dirs``
56+
:param config_dir:
57+
The base directory for configuration files, passed to ``mono_set_dirs``
58+
:param set_signal_chaining:
59+
Whether to enable signal chaining, passed to ``mono_set_signal_chaining``.
60+
If it is enabled, the runtime saves the original signal handlers before
61+
installing its own, and calls the original ones in the following cases:
62+
- SIGSEGV/SIGABRT while executing native code
63+
- SIGPROF
64+
- SIGFPE
65+
- SIGQUIT
66+
- SIGUSR2
67+
This currently only works on POSIX platforms
5168
"""
5269
from .mono import Mono
5370

@@ -62,6 +79,9 @@ def get_mono(
6279
config_file=_maybe_path(config_file),
6380
global_config_file=_maybe_path(global_config_file),
6481
libmono=libmono,
82+
assembly_dir=assembly_dir,
83+
config_dir=config_dir,
84+
set_signal_chaining=set_signal_chaining,
6585
)
6686
return impl
6787

clr_loader/ffi/mono.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@
3939
MonoObject* mono_runtime_invoke(MonoMethod *method, void *obj, void **params, MonoObject **exc);
4040
4141
void* mono_object_unbox(MonoObject *object);
42+
43+
void mono_set_dirs(const char *assembly_dir, const char* config_dir);
44+
45+
void mono_set_signal_chaining(bool chain_signals);
46+
4247
"""
4348
)

clr_loader/mono.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def __init__(
2424
jit_options: Optional[Sequence[str]] = None,
2525
config_file: Optional[Path] = None,
2626
global_config_file: Optional[Path] = None,
27+
assembly_dir: Optional[str] = None,
28+
config_dir: Optional[str] = None,
29+
set_signal_chaining: bool = False,
2730
):
2831
self._assemblies: Dict[Path, Any] = {}
2932

@@ -33,6 +36,9 @@ def __init__(
3336
jit_options=jit_options,
3437
global_config_file=optional_path_as_string(global_config_file),
3538
libmono=libmono,
39+
assembly_dir=assembly_dir,
40+
config_dir=config_dir,
41+
set_signal_chaining=set_signal_chaining,
3642
)
3743

3844
if domain is None:
@@ -121,11 +127,17 @@ def initialize(
121127
jit_options: Optional[Sequence[str]] = None,
122128
config_file: Optional[str] = None,
123129
global_config_file: Optional[str] = None,
130+
assembly_dir: Optional[str] = None,
131+
config_dir: Optional[str] = None,
132+
set_signal_chaining: bool = False,
124133
) -> str:
125134
global _MONO, _ROOT_DOMAIN
126135
if _MONO is None:
127136
_MONO = load_mono(libmono)
128137

138+
if assembly_dir is not None and config_dir is not None:
139+
_MONO.mono_set_dirs(assembly_dir, config_dir)
140+
129141
# Load in global config (i.e /etc/mono/config)
130142
global_encoded = global_config_file or ffi.NULL
131143
_MONO.mono_config_parse(global_encoded)
@@ -143,6 +155,9 @@ def initialize(
143155
else:
144156
options = []
145157

158+
if set_signal_chaining:
159+
_MONO.mono_set_signal_chaining(True)
160+
146161
if debug:
147162
_MONO.mono_debug_init(_MONO.MONO_DEBUG_FORMAT_MONO)
148163

tests/test_common.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ def test_mono_debug(example_netstandard):
4646

4747
run_tests(asm)
4848

49+
def test_mono_signal_chaining(example_netstandard):
50+
from clr_loader import get_mono
51+
52+
mono = get_mono(set_signal_chaining=True)
53+
asm = mono.get_assembly(example_netstandard / "example.dll")
54+
55+
run_tests(asm)
56+
57+
def test_mono_set_dir(example_netstandard):
58+
from clr_loader import get_mono
59+
60+
mono = get_mono(assembly_dir="/usr/lib", config_dir="/etc")
61+
asm = mono.get_assembly(example_netstandard / "example.dll")
62+
63+
run_tests(asm)
4964

5065
def test_coreclr(example_netcore):
5166
from clr_loader import get_coreclr

0 commit comments

Comments
 (0)