Revision as of 22:32, 14 December 2019 by Vegard (talk | contribs) (new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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;

                printf("%lx %u\n", gdt_descr.address, gdt_descr.size);


        return 0;

This program will typically bounce between CPUs and therefore print different addresses depending on which CPU the sgdt instructions runs on.