write protection by mmap of /dev/mem doesn't work

Alexej Sokolov bsd.quest at googlemail.com
Tue Mar 10 09:05:53 PDT 2009


hello,
How can I mmap some memory regions with PROT_WRITE protection flag ?
What i do:
 /* Open mem device */
        if ((devmem_fd = open("/dev/mem", O_RDWR)) == -1){
                perror("/dev/mem");
                exit (1);
        }

then if I try to mmap some memory region with PROT_READ it goes Ok. But by
PROT_WRITE it doesn't work:
sp =    mmap (  0,
                       MCLBYTES,       /* Size of remapped buffer = size of
mbuf cluster */
                       PROT_WRITE,
                       MAP_SHARED,
                       devmem_fd,
                       phys_addr       /* Physical addres of packet buffer
from descriptor */
                     );
I get by PROT_WRITE " segmentation fault"
What is the problem here ?
And question again:
How can I do it possible to remapp the kernel memory region to user space
process through /dev/mem and give to this user process write permissions to
remmaped space ?

Thanx


More information about the freebsd-hackers mailing list