Add support for mono_set_dirs (#43)

* add support for mono_set_dirs
* add set_signal_chaining flag
* add tests
This commit is contained in:
Mohamed Koubaa 2023-01-03 06:08:04 -06:00 коммит произвёл GitHub
Родитель c6b464942f
Коммит 717e797616
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 55 добавлений и 0 удалений

Просмотреть файл

@ -30,6 +30,9 @@ def get_mono(
sgen: bool = True,
debug: bool = False,
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
@ -48,6 +51,20 @@ def get_mono(
Whether to initialise Mono debugging
:param jit_options:
"Command line options" passed to Mono's ``mono_jit_parse_options``
:param assembly_dir:
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
@ -62,6 +79,9 @@ def get_mono(
config_file=_maybe_path(config_file),
global_config_file=_maybe_path(global_config_file),
libmono=libmono,
assembly_dir=assembly_dir,
config_dir=config_dir,
set_signal_chaining=set_signal_chaining,
)
return impl

Просмотреть файл

@ -39,5 +39,10 @@ void mono_method_desc_free(MonoMethodDesc *method_desc);
MonoObject* mono_runtime_invoke(MonoMethod *method, void *obj, void **params, MonoObject **exc);
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);
"""
)

Просмотреть файл

@ -24,6 +24,9 @@ class Mono(Runtime):
jit_options: Optional[Sequence[str]] = None,
config_file: Optional[Path] = None,
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] = {}
@ -33,6 +36,9 @@ class Mono(Runtime):
jit_options=jit_options,
global_config_file=optional_path_as_string(global_config_file),
libmono=libmono,
assembly_dir=assembly_dir,
config_dir=config_dir,
set_signal_chaining=set_signal_chaining,
)
if domain is None:
@ -121,11 +127,17 @@ def initialize(
jit_options: Optional[Sequence[str]] = None,
config_file: Optional[str] = None,
global_config_file: Optional[str] = None,
assembly_dir: Optional[str] = None,
config_dir: Optional[str] = None,
set_signal_chaining: bool = False,
) -> str:
global _MONO, _ROOT_DOMAIN
if _MONO is None:
_MONO = load_mono(libmono)
if assembly_dir is not None and config_dir is not None:
_MONO.mono_set_dirs(assembly_dir, config_dir)
# Load in global config (i.e /etc/mono/config)
global_encoded = global_config_file or ffi.NULL
_MONO.mono_config_parse(global_encoded)
@ -143,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)

Просмотреть файл

@ -46,6 +46,21 @@ def test_mono_debug(example_netstandard):
run_tests(asm)
def test_mono_signal_chaining(example_netstandard):
from clr_loader import get_mono
mono = get_mono(set_signal_chaining=True)
asm = mono.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def test_mono_set_dir(example_netstandard):
from clr_loader import get_mono
mono = get_mono(assembly_dir="/usr/lib", config_dir="/etc")
asm = mono.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def test_coreclr(example_netcore):
from clr_loader import get_coreclr