Skip to content

Instantly share code, notes, and snippets.

@JustasMasiulis
Created April 17, 2019 11:14
Show Gist options
  • Save JustasMasiulis/30475cb2fac76bb1c69df3fd414647f1 to your computer and use it in GitHub Desktop.
Save JustasMasiulis/30475cb2fac76bb1c69df3fd414647f1 to your computer and use it in GitHub Desktop.
struct MI_PAGE_COLOR_BASE { // I thought this one up. No idea if anything like it exists in symbols
PULONG Color;
WORD ColorMask;
WORD NodeShiftedColor;
};
void __fastcall MiInitializePageColorBase(_MMSUPPORT_INSTANCE *instance, int node, MI_PAGE_COLOR_BASE *colorBase) {
_KPRCB* prcb;
if(node) {
prcb = KeGetCurrentPrcb();
colorBase->NodeShiftedColor = ((_WORD)node - 1) << colorShift;
}
else
{
prcb = KiProcessorBlock[KeGetCurrentThread()->IdealProcessor];
colorBase->NodeShiftedColor = prcb->NodeShiftedColor;
}
colorBase->ColorMask = secondLevelCacheColorMask; // essentially (SecondLevelCacheSize / SecondLevelCacheAffinity) - 1
// could be _WORKING_SET_TYPE or _MI_WORKING_SET_TYPE. Both are different. Your call what the 2 is.
if(instance && (instance->Flags.WorkingSetType < 2))
colorBase->Color = &instance->NextPageColor;
else
colorBase->Color = &prcb->PageColor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment