Skip to Content
Linux Device Drivers Development
book

Linux Device Drivers Development

by John Madieu
October 2017
Intermediate to advanced
586 pages
14h 8m
English
Packt Publishing
Content preview from Linux Device Drivers Development

Implementing mmap in the kernel

Since user space code cannot access kernel memory, the purpose of the mmap() function is to derive one or more protected kernel page table entries (which correspond to the memory to be mapped) and duplicate the user space page tables, remove the kernel flag protection, and set permission flags that will allow the user to access the same memory as the kernel without needing special privileges.

The steps to write a mmap file operation are as follows:

  1. Get the mapping offset and check whether it is beyond our buffer size or not:
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;  
if (offset >= buffer_size) 
         return -EINVAL; 
  1. Check whether the mapping size is bigger than our buffer size:
unsigned long size = vma->vm_end ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Device Drivers, Second Edition

Linux Device Drivers, Second Edition

Jonathan Corbet, Alessandro Rubini
Linux Device Drivers, 3rd Edition

Linux Device Drivers, 3rd Edition

Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman

Publisher Resources

ISBN: 9781785280009Supplemental Content