JustKernel

Ray Of Hope

basic programs to clear the concepts

Userspace and kernel space virtual address space division. TO understand the address space allocation between user space and kernel space I wrote this simple program.

Kernel space:
10 int init_module(void)
11 {
12 void * kern_mem;
13 kern_mem = kmalloc(5, GFP_KERNEL);
14 printk(KERN_INFO “Hello world addr=%lx”, (unsigned long)kern_mem);
15 return 0;
16 }
O/P : addr 0xffff88018a050160 // in the kernel space

user program
void main()
{
void *usersp_mem;
usersp_mem = (char *) malloc(20)
printf(“%lx”, (unsigned long) usersp_mem);
}
O/P: 0x1bcb010 user space address.

Canonical form addresses run from 0 through 00007FFF’FFFFFFFF — USERMODE, and from FFFF8000’00000000 through FFFFFFFF’FFFFFFFF — KERNEL MODE, for a total of 256 TB of usable virtual address . If MSB is 1 then its a kernel mode address.

One Response to “basic programs to clear the concepts”


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.