Bug 19460

Summary: View Accessor for Zero byte file MemoryMappedFile
Product: [Mono] Class Libraries Reporter: nicholas.rudh
Component: System.CoreAssignee: Bugzilla <bugzilla>
Severity: normal CC: kumpera, mono-bugs+mono
Priority: ---    
Version: 3.2.x   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description nicholas.rudh 2014-05-01 14:42:07 UTC
  Hello, I am currently using Mono on a Xilinx Zynq board. I have been trying to use /dev/mem to increase the speed at which I can toggle GPIO pins. However i have found that there is an error with how the MemoryMappedFile handles Zero byte files. The first was addressed in the current Master solution(error with "capacity"), but there is another when one tries to create a MemroyMapedViewAccessor from a Zero byte file the "size" will always be set to zero because of this logic (line 165 MemoryMapImpl.Map)

   if (size == 0 || size > fsize)
      size = fsize;

  fsize will always be zero resulting in size being set to zero and the Syscall.mmap will fail and return a -1 resulting in the IOException being thrown.

 Steps to Reproduce: 
1) create MemoryMap of /dev/mem
2) create MemoryMappedViewAccessor

 Actual Results: 
  Throws the IOException (line 186) because the mmap fails

 Expected Results: 
  Create a MemoryMappedViewAccessor, which should allow for size to be greater than the file size.

 Build Date & Platform: 
  5/1/2014 PetaLinux v2013.10 Yocto 1.4

 Additional Builds and Platforms: 

if you need anymore information I can provide it. Thanks
Comment 1 Rodrigo Kumpera 2014-06-19 19:10:57 UTC
Fixed in master.