Skip to content
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

[Mono]Assertion at /runtime/src/mono/mono/mini/mini-runtime.c:417, condition `ptr' not met #111012

Open
CeSun opened this issue Dec 31, 2024 · 0 comments
Labels
area-VM-meta-mono untriaged New issue has not been triaged by the area owner

Comments

@CeSun
Copy link

CeSun commented Dec 31, 2024

I tried to run Mono on the HarmonyOS(HarmonyOS info: #110074 (comment)).

When calling the mono_jit_init function, a crash occurs and the error message is output:

Image

After investigation, it was found that the mono_valloc function failed when calling mmap:

Image

The value of the prot parameter here is PROT_READ | PROT_WRITE | PROT_EXEC.
HarmonyOS may not support the PROT_EXEC flag

I guessed that PROT_EXEC has something to do with jit, so I set Mono's AOT mode to MONO_AOT_MODE_INTERP_ONLY, but still crashes.

void Mono_Init()
{
    if (g_MonoDomain != nullptr)
        return;
    mono_jit_set_aot_mode(MONO_AOT_MODE_INTERP_ONLY);
    mono_trace_set_log_handler(Mono_Log, nullptr);
#ifdef __aarch64__
    mono_set_dirs("/data/storage/el1/bundle/entry/resources/resfile/BCL/arm64-v8a", "");
#elif __x86_64__
    mono_set_dirs("/data/storage/el1/bundle/entry/resources/resfile/BCL/x86_64", "");
#else 
    assert(0);
#endif
    g_MonoDomain = mono_jit_init("OpenHarmonyMonoDomain");
    assert(g_MonoDomain != nullptr);
    
    MonoAssembly* assembly = mono_domain_assembly_open(g_MonoDomain, "/data/storage/el1/bundle/entry/resources/resfile/UserLibrary/ClassLibrary1.dll");
    assert(assembly != nullptr);
    
    MonoImage* image = mono_assembly_get_image(assembly);
    assert(image != nullptr);
    
    MonoClass* main_class = mono_class_from_name(image, "ClassLibrary1", "Class1");
    assert(main_class != nullptr);

    MonoMethod* mono_method = mono_class_get_method_from_name(main_class, "Add", 2);
    assert(mono_method != nullptr);
    int a = 2;
    int b = 3;
    void *args[2] = {&a, &b};
    
    auto rtl = mono_runtime_invoke(mono_method, nullptr, args, nullptr);
    
    int res = *(int*)mono_object_unbox (rtl);
}

I would like to ask if there is a way to avoid the PROT_EXEC flag

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 31, 2024
@CeSun CeSun changed the title [Mono]Assertion at /runtime/src/mono/mono/mini/mini-runtime.c:417, condition `ptr' not met\n" [Mono]Assertion at /runtime/src/mono/mono/mini/mini-runtime.c:417, condition `ptr' not met Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-VM-meta-mono untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

1 participant