TSS GDT Gate

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.
Post Reply
0xBADC0DE

TSS GDT Gate

Post by 0xBADC0DE »

Is my code for my TSS GDT Gate good?

Code: Select all


struct KeGDTEntry gdte[6];
struct KeGDTPtr gdt;




void KeGDTSetGate(int num, unsigned long base, unsigned long limit, unsigned char access,unsigned char gran)
{
   gdte[num].base_low = (base & 0xFFFF);
   gdte[num].base_middle = (base >> 16) & 0xFF;
   gdte[num].base_high = (base >> 24) & 0xFF;
   gdte[num].limit_low = (limit & 0xFFFF);
   gdte[num].granularity = ((limit >> 16) & 0x0F);
   gdte[num].granularity |= (gran & 0xF0);
   gdte[num].access = access;
}

void KeGDTSetTSS(int num)
{
   gdte[num].base_low = 0;
   gdte[num].base_middle=0;
   gdte[num].base_high=0;
   gdte[num].limit_low = 103;
   gdte[num].access = 0x89;
   gdte[num].granularity = 0;

}

void KeGDTInstall()
{
   gdt.limit = (sizeof(struct KeGDTEntry)*6) - 1;
   gdt.base = (unsigned int)&gdte;

   /* [0x00] */   KeGDTSetGate(0,0,0,0,0);
   /* [0x08] */   KeGDTSetGate(1,0,0xFFFFFFFF,0x9A,0xCF); // Ring0 CS
   /* [0x10] */   KeGDTSetGate(2,0,0xFFFFFFFF,0x92,0xCF); // Ring0 DS
   /* [0x18] */   KeGDTSetTSS(3);
   /* [0x20] */   KeGDTSetGate(4,0,0xFFFFFFFF,0xFA,0xCF); // Ring3 CS
   /* [0x28] */   KeGDTSetGate(5,0,0xFFFFFFFF,0xF2,0xCF); // Ring3 DS

   KeSetGDT();
}
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:TSS GDT Gate

Post by Pype.Clicker »

i don't see why you call them "gates": CS and DS are loaded with _segments_, not gates.

I think you should read about TSSes again too: a TSS typically _do_ have a base address so i don't see why you load it with 0 by default.
0Scoder
Member
Member
Posts: 53
Joined: Sat Nov 11, 2006 8:02 am

Re:TSS GDT Gate

Post by 0Scoder »

yes, like pype said you need to change the naming for your functions. Also, seen as the 'gate' code you use seems to be for segments, you will also need a function for adding gate descriptors.
Post Reply