Skip to content

Instantly share code, notes, and snippets.

@wmealing
Created April 20, 2015 06:44
Show Gist options
  • Save wmealing/d94a909009fbac807a6f to your computer and use it in GitHub Desktop.
Save wmealing/d94a909009fbac807a6f to your computer and use it in GitHub Desktop.
#include <linux/slab.h>
void *ptr1;
void *ptr2;
int init_module()
{
ptr1 = kmalloc( (size_t)255,GFP_KERNEL);
ptr2 = kmalloc( (size_t)255,GFP_KERNEL);
printk("Ksize: %d\n", (int) ksize(ptr1));
printk("location ptr1: %p\n", ptr1);
printk("location ptr2: %p\n", ptr2);
return 0;
}
void cleanup_module()
{
kfree(ptr1);
kfree(ptr2);
return;
}
[root@localhost test]# make test
rmmod test && insmod test.ko
Ksize: 256
location ptr1: ffff880037b55b80
location ptr2: ffff880037f3fdc0
>>> 0xffff880037f3fdc0 - 0xffff880037b55b80
4104768L
>>> hex( 0xffff880037f3fdc0 - 0xffff880037b55b80 )
'0x3ea240L'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment