Re: Reading the GDT in kernel space?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



mohanlal jangir wrote:

I'm trying to read & display the GDT contents in kernel space. Is
this permissible?

Sure. Also note that sgdt is available from userspace even.

I used the "sgdt" assembly instruction to load the GDT register,
and found out the address & length of GDT from that (It is "0000c248") . Is this the physical or the virtual address?

SGDT gets you a kernel virtual address. That 0000c248 isn't though and it's incorrect. The problem you will be experiencing is that you haven't told GCC to pack the struct in which you put the result. If you declare:

struct gdtr {
        u16 limit;
        u32 base;
};

then gcc will align the 32-bit base field on a 32-bit boundary, meaning it will end up looking like:

struct gdtr {
        u16 limit;
	u16 padding
        u32 base;
};

SGDT then stores into the limit and padding and only the low 16-bits of base (your base is actually 0xc248xxxx). To avoid this, tell GCC to pack the struct:

struct gdtr {
        u16 limit;
        u32 base;
} __attribute__((packed));

Rene.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux