Propagate error in mono_file_map_error on posix (mono/mono#14710)
authorRyan Lucia <rylucia@microsoft.com>
Fri, 31 May 2019 21:19:32 +0000 (17:19 -0400)
committerGitHub <noreply@github.com>
Fri, 31 May 2019 21:19:32 +0000 (17:19 -0400)
Commit migrated from https://github.com/mono/mono/commit/43aeac9e1e4ca32e10e476a07b38dde08c56beac

src/mono/mono/utils/mono-mmap.c

index b6931bc..eadfb0f 100644 (file)
@@ -364,6 +364,13 @@ mono_vfree (void *addr, size_t length, MonoMemAccountType type)
 void*
 mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
 {
+       return mono_file_map_error (length, flags, fd, offset, ret_handle, NULL, NULL);
+}
+
+void*
+mono_file_map_error (size_t length, int flags, int fd, guint64 offset, void **ret_handle,
+       const char *filepath, char **error_message)
+{
        void *ptr;
        int mflags = 0;
        int prot = prot_from_flags (flags);
@@ -380,6 +387,8 @@ mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_hand
 #ifdef HOST_WASM
        if (length == 0)
                /* emscripten throws an exception on 0 length */
+               *error_message = g_stdrup_printf ("%s failed file:%s length:0x%zx offset:0x%lluX error:%s\n",
+                       __func__, filepath ? filepath : "", length, offset, "mmaps of zero length are not permitted with emscripten");
                return NULL;
 #endif
 
@@ -387,19 +396,17 @@ mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_hand
        BEGIN_CRITICAL_SECTION;
        ptr = mmap (0, length, prot, mflags, fd, offset);
        END_CRITICAL_SECTION;
-       if (ptr == MAP_FAILED)
+       if (ptr == MAP_FAILED) {
+               if (error_message) {
+                       *error_message = g_strdup_printf ("%s failed file:%s length:0x%zX offset:0x%lluX error:%s(0x%X)\n",
+                               __func__, filepath ? filepath : "", length, offset, g_strerror (errno), errno);
+               }
                return NULL;
+       }
        *ret_handle = (void*)length;
        return ptr;
 }
 
-void*
-mono_file_map_error (size_t length, int flags, int fd, guint64 offset, void **ret_handle,
-       const char *filepath, char **error_message)
-{
-       return mono_file_map (length, flags, fd, offset, ret_handle);
-}
-
 /**
  * mono_file_unmap:
  * \param addr memory address returned by mono_file_map ()