implementing mmap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I'm just writing some code that wants to implement a stupid mmap on a 
device.
What  I did is the following:
1 - allocating a buffer with kmalloc:
	kmalloc_ptr = kmalloc(LEN + 2 * PAGE_SIZE, GFP_KERNEL);
2 - make sure that it's page aligned:
	kmalloc_area = (kmalloc_ptr + PAGE_SIZE -1) & PAGE_MASK;
  ( _area and _ptr point to the same address, though )
3 - fill it with some dumb numbers and print them to check:
	for( i = 0; i < LEN; i++) {
		((unsigned char*)kmalloc_area)[i] = (unsigned char)i;
	}
	for( i = 0; i < 20; i++) {
		printk(" %d ",( (unsigned char*)kmalloc_area)[i]);
	}
4 - in properly registered mmap, driver side, i wrote simply:
      ret = remap_pfn_range(vma, vma->vm_start,
             virt_to_phys(kmalloc_area) >> PAGE_SHIFT,
             vma->vm_end-vma->vm_start, vma->vm_page_prot);

Ok, what's wrong with that? From a userspace test program, I got only 
zeroes:
   fd = open("/dev/mmaptest",O_RDWR);
   mmapped_ptr = mmap(NULL,SIZE,PROT_READ | PROT_WRITE, MAP_FILE | 
MAP_SHARED ,fd,0);
   for( i=0; i < SIZE; i++){
       printf(" i=%d, mmap[%d]=%d\n",i,i,mmapped_ptr[i]);
   }
and that's the output:
 i=0, mmap[0]=0
 i=1, mmap[1]=0
 i=2, mmap[2]=0
...

I'm clearly missing something trivial, and probably need more coffe... ;)
Ideas? 
Thanks in advance.
-- 
-gaspa-
-----------------------------------------------
-------- https://launchpad.net/~gaspa ---------
------ HomePage: iogaspa.altervista.org -------
-Il lunedi'dell'arrampicatore: www.lunedi.org -

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux