Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Currently, memory-mapped file access via System.IO.MemoryMappedFiles is broken on Android due to an assumption that the unistd.h-declared getpagesize() function has an entrypoint in the system libc.so.
Example (simple read-only map of an entire file):
using (MemoryMappedFile file = MemoryMappedFile.CreateFromFile(path, FileMode.Open, null, 0, MemoryMappedFileAccess.Read))
using (MemoryMappedViewAccessor accessor = file.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read))
// Do something with the view.
System.EntryPointNotFoundException: getpagesize at at (wrapper managed-to-native) System.IO.MemoryMappedFiles.MemoryMapImpl.getpagesize () at at System.IO.MemoryMappedFiles.MemoryMapImpl.Map (int,long,long&,System.IO.MemoryMappedFiles.MemoryMappedFileAccess,intptr&,int&) at at System.IO.MemoryMappedFiles.MemoryMappedViewAccessor.Create (long,long,System.IO.MemoryMappedFiles.MemoryMappedFileAccess) at at System.IO.MemoryMappedFiles.MemoryMappedViewAccessor..ctor (int,long,long,System.IO.MemoryMappedFiles.MemoryMappedFileAccess) at at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor (long,long,System.IO.MemoryMappedFiles.MemoryMappedFileAccess) at GetPageSize.MainActivity/c__AnonStorey0.<>m__0 (object,System.EventArgs) [0x0001e] in
Expected: Successful p/invoke to acquire the system page size for use in establishing memory map views.
Note: Can also be more easily reproduced by simply declaring the extern with its DllImport attribute and calling it directly.
Likely cause: getpagesize() is an inline in the NDK headers, not present as an entrypoint in the system libc.so.
Possible resolution: Simply implement a simple concrete getpagesize() entrypoint in the existing native .so's already supplied for the Xamarin.Android runtime, change the DllImport attribute for the extern to match.
Note: initially discussed in the forums (http://forums.xamarin.com/discussion/5231/system-io-memorymappedfiles-unsupported-on-android).
> Likely cause: getpagesize() is an inline in the NDK headers.
This is correct.
The fix will be to change the [DllImport] to be __Internal and provide a getpagesize() method from libmonodroid.so:
Much appreciated, Jonathan!
Fixed in monodroid/78101f5e6. It will hopefully land in 4.8.3.