@@ -982,7 +982,7 @@ gboolean
982982mono_pe_file_time_date_stamp (const gunichar2 * filename , guint32 * out )
983983{
984984 void * map_handle ;
985- gint32 map_size ;
985+ guint32 map_size ;
986986 gpointer file_map = mono_pe_file_map (filename , & map_size , & map_handle );
987987 if (!file_map )
988988 return FALSE;
@@ -1011,13 +1011,13 @@ mono_pe_file_time_date_stamp (const gunichar2 *filename, guint32 *out)
10111011}
10121012
10131013gpointer
1014- mono_pe_file_map (const gunichar2 * filename , gint32 * map_size , void * * handle )
1014+ mono_pe_file_map (const gunichar2 * filename , guint32 * map_size , void * * handle )
10151015{
10161016 gchar * filename_ext = NULL ;
10171017 gchar * located_filename = NULL ;
1018- int fd = -1 ;
1019- struct stat statbuf ;
1018+ guint64 fsize = 0 ;
10201019 gpointer file_map = NULL ;
1020+ MonoFileMap * filed = NULL ;
10211021 ERROR_DECL (error );
10221022
10231023 /* According to the MSDN docs, a search path is applied to
@@ -1041,8 +1041,7 @@ mono_pe_file_map (const gunichar2 *filename, gint32 *map_size, void **handle)
10411041 goto exit ;
10421042 }
10431043
1044- fd = open (filename_ext , O_RDONLY , 0 );
1045- if (fd == -1 && (errno == ENOENT || errno == ENOTDIR ) && IS_PORTABILITY_SET ) {
1044+ if ((filed = mono_file_map_open (filename_ext )) == NULL && IS_PORTABILITY_SET ) {
10461045 gint saved_errno = errno ;
10471046
10481047 located_filename = mono_portability_find_file (filename_ext , TRUE);
@@ -1053,38 +1052,39 @@ mono_pe_file_map (const gunichar2 *filename, gint32 *map_size, void **handle)
10531052 goto exit ;
10541053 }
10551054
1056- fd = open (located_filename , O_RDONLY , 0 );
1057- if (fd == -1 ) {
1058- mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_PROCESS , "%s: Error opening file %s (3): %s" , __func__ , filename_ext , strerror (errno ));
1055+ if ((filed = mono_file_map_open (located_filename )) == NULL ) {
1056+ mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_PROCESS , "%s: Error opening file %s (3): %s" , __func__ , located_filename , strerror (errno ));
10591057 goto exit ;
10601058 }
10611059 }
1062- else if (fd == -1 ) {
1060+ else if (filed == NULL ) {
10631061 mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_PROCESS , "%s: Error opening file %s (3): %s" , __func__ , filename_ext , strerror (errno ));
10641062 goto exit ;
10651063 }
10661064
1067- if (fstat (fd , & statbuf ) == -1 ) {
1065+ fsize = mono_file_map_size (filed );
1066+ if (fsize == 0 ) {
10681067 mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_PROCESS , "%s: Error stat()ing file %s: %s" , __func__ , filename_ext , strerror (errno ));
10691068 goto exit ;
10701069 }
1071- * map_size = statbuf .st_size ;
1070+ g_assert (fsize <= G_MAXUINT32 );
1071+ * map_size = fsize ;
10721072
10731073 /* Check basic file size */
1074- if (statbuf . st_size < sizeof (IMAGE_DOS_HEADER )) {
1075- mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_PROCESS , "%s: File %s is too small: %" PRId64 , __func__ , filename_ext , ( gint64 ) statbuf . st_size );
1074+ if (fsize < sizeof (IMAGE_DOS_HEADER )) {
1075+ mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_PROCESS , "%s: File %s is too small: %" PRId64 , __func__ , filename_ext , fsize );
10761076
10771077 goto exit ;
10781078 }
10791079
1080- file_map = mono_file_map (statbuf . st_size , MONO_MMAP_READ | MONO_MMAP_PRIVATE , fd , 0 , handle );
1080+ file_map = mono_file_map (fsize , MONO_MMAP_READ | MONO_MMAP_PRIVATE , mono_file_map_fd ( filed ) , 0 , handle );
10811081 if (file_map == NULL ) {
10821082 mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_PROCESS , "%s: Error mmap()int file %s: %s" , __func__ , filename_ext , strerror (errno ));
10831083 goto exit ;
10841084 }
10851085exit :
1086- if (fd != -1 )
1087- close ( fd );
1086+ if (filed )
1087+ mono_file_map_close ( filed );
10881088 g_free (located_filename );
10891089 g_free (filename_ext );
10901090 return file_map ;
0 commit comments