Fix: bt2: autodisc: remove thread error while inserting status in map
[babeltrace.git] / src / compat / mman.c
index 1a7638c98381e0d6511a3a78f597e43015d90df7..7cd7a6fd8105dff245209cf3311473c0e8e84957 100644 (file)
@@ -1,29 +1,11 @@
 /*
- * compat/compat_mman.h
+ * SPDX-License-Identifier: MIT
  *
- * Copyright (C) 2013   JP Ikaheimonen <jp_ikaheimonen@mentor.com>
- *               2016   Michael Jeanson <mjeanson@efficios.com>
+ * Copyright (C) 2013 JP Ikaheimonen <jp_ikaheimonen@mentor.com>
+ * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
  *
  * These sources are based on ftp://g.oswego.edu/pub/misc/malloc.c
  * file by Doug Lea, released to the public domain.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
  */
 
 #define BT_LOG_OUTPUT_LEVEL (mapping->log_level)
@@ -31,6 +13,7 @@
 #include "logging/log.h"
 
 #include "common/macros.h"
+#include "common/common.h"
 
 #ifdef __APPLE__
 /*
@@ -90,11 +73,11 @@ void mapping_clean(struct mmap_mapping *mapping)
        if (mapping) {
                if (!CloseHandle(mapping->map_handle)) {
                        BT_LOGF_STR("Failed to close mmap map_handle.");
-                       abort();
+                       bt_common_abort();
                }
                if (!CloseHandle(mapping->file_handle)) {
                        BT_LOGF_STR("Failed to close mmap file_handle.");
-                       abort();
+                       bt_common_abort();
                }
                free(mapping);
                mapping = NULL;
@@ -112,7 +95,7 @@ void addr_clean(void *addr)
                 */
                BT_LOG_WRITE_CUR_LVL(BT_LOG_FATAL, BT_LOG_FATAL, BT_LOG_TAG,
                        "Failed to unmap mmap mapping.");
-               abort();
+               bt_common_abort();
        }
 }
 
@@ -121,7 +104,7 @@ void mmap_lock(int log_level)
 {
        if (pthread_mutex_lock(&mmap_mutex)) {
                BT_LOG_WRITE_CUR_LVL(BT_LOG_FATAL, log_level, BT_LOG_TAG, "Failed to acquire mmap_mutex.");
-               abort();
+               bt_common_abort();
        }
 }
 
@@ -130,7 +113,7 @@ void mmap_unlock(int log_level)
 {
        if (pthread_mutex_unlock(&mmap_mutex)) {
                BT_LOG_WRITE_CUR_LVL(BT_LOG_FATAL, log_level, BT_LOG_TAG, "Failed to release mmap_mutex.");
-               abort();
+               bt_common_abort();
        }
 }
 
@@ -292,7 +275,7 @@ int bt_munmap(void *addr, size_t length)
        /* Remove it. */
        if (!g_hash_table_remove(mmap_mappings, addr)) {
                BT_LOGF_STR("Failed to remove mapping from hashtable.");
-               abort();
+               bt_common_abort();
        }
 
 end:
@@ -300,4 +283,17 @@ end:
        return ret;
 }
 
+BT_HIDDEN
+size_t bt_mmap_get_offset_align_size(int log_level)
+{
+       SYSTEM_INFO sysinfo;
+
+       GetNativeSystemInfo(&sysinfo);
+       BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level, BT_LOG_TAG,
+               "Allocator granularity is %lu.",
+               sysinfo.dwAllocationGranularity);
+
+       return sysinfo.dwAllocationGranularity;
+}
+
 #endif
This page took 0.025703 seconds and 4 git commands to generate.