[System.Core/Android] Android's libc.so doesn't export getpagesize()
authorJonathan Pryor <jonpryor@vt.edu>
Mon, 12 Aug 2013 20:59:14 +0000 (16:59 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Mon, 12 Aug 2013 20:59:14 +0000 (16:59 -0400)
Partially fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=12739

Android's libc.so doesn't export getpagesize(3), resulting in an
EntryPointNotFoundException:

System.EntryPointNotFoundException: getpagesize
  at (wrapper managed-to-native) System.IO.MemoryMappedFiles.MemoryMapImpl.getpagesize ()
  at System.IO.MemoryMappedFiles.MemoryMapImpl.Map (int,long,long&,System.IO.MemoryMappedFiles.MemoryMappedFileAccess,intptr&,int&)
  at System.IO.MemoryMappedFiles.MemoryMappedViewAccessor.Create (long,long,System.IO.MemoryMappedFiles.MemoryMappedFileAccess)
  at System.IO.MemoryMappedFiles.MemoryMappedViewAccessor..ctor (int,long,long,System.IO.MemoryMappedFiles.MemoryMappedFileAccess)
  at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor (long,long,System.IO.MemoryMappedFiles.MemoryMappedFileAccess)

Android does provide getpagesize(3); it's just an inline function.

The full fix will require two parts:

 1. Update MemoryMapImpl to P/Invoke
    libmonodroid.so!monodroid_getpagesize()
 2. Add a libmonodroid.so!monodroid_getpagesize() export.

This commit implements (1).

mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs

index 005f0882ac6054af1f4e178830065b0ee32aa6a7..014cde469fa40cfd79d48db94249e05397586bba 100644 (file)
@@ -236,8 +236,18 @@ namespace System.IO.MemoryMappedFiles
                [DllImport ("libc", SetLastError=true)]
                static extern int open (string path, int flags, int access);
 
+#if MONODROID
+               [DllImport ("__Internal")]
+               static extern int monodroid_getpagesize ();
+
+               static int getpagesize ()
+               {
+                       return monodroid_getpagesize ();
+               }
+#else
                [DllImport ("libc")]
                static extern int getpagesize ();
+#endif
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                static extern long mono_filesize_from_path (string str);