<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://vegard.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=GDT</id>
	<title>GDT - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://vegard.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=GDT"/>
	<link rel="alternate" type="text/html" href="http://vegard.wiki/mediawiki/index.php?title=GDT&amp;action=history"/>
	<updated>2026-07-04T15:52:21Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>http://vegard.wiki/mediawiki/index.php?title=GDT&amp;diff=46&amp;oldid=prev</id>
		<title>Vegard: new page</title>
		<link rel="alternate" type="text/html" href="http://vegard.wiki/mediawiki/index.php?title=GDT&amp;diff=46&amp;oldid=prev"/>
		<updated>2019-12-14T22:32:51Z</updated>

		<summary type="html">&lt;p&gt;new page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;You can get the (kernel mapped) address of the GDT using the &amp;lt;tt&amp;gt;sgdt&amp;lt;/tt&amp;gt; instruction from userspace:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
struct desc_ptr {&lt;br /&gt;
        unsigned short size;&lt;br /&gt;
        unsigned long address;&lt;br /&gt;
} __attribute__((packed)) ;&lt;br /&gt;
&lt;br /&gt;
static inline void sgdt(struct desc_ptr *dtr)&lt;br /&gt;
{&lt;br /&gt;
        asm volatile(&amp;quot;sgdt %0&amp;quot; : &amp;quot;=m&amp;quot; (*dtr));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
        while (1) {&lt;br /&gt;
                struct desc_ptr gdt_descr;&lt;br /&gt;
                sgdt(&amp;amp;gdt_descr);&lt;br /&gt;
&lt;br /&gt;
                printf(&amp;quot;%lx %u\n&amp;quot;, gdt_descr.address, gdt_descr.size);&lt;br /&gt;
&lt;br /&gt;
                usleep(100000);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This program will typically bounce between CPUs and therefore print different addresses depending on which CPU the &amp;lt;tt&amp;gt;sgdt&amp;lt;/tt&amp;gt; instructions runs on.&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
[[Category:x86]]&lt;/div&gt;</summary>
		<author><name>Vegard</name></author>
	</entry>
</feed>