Reputation: 305
I am trying to learn about the kernel and have been trying, unsuccessfully, for some time to print some of the basic data structures that make up the kernel landscape. My issue is that given a memory address, I'd like to be able to print the contents of that address.
For example, I have a function that determines the location of IDT. It returns (void *)
on the order of 0xffff81b8c0000fff
. However, whenever I try to printk
what's at that address, the result is a kernel panic. I understand that there are protections in place to prevent one from accessing kernel memory from userspace, but I am attempting to do this from within start_kernel, where I would have thought them to be readable.
The code is:
idt_ptr = sidt(); // returns (void *)
printk(KERN_INFO "680: IDT TABLE, FIRST ENTRY\n");
//entry is 64 bits
printk(KERN_INFO "680: %llx\n", *(unsigned long long *)idt_ptr);
Here's the tail end of the kernel panic that occurs after making this attempt:
It seems I need a semaphore for read access, but isn't this just an arbitrary address?
Upvotes: 4
Views: 649
Reputation: 13877
I recommend giving kdb a go for poking around inside the kernel.
Try setting up a KVM or qemu VM with a kdb-patched kernel.
Upvotes: 1
Reputation: 213386
For example, I have a function that determines the location of IDT. It returns (void *) on the order of 0xffff81b8c0000fff
No pointer to anything other than char*
could possibly equal 0x...ff
-- that address is not properly aligned for a pointer to a data structure containing anything other than char
s.
Conclusion: your sidt
function is broken and returns bogus address.
Upvotes: 6