Home > OS >  Mmap o_direct writing files after bad address
Mmap o_direct writing files after bad address

Time:11-09

As the user layer function code below:

C/C + + code


Void simple_test (char * filename, int dma_fd)
{
Int file_fd
Void * user_mem=NULL;
Int pagesize=0;
Int rc;

File_fd=open (filename, O_RDWR | O_CREAT | O_TRUNC | O_DIRECT, 0666);
Pagesize=getpagesize ();
User_mem=mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, dma_fd, 0).
If (user_mem==(void *) - 1)
{
Fprintf (stderr, "mmap: % s \ n", the strerror (errno));
exit(-1);
}

Printf (" user_mem % p \ n ", user_mem);

Rc=write (file_fd user_mem, pagesize);
If (rc & lt; 0)
{
Perror (" write file ");
}
Else if (rc!=pagesize)
{
Printf (" Write file fail 0 x % lx!=0 x % lx. \ n ", rc, pagesize);
}

Rc=munmap (user_mem, pagesize);
If (rc)
{
Perror (" munmap ");
}
}

Kernel driver USES dma_alloc_coherent allocated memory, using dma_mmap_coherent mapped to the user space,
Execute the test function simple_test times write file: Bad addree
  • Related