eina file: Fix map_populate on the global map
authorJean-Philippe Andre <jp.andre@samsung.com>
Fri, 15 Sep 2017 05:38:29 +0000 (14:38 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 18 Sep 2017 02:58:53 +0000 (11:58 +0900)
If eina_file_map_all() is called, the map isn't added to the internal
hash "rmap" and so _eina_file_map_rule_apply() would never be called.

@fix

asa

src/lib/eina/eina_file.c
src/lib/eina/eina_file_common.h

index c2c7f8f..97dec3e 100644 (file)
@@ -936,6 +936,11 @@ eina_file_map_all(Eina_File *file, Eina_File_Populate rule)
 #ifdef MAP_HUGETLB
         hugetlb = !!(flags & MAP_HUGETLB);
 #endif
+        if (!file->global_refcount)
+          file->global_hugetlb = hugetlb;
+        else
+          hugetlb = file->global_hugetlb;
+
         _eina_file_map_rule_apply(rule, file->global_map, file->length, hugetlb);
         file->global_refcount++;
         ret = file->global_map;
@@ -1059,13 +1064,21 @@ EAPI void
 eina_file_map_populate(Eina_File *file, Eina_File_Populate rule, const void *map,
                        unsigned long int offset, unsigned long int length)
 {
-   Eina_File_Map *em;
-   
    EINA_SAFETY_ON_NULL_RETURN(file);
    eina_lock_take(&file->lock);
-   em = eina_hash_find(file->rmap, &map);
-   if (em) _eina_file_map_rule_apply(rule, ((char *)em->map) + offset,
-                                     length, em->hugetlb);
+   if (map == file->global_map)
+     {
+        _eina_file_map_rule_apply(rule, ((char*) map) + offset, length,
+                                  file->global_hugetlb);
+     }
+   else
+     {
+        Eina_File_Map *em;
+
+        em = eina_hash_find(file->rmap, &map);
+        if (em) _eina_file_map_rule_apply(rule, ((char *) em->map) + offset,
+                                          length, em->hugetlb);
+     }
    eina_lock_release(&file->lock);
 }
 
index 0502029..93ba274 100644 (file)
@@ -101,6 +101,7 @@ struct _Eina_File
    Eina_Bool shared : 1;         /**< Indicates whether this file can be shared */
    Eina_Bool delete_me : 1;      /**< Indicates that this file should be deleted */
    Eina_Bool global_faulty : 1;  /**< Indicates whether #global_map is bad */
+   Eina_Bool global_hugetlb : 1; /**< Indicates whether #global_map uses HugeTLB */
    Eina_Bool virtual : 1;        /**< Indicates that this is a virtual file */
    Eina_Bool copied : 1;         /**< Indicates whether this file has copied data */
 };