Skip to content

Conversation

@0x0ade
Copy link

@0x0ade 0x0ade commented Jul 19, 2016

The symbols are public on non-Windows platforms and are exported on Windows in vanilla mono: https://github.com/mono/mono/blob/master/msvc/mono.def#L200

Making the symbols public would remove the need for any address hackery and offset guessing on Windows when trying to access it:

    // REPLACE THOSE ADDRESSES WITH THOSE IN THE mono.dll SHIPPING WITH YOUR GAME!
    private static long WINDOWS_f_mono_debug_init = 0x0000000180074cd4;
    private static long WINDOWS_f_mono_debug_domain_create = 0x0000000180074ac0;
    // ...
    public static bool/*-if-it-returns-at-all*/ Force(MonoDebugFormat format = MonoDebugFormat.MONO_DEBUG_FORMAT_MONO) {
    // ...
        if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
            Debug.Log("On Windows, mono_debug_domain_create is not public. Creating delegate from pointer.");
            // The function is not in the export table on Windows... although it should
            // See https://github.com/Unity-Technologies/mono/blob/unity-staging/msvc/mono.def
            // Compare with https://github.com/mono/mono/blob/master/msvc/mono.def, where mono_debug_domain_create is exported
            IntPtr m_mono = GetModuleHandle("mono.dll");
            IntPtr p_mono_debug_init = GetProcAddress(m_mono, "mono_debug_init");
            IntPtr p_mono_debug_domain_create = new IntPtr(WINDOWS_f_mono_debug_domain_create - WINDOWS_f_mono_debug_init + (p_mono_debug_init.ToInt64()));
            mono_debug_domain_create = (d_mono_debug_domain_create) Marshal.GetDelegateForFunctionPointer(p_mono_debug_domain_create, typeof(d_mono_debug_domain_create));

        }

I understand if this pull request gets ignored. Forcing mono into debug mode from managed space is quite unstable and unsupported.

This is not used by Unity itself but rather an ugly hack to force mono into debug mode.
Said symbols are public on non-Windows platforms and are exported on Windows in vanilla mono.
@joshpeterson
Copy link

This change looks fine actually, we should be able expose these additional functions without problems.

@joshpeterson joshpeterson merged commit bdae8c6 into Unity-Technologies:unity-staging Aug 9, 2016
joshpeterson added a commit that referenced this pull request Aug 9, 2016
It looks like mono_debug_enabled does not exist, so this commit breaks
the build on Windows.

This reverts commit bdae8c6, reversing
changes made to db0f2b7.
@joshpeterson
Copy link

Actually, I've had to revert this merge at 9036ae8. It looks like mono_debug_enabled does not exist, so the Windows build breaks. Did you intend to expose something else?

@0x0ade
Copy link
Author

0x0ade commented Aug 9, 2016

It's actually the symbol next to mono_debug_domain_unload, so I must've accidentally carried it over from the vanilla mono.def. I'll update my fork accordingly.

I didn't intend to expose anything else. And actually, I didn't expect any response! Thanks for taking a look!

@0x0ade
Copy link
Author

0x0ade commented Aug 9, 2016

I've updated my fork, but GitHub doesn't show the change here as this PR is already "merged". Should I submit a new PR?

@joshpeterson
Copy link

Yes, please submit a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants