GDT: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
Content added Content deleted
 (new page)  | 
			
(No difference) 
 | 
Latest revision as of 22:32, 14 December 2019
You can get the (kernel mapped) address of the GDT using the sgdt instruction from userspace:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
struct desc_ptr {
        unsigned short size;
        unsigned long address;
} __attribute__((packed)) ;
static inline void sgdt(struct desc_ptr *dtr)
{
        asm volatile("sgdt %0" : "=m" (*dtr));
}
int main(int argc, char *argv[])
{
        while (1) {
                struct desc_ptr gdt_descr;
                sgdt(&gdt_descr);
                printf("%lx %u\n", gdt_descr.address, gdt_descr.size);
                usleep(100000);
        }
        return 0;
}
This program will typically bounce between CPUs and therefore print different addresses depending on which CPU the sgdt instructions runs on.