kmalloc - Address is not consecutive
Hi, I am trying to print the address of consecutive locations in a memory allocated using kmalloc. It prints non contiguous addresses! I tried with kmalloc_array, and normal array on stack, I got the same result. May I know the reason? The code fragment for array and result are given below. uint8_t MyArray[100]={'0'}; printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[0]); printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[1]); printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[2]); [ 8684.613909] Address is-> 00000000b3330991 [ 8684.613914] Address is-> 000000000519068c [ 8684.613915] Address is-> 00000000e448ca76 Thanks a lot, Lloyd
On 8/19/21 6:54 PM, Lloyd wrote:
Hi,
I am trying to print the address of consecutive locations in a memory allocated using kmalloc. It prints non contiguous addresses! I tried with kmalloc_array, and normal array on stack, I got the same result. May I know the reason? The code fragment for array and result are given below.
uint8_t MyArray[100]={'0'}; printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[0]); printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[1]); printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[2]);
[ 8684.613909] Address is-> 00000000b3330991 [ 8684.613914] Address is-> 000000000519068c [ 8684.613915] Address is-> 00000000e448ca76
Quoted from Documentation/core-api/printk-formats.rst:
A raw pointer value may be printed with %p which will hash the address before printing. The kernel also supports extended specifiers for printing pointers of different types. So the address printed neither logical nor physical address.
Thanks a lot, Lloyd
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi! this one is easy :)For printing pointer in kernel space, you should use %px not %p as format specifier. I heard this is for security reason(?).Chan Kim내 Galaxy에서 보냄 -------- 원본 이메일 --------발신: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> 날짜: 21/8/19 오후 9:17 (GMT+09:00) 받은 사람: Lloyd <lloydkl.tech@gmail.com>, kernelnewbies@kernelnewbies.org 제목: Re: kmalloc - Address is not consecutive On 8/19/21 6:54 PM, Lloyd wrote:> Hi,>> I am trying to print the address of consecutive locations in a > memory allocated using kmalloc. It prints non contiguous addresses! I > tried with kmalloc_array, and normal array on stack, I got the same > result. May I know the reason? The code fragment for array and result > are given below.>> uint8_t MyArray[100]={'0'};> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[0]);> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[1]);> printk(KERN_INFO "\nAddress is-> %p\n",&MyArray[2]);>>> [ 8684.613909] Address is-> 00000000b3330991> [ 8684.613914] Address is-> 000000000519068c> [ 8684.613915] Address is-> 00000000e448ca76>Quoted from Documentation/core-api/printk-formats.rst:> A raw pointer value may be printed with %p which will hash the address> before printing. The kernel also supports extended specifiers for printing> pointers of different types.So the address printed neither logical nor physical address.> Thanks a lot,> Lloyd>>> _______________________________________________> Kernelnewbies mailing list> Kernelnewbies@kernelnewbies.org> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies______________... mailing listKernelnewbies@kernelnewbies.orghttps://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (3)
-
ckim -
Lloyd -
wuzhouhui