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

Removing g_hmodCoreCLR and g_hThisInst #43735

Merged
21 commits merged into from
Nov 10, 2020
Merged

Removing g_hmodCoreCLR and g_hThisInst #43735

21 commits merged into from
Nov 10, 2020

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Oct 22, 2020

Introduced two new internal APIs:

  • GetClrModulePathName
  • GetClrModuleBase

Unlike g_hmodCoreCLR and g_hThisInst, these methods make sense and can be implemented regardless of the platform.
They also do not need to rely on DllMain or other kind of initialization.

All uses of g_hmodCoreCLR and g_hThisInst in coreclr were reduced to the above APIs and the variables have been removed.

@jkoritzinsky
Copy link
Member

If this works (and they’re only needed on Windows) then you should be able to use the __ImageBase symbol to replace g_hThisInst and replace the main usage of g_hmodCoreCLR (I think diagnostics uses it in a slightly different way).

@Wraith2
Copy link
Contributor

Wraith2 commented Oct 25, 2020

It might be worth a code comment explaining that 42 has no meaning other than to be non-zero to save a future reader some confusion.

@VSadov
Copy link
Member Author

VSadov commented Oct 26, 2020

@Wraith2 - it will definitely be a named constant, not a literal. This was just a quick check to confirm that any nonzero value works.

@VSadov VSadov changed the title Experimenting with removing g_hmodCoreCLR and g_hThisInst on Unix. Removing g_hmodCoreCLR and g_hThisInst on Unix. Oct 28, 2020
@VSadov VSadov changed the title Removing g_hmodCoreCLR and g_hThisInst on Unix. Removing g_hmodCoreCLR and g_hThisInst Nov 7, 2020
@VSadov VSadov marked this pull request as ready for review November 7, 2020 20:09
@@ -7473,7 +7473,7 @@ VEH_ACTION WINAPI CLRVectoredExceptionHandlerPhase3(PEXCEPTION_POINTERS pExcepti
if ((!fAVisOk) && !(pExceptionRecord->ExceptionFlags & EXCEPTION_UNWINDING))
{
PCODE ip = (PCODE)GetIP(pContext);
if (IsIPInModule(g_hThisInst, ip) || IsIPInModule(GCHeapUtilities::GetGCModule(), ip))
if (IsIPInModule(GetClrModuleBase(), ip) || IsIPInModule(GCHeapUtilities::GetGCModule(), ip))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetGCModule does not return module base on Unix.

Since this IsIPInModule check is Windows-only (at least today) anyway, should we make Windows-only, and ifdef the callsites for Windows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetGCModule returns the module base for normal GC. (it is set in InitializeDefaultGC()).

Standalone variant returns hMod. Is standalone GC supported on Unix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be possible to pass module base for the standalone GC module.
Just wonder if standalone GC on Unix is a real scenario. Maybe should just pass NULL on Unix/standalone case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing that prevents standalone GC from working on Unix.

The non-scenario on Unix is the special handling of crashes in selected modules that this code is for. As far as I know, it works just fine without any special handling. There is no SEH nor exception interop on Unix.

Copy link
Member Author

@VSadov VSadov Nov 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made standalone GC to pass the module base as well. I think that minimizes platform differences.

If one day we want to special case crashes in CLR/GC for reasons that include Unix as well, it will have a good chance to work on all platforms.

@VSadov
Copy link
Member Author

VSadov commented Nov 9, 2020

I think I have addressed all the concerns. Please take a look and let me know if something is not adequately resolved.

#endif
InitializeCriticalSection(&g_dacCritSec);

#else
// Save the module handle.
g_thisModule = (HINSTANCE)instance;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can g_thisModule be deleted now? (Or if it needs to stay - ifdef it out for non-Windows at the top of the file?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course. This assignment is the only use.
I thought I removed them all. This one does not have "h" in the name could be missed when I searched for what remains.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for cleaning this up!

return S_OK;
#else
// hModule is not avaialable under TARGET_UNIX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit:

Suggested change
// hModule is not avaialable under TARGET_UNIX
// hModule is not available under TARGET_UNIX

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was one more typo like this. Will fix both.

@VSadov
Copy link
Member Author

VSadov commented Nov 9, 2020

Thanks!!!

@ghost
Copy link

ghost commented Nov 9, 2020

Hello @VSadov!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 1c1757c into dotnet:master Nov 10, 2020
@VSadov VSadov deleted the hMod branch November 10, 2020 00:20
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
@mikem8361
Copy link
Member

@VSadov and @jkotas, it looks like #103872 was caused by this change. Any ideas on the best solution to fix this here?

@jkotas
Copy link
Member

jkotas commented Aug 9, 2024

I think that the simplest fix is to revert the part of this change that introduced the problem. Something like main...jkotas:runtime:thrown-by-us . I have not tested it.

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants