lhmouse/mcfgthread

Make global data shareable between static libraries

lhmouse opened this issue · 1 comments

At the moment, we have some global states as static variables:

/* Define global data last to ensure that all of them have all been

This is not a problem if mcfgthread is always linked as a shared library. But, there are people who prefer static linking. In the latter case, all static instances in an EXE and all DLLs it has loaded get distinct copies of these variables, and it is dangerous to pass thread handles, TLS key handles, etc. between them.

Therefore, I think we can place these data into a named shared memory region, so individual modules always refer to the same region.

The name of mapping of global data looks like

Local\__MCF_crt_xglobals_<PID>_<RANDOM>

where <PID> is the process ID and <RANDOM> is the 64-bit result of EncodePointer(-42) * 0x9E3779B97F4A7C15ULL 1. This value should be unique to each process, and not exploitable by others.

Footnotes

  1. 0x9E3779B97F4A7C15 is the 64-bit fixed-point value of the Golden Ratio.