Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Well, my MM is working, except for one aspect - When I create a Ring-3 MM Context, it overwrites my current Ring-0 MM Context, causing Page-Faults. I believe the error is somewhere in the code below, but I can't find it
index will be equal to 512 after the last iteration of the loop. It must be since this is the condition that would stop the loop, (this is why the condition works in the first place, "the loop will execute while index is less than 512").
The reason why this works is because index is declared outside of the for loop scope (in c++ and c99 for(int i;;){} i does not exist outside of the for loops block).
KeMMContext* KeMemManagerCreateContext(unsigned long dpl)
{
unsigned long index = 0;
while ((index < 512) && (contextes[index].flags != 0))
index++;
if (index == 512)
return 0;
unsigned long* pagedirectory = KePhysMemManagerAllocPage();
for (index = 0; index < 1024; index++)
*(KePhysMemManagerGetPage(pagedirectory) + index) = 0;
KePagingInitPageDirectory(pagedirectory);
contextes[index].cr3 = (unsigned long)pagedirectory;
contextes[index].dpl = dpl;
contextes[index].flags = 1;
return (contextes + index);
}
This doesn't fix any bugs (especially pay attention to your use of index in the last four lines), but I just don't like commands that break program flow (such as the cunningly named break) and inconsistent styles.
Also, you are creating pagedirectory as a pointer to an unsigned long and then casting it as an unsigned long, I hope getting the address of the value is the intended goal...
Kemp wrote:
That's why we told him to think about how it was used ;D
I figured as much, but at times you can throw people a bone. You can just tell them what's wrong and let them figure out how to solve it. If I don't understand why it isn't working, a vague hint about something that isn't directly related to the code I should change isn't going to help much.