how to read the big buffer from kernel space to user applcation via mmap?
Hi driver experts,
I'm trying to use the mmap to let user application read data from kernel buffer.
I have 700000 bytes data in the kernel buffer and user application need to get it via mmap.
In driver code:
===============
I have alallocated 700000 bytes buffer and write drive_mmap as the following:
char *kmalloc_area;
xxx_mmap(structile *file,
struct vmarea_struct *vma
{
int i;
vma->vm_flags |= VM_SHARED;
remap_page_range(vma->vm_start,
virt_to_phys(kmalloc_area),
700000,
PAGE_SHARED);
return 0;
}and in the driver ininitunction:
=================================
kkmalloc_area=kmalloc(700000,GFP_KERNEL);
/* set first 100 bytes as 0x8 for testing */
for (i=0; i<100; i++)
kmalloc_area[i] = 0x8;I have other routine to to mmap
static int xxx_mmap_buffers(void)
{
ststructage *page;
int i;
page = vivirto_page(kmalloc_area);
memap_reserve(page);
return 1;
}in user application:
=====================
char *adaddr
addr = mmap(0, 700000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (adaddr= MAP_FAILED)
printf"****oops! error-->%d\n", ererrno;
printf"****adaddr>0x%x\n", adaddr);
for (i=0; i<100; i++)
printfuser addr[%d] --> 0x%x\n", i, addr[i]);at the end of user app function
===============================
xxx_mmap_buffers()
Now I have 2 two issues:
1. since I set first 100 bytes to 0x8 in the kernel buffer, I should read back when I run user app, but after mmap all '0x0' in the first 100 bytes, can someone tell me why and what's wrong?
2. Since my buffer is big, what I should to do to get the right buffer pointer in user app function to read ALL data back from the kernel space? can anyone give me a real example?
Many thanks for your help!
-Lan
__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com