I am doing a mmap of a file using the crate memmap. The mapping is done like this :
let mut mmap_var = memmap::MmapOptions::new().len(8589934592)
.map_mut(file).unwrap();
Everything goes well until i reach the value contained in mmap_var[4096]
for u8 and mmap_var[511]
for u64 for example.
When I try to go further, I get a : signal: 7, SIGBUS: access to undefined memory.
I don't understand why, because when I read the length of the mmaped array, it corresponds to the value I set it to.
I would like to access the whole mapped area.
EDIT
I know know that the problem was the file size as it was a regular file.
My problem is now that the main goal is to mmap a character device file that has zero as length.
The instruction is :
memmap2::MmapOptions::new().len(65000)
.map_mut(&file);
And it results in :
Os {
code: 19,
kind: Uncategorized,
message: "No such device",}
I got it!
When you try to mmap a regular file, the lenght should be at max, the size of the file in order to avoid SIGBUS for undefined memory region access.
Concerning the device files, the situation is different because even though their size is zero, they should be considered as a memory region that is attributed to the device.
So the fact that device files have zero as length is not a problem. But be careful to set the length to a value that is less than the device memory region size.
EDIT About the last error, it is simply due to the fact that the underlying device doesn't support mmap. So you should provide a mmap handler to the file operations of that device.