Hi all,

I am writing a mmap function for a new socket family. The function looks like the following. The memory that's being mapped is a contiguous block of memory that's allocated by a device driver which is around 2M in size.

/************************************************** ************/
int new_socket_mmap(struct file *file, struct socket *sock, struct vm_area_struct *vma)
int fd = (int)sock->sk;

unsigned long start = (unsigned long)vma->vm_start;
unsigned long size = (unsigned long)(vma->vm_end - vma->vm_start);
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
int error;

if (offset != 0)
return -ENXIO;

/* map the whole physically contiguous area in one piece
* hostBuffer is the physical address of the memory that
* needs to be mapped
if ( ( error = remap_pfn_range( vma,
pNEWSOCK->hostBuffer >> PAGE_SHIFT ),
vma->vm_page_prot ) ) < 0 )
return error;

return 0;
/************************************************** ************/

Everything seems to work except that when I call the mmap function from a user application, it returns 0 instead of the start address that was mapped. I called the mmap function as below.

if ( pBuffer = (unsigned long *)mmap( 0,
0 ) < 0 )
perror( "mmapping" );
exit( 1 );
printf( "0x%X\n", pBuffer );
/* and pBuffer turns out to be 0 */

However, if I do a printk at for the "start" variable in the mmap function and hardcode that into the user application (ie. pBuffer = 0xXXXXXXXX), I am able to see the right data that's in the memory (That means the mapping is actually working). So the question is, if the mapping works, how come it returns a 0 instead of the mapped address. Can someone please help me out on this one?

Thanks a lot,