Bug 12739 - System.IO.MemoryMappedFile implementation nonfunctional (cannot p/invoke to getpagesize()).
Summary: System.IO.MemoryMappedFile implementation nonfunctional (cannot p/invoke to g...
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.7.x
Hardware: Macintosh Mac OS
: High normal
Target Milestone: ---
Assignee: Radek Doulik
Depends on:
Reported: 2013-06-18 13:57 UTC by Brian Berry
Modified: 2013-08-12 17:14 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:

Description Brian Berry 2013-06-18 13:57:43 UTC
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.

Many thanks!
Comment 1 Brian Berry 2013-06-18 13:58:42 UTC
Note:  initially discussed in the forums (http://forums.xamarin.com/discussion/5231/system-io-memorymappedfiles-unsupported-on-android).
Comment 2 Jonathan Pryor 2013-06-18 14:34:08 UTC
> 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:

Comment 3 Brian Berry 2013-06-18 14:52:07 UTC
Much appreciated, Jonathan!
Comment 4 Jonathan Pryor 2013-08-12 17:14:11 UTC
Fixed in monodroid/78101f5e6. It will hopefully land in 4.8.3.