Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for mono_set_dirs #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions clr_loader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions clr_loader/ffi/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@
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);

"""
)
15 changes: 15 additions & 0 deletions clr_loader/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def __init__(
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] = {}

Expand All @@ -33,6 +36,9 @@ def __init__(
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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
15 changes: 15 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down