Write protection for rodata and text functionnal

This commit is contained in:
Adrien Bourmault 2020-01-05 22:12:50 +01:00
parent 5829d7a353
commit 4cbd42a19f
4 changed files with 50 additions and 28 deletions

View File

@ -38,6 +38,12 @@ void IoDoBeepNoIdt(void);
void IoDoStarWars(void);
struct Note
{
uint tone;
uint time;
};
//----------------------------------------------------------------------------//
#endif

View File

@ -28,6 +28,18 @@
extern bool KeIdtIsInitialized;
const struct Note score[40] = { {440, 200}, {110, 200}, {440, 200}, {110, 200},
{440, 200}, {110, 200}, {349, 140}, {87, 100},
{523, 60}, {87, 100}, {440, 200}, {110, 200},
{349, 140}, {87, 100}, {523, 60}, {87, 100},
{440, 200}, {110, 200}, {440, 200}, {110, 200},
{659, 200}, {110, 200}, {659, 200}, {110, 200},
{659, 200}, {87, 200}, {698, 140}, {87, 100},
{523, 60}, {87, 100}, {415, 200}, {87, 200},
{349, 140}, {87, 100}, {523, 60}, {87, 100},
{440, 200}, {110, 200}, {110, 200}, {110, 200}
};
void IoStartSpeaker(int freq)
{
uchar temp;
@ -81,28 +93,10 @@ void IoDoBeepNoIdt(void)
void IoDoStarWars(void)
{
struct Note {
uint tone;
uint time;
};
const struct Note score[40] = { {440, 200}, {110, 200}, {440, 200}, {110, 200},
{440, 200}, {110, 200}, {349, 140}, {87, 100},
{523, 60}, {87, 100}, {440, 200}, {110, 200},
{349, 140}, {87, 100}, {523, 60}, {87, 100},
{440, 200}, {110, 200}, {440, 200}, {110, 200},
{659, 200}, {110, 200}, {659, 200}, {110, 200},
{659, 200}, {87, 200}, {698, 140}, {87, 100},
{523, 60}, {87, 100}, {415, 200}, {87, 200},
{349, 140}, {87, 100}, {523, 60}, {87, 100},
{440, 200}, {110, 200}, {110, 200}, {110, 200}
};
bprintf(BStdOut, "Address of the score : %p\n", &score[37]);
for (uint i = 0; i < 40; i++) {
//IoDoTone(score[i].tone, score[i].time);
bprintf(BStdOut, "%d ", score[i].time);
bprintf(BStdOut, "At %p : %u\n", &(score[i].tone), score[i].tone);
bprintf(BStdOut, "At %p : %u\n", &(score[i].time), score[i].time);
BStdOut->flusher(BStdOut);
}
IoQuietSpeaker();

View File

@ -83,17 +83,17 @@ void MmInitPaging(void)
// RODATA
if ((ulong)(i*KPAGESIZE) >= (ulong)&_rodata && (ulong)(i*KPAGESIZE) <= (ulong)&_rodata_end) {
MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT;
MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT | MF_WRITETHR;
continue;
}
// DATA
if ((ulong)(i*KPAGESIZE) >= (ulong)&_data && (ulong)(i*KPAGESIZE) <= (ulong)&_data_end) {
MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT | MF_READWRITE;
MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT | MF_WRITETHR | MF_READWRITE;
continue;
}
MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT | MF_READWRITE;
MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT | MF_WRITETHR | MF_READWRITE;
}
for (volatile ulong i = 0; i < NB_4K; i++) {
@ -117,10 +117,9 @@ void MmInitPaging(void)
MmPML4[0] = (ulong)(&MmPDP[0])| MF_PRESENT | MF_READWRITE;
MmLoadPML4((void *)MmPML4);
/* DebugLog("Read only : %p\n", (ulong)&_text); */
/* DebugLog("Read only : %p\n", (ulong)&_text_end); */
/* DebugLog("Read only : %p\n", (ulong)&_rodata); */
/* DebugLog("Read only : %p\n", (ulong)&_rodata_end); */
MmEnableWriteProtect();
DebugLog("\tPage RO from %p to %p\n", (ulong)&_text, (ulong)&_text_end);
DebugLog("\tPage RO from %p to %p\n", (ulong)&_rodata, (ulong)&_rodata_end);
//DebugLog("\tPaging tables initialized at %p, %p\n", &MmPD, &MmPT);
//DebugLog("\tStack Guards at %p, %p\n", MmStackGuards[0], MmStackGuards[1]);
}

View File

@ -155,11 +155,13 @@ error_t CmdHelpTest(int argc, char **argv, char *cmdline)
error_t CmdPF(int argc, char **argv, char *cmdline)
{
char *address = (void*)(ulong)atoi(argv[1]);
ulong *address = (ulong*)(ulong)atoi(argv[1]);
KernLog("Provoking Page Fault at %#x\n", address);
KernLog("It contained %#x\n", *address);
*address = 1;
KernLog("Now it contains %#x\n", *address);
KernLog("No page fault : address was valid/present\n");
@ -203,6 +205,26 @@ error_t CmdTimerTest(int argc, char **argv, char *cmdline)
return EOK;
}
error_t CmdprintfTest(int argc, char **argv, char *cmdline)
{
/* bprintf(BStdOut, "INT_MIN : %u\n", INT_MIN); */
/* BStdOut->flusher(BStdOut); */
bprintf(BStdOut, "INT_MAX : %u\n", INT_MAX);
BStdOut->flusher(BStdOut);
int n = - 5;
for (int i=INT_MAX - 5; n < 10; i++) {
bprintf(BStdOut, "INT_MAX + %d : %d\n", n, i);
BStdOut->flusher(BStdOut);
n++;
}
KernLog("Finished !\n");
return EOK;
}
static Command_t testcmdtable[] =
{
{ "args", CmdArgs, "Print command line" },
@ -215,5 +237,6 @@ static Command_t testcmdtable[] =
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
{ "timer", CmdTimerTest, "test timer of x ms" },
{ "printf", CmdprintfTest, "test timer of x ms" },
{ NULL, NULL, NULL }
};