[BUG] Stack smashed during paging init
This commit is contained in:
parent
d99e22fe41
commit
a22eb6669d
|
@ -81,9 +81,15 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
|
|||
KeGetCpuInfos();
|
||||
IoEnableKeyb();
|
||||
|
||||
for (ulong curAddrPT = 0x00971db000; curAddrPT <= 0x00971fc000; curAddrPT+= (ulong)KPAGESIZE) {
|
||||
DebugLog("\t\t\t\tTable %p : %p\n", MmTransPhyToVirtAddr((void*)curAddrPT), MmTransVirtToPhyAddr((void*)curAddrPT));
|
||||
}
|
||||
|
||||
// Command line (kernel mode)
|
||||
ShStartShell();
|
||||
|
||||
//KeCrashSystem();
|
||||
// Exit !
|
||||
PoShutdown();
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <kernel.h>
|
||||
|
||||
ulong __stack_chk_guard = 0x447c0ffe4dbf9e55;
|
||||
ulong __stack_chk_guard = 0xec0ffec0ffec0ffe;
|
||||
|
||||
noreturn void __stack_chk_fail(void)
|
||||
{
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
|
||||
//-----------
|
||||
|
||||
pml4_t MmPageMapLevel4[512] __attribute__((__aligned__(KPAGESIZE)));
|
||||
ulong *MmPhysicalPageTable;
|
||||
static pml4_t MmPageMapLevel4[512] __attribute__((__aligned__(KPAGESIZE)));
|
||||
static ulong *MmPhysicalPageTable __attribute__((__aligned__(KPAGESIZE)));
|
||||
|
||||
extern ulong _text;
|
||||
extern ulong _text_end;
|
||||
|
@ -89,7 +89,7 @@ void MmInitPaging(void)
|
|||
memzero((void *)&MmPageMapLevel4[0], 512*sizeof(ulong));
|
||||
KalAllocMemoryEx((void**)&MmPhysicalPageTable, phDirSize, M_ZEROED, KPAGESIZE);
|
||||
|
||||
DebugLog("PhDirSize : %d\n", phDirSize/sizeof(ulong));
|
||||
DebugLog("\t\t\t\tPhysical map addr : %p\n", MmPhysicalPageTable);
|
||||
|
||||
for (curAddrPML4 = 0;
|
||||
curAddrPML4 < 512 * KPAGESIZE * 0x8000000;
|
||||
|
@ -128,9 +128,6 @@ void MmInitPaging(void)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (index == 0x447c0ffe4dbf9e55)
|
||||
KeStartPanic("ERROR");
|
||||
|
||||
MmPD = (pde_t *)malloc(512*sizeof(pde_t));
|
||||
|
||||
index = (curAddrPDP / ((ulong)KPAGESIZE * 0x40000)) % 512;
|
||||
|
@ -168,21 +165,18 @@ void MmInitPaging(void)
|
|||
index = (curAddrPT / ((ulong)KPAGESIZE)) % 512;
|
||||
xedni = (curAddrPT / ((ulong)KPAGESIZE));
|
||||
|
||||
if (curAddrPT == 0x973db000)
|
||||
DebugLog("ERR : %p\n", &MmPhysicalPageTable[xedni]);
|
||||
|
||||
// STACK GUARD PAGE */
|
||||
if ((ulong)curAddrPT == (ulong)BtLoaderInfo.stackEndAddr) {
|
||||
MmPT[index] = (ulong)curAddrPT | PRESENT;
|
||||
MmPhysicalPageTable[xedni] = (ulong)curAddrPT;
|
||||
MmStackGuards[0] = (ulong)curAddrPT;
|
||||
//DebugLog("\tStack Guard at %p\n", curAddrPT);
|
||||
DebugLog("\tStack Guard at %p\n", curAddrPT);
|
||||
}
|
||||
else if ((ulong)curAddrPT == (ulong)BtLoaderInfo.kernelEndAddr) {
|
||||
MmPT[index] = (ulong)curAddrPT | PRESENT;
|
||||
MmPhysicalPageTable[xedni] = (ulong)curAddrPT;
|
||||
MmStackGuards[1] = (ulong)curAddrPT;
|
||||
//DebugLog("\tStack Guard at %p\n", curAddrPT);
|
||||
DebugLog("\tStack Guard at %p\n", curAddrPT);
|
||||
}
|
||||
// SECTION .TEXT PROTECTION
|
||||
else if ((ulong)curAddrPT >= (ulong)&_text && (ulong)curAddrPT <= (ulong)&_text_end) {
|
||||
|
@ -207,12 +201,6 @@ void MmInitPaging(void)
|
|||
MmPT[index] = (ulong)curAddrPT | PRESENT | READWRITE;
|
||||
MmPhysicalPageTable[xedni] = (ulong)curAddrPT;
|
||||
}
|
||||
else {
|
||||
MmPT[index] = (ulong)0;
|
||||
MmPhysicalPageTable[xedni] = (ulong)0;
|
||||
}
|
||||
|
||||
KeFlushTlbSingle(curAddrPT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,6 +211,11 @@ void MmInitPaging(void)
|
|||
MmEnableWriteProtect();
|
||||
|
||||
DebugLog("\tPage table size : %u MB\n", (lastDirectoryAddr - firstDirectoryAddr + phDirSize)/MB);
|
||||
|
||||
for (ulong curAddrPT = 0x00971db000; curAddrPT <= 0x00971fc000; curAddrPT+= (ulong)KPAGESIZE) {
|
||||
DebugLog("\t\t\t\tTable %p : %p\n", MmTransPhyToVirtAddr((void*)curAddrPT), MmTransVirtToPhyAddr((void*)curAddrPT));
|
||||
}
|
||||
DebugLog("\n");
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -249,24 +249,28 @@ error_t MmUnmapPageFrame(ulong id)
|
|||
|
||||
error_t MmTestBusyPage(void)
|
||||
{
|
||||
ulong tab[2000] = {0};
|
||||
int j = 0;
|
||||
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
if (rand() %2) {
|
||||
if (rand() %2) {
|
||||
tab[j++] = MmAllocPageFrame(rand()%65536, NORMAL);
|
||||
} else {
|
||||
tab[j++] = MmAllocPageFrame(rand()%65536, CONTIGUOUS);
|
||||
}
|
||||
} else {
|
||||
MmFreePageFrame(tab[rand() % (j+1)]);
|
||||
}
|
||||
for (ulong curAddrPT = 0x00971cb000; curAddrPT <= 0x00971fb000; curAddrPT+= (ulong)KPAGESIZE) {
|
||||
DebugLog("\t\t\t\tTable %p : %p\n", MmTransPhyToVirtAddr((void*)curAddrPT), MmTransVirtToPhyAddr((void*)curAddrPT));
|
||||
}
|
||||
|
||||
//printBusyPages();
|
||||
/* ulong tab[2000] = {0}; */
|
||||
/* int j = 0; */
|
||||
|
||||
DebugLog("Alloc : %d; Free : %d\n", NSuccessfulAlloc, NSuccessfulFree);
|
||||
/* for (int i = 0; i < 2000; i++) { */
|
||||
/* if (rand() %2) { */
|
||||
/* if (rand() %2) { */
|
||||
/* tab[j++] = MmAllocPageFrame(rand()%65536, NORMAL); */
|
||||
/* } else { */
|
||||
/* tab[j++] = MmAllocPageFrame(rand()%65536, CONTIGUOUS); */
|
||||
/* } */
|
||||
/* } else { */
|
||||
/* MmFreePageFrame(tab[rand() % (j+1)]); */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* //printBusyPages(); */
|
||||
|
||||
/* DebugLog("Alloc : %d; Free : %d\n", NSuccessfulAlloc, NSuccessfulFree); */
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue