size_t length; /* virtual mmap length */
};
-#ifdef __WIN32__
-#include <windows.h>
-
-/*
- * On windows the memory mapping offset must be aligned to the memory
- * allocator allocation granularity and not the page size.
- */
-static inline
-off_t get_page_aligned_offset(off_t offset, size_t page_size)
-{
- SYSTEM_INFO sysinfo;
-
- GetNativeSystemInfo(&sysinfo);
-
- return ALIGN_FLOOR(offset, sysinfo.dwAllocationGranularity);
-}
-#else
static inline
-off_t get_page_aligned_offset(off_t offset, size_t page_size)
+off_t get_page_aligned_offset(off_t offset, int log_level)
{
- return ALIGN_FLOOR(offset, page_size);
+ return ALIGN_FLOOR(offset, bt_mmap_get_offset_align_size(log_level));
}
-#endif
static inline
struct mmap_align *mmap_align(size_t length, int prot,
if (!mma)
return MAP_FAILED;
mma->length = length;
- page_aligned_offset = get_page_aligned_offset(offset, page_size);
+ page_aligned_offset = get_page_aligned_offset(offset, log_level);
/*
* Page aligned length needs to contain the requested range.
* E.g., for a small range that fits within a single page, we might
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
int bt_munmap(void *addr, size_t length);
+/*
+ * On Windows the memory mapping offset must be aligned to the memory
+ * allocator allocation granularity and not the page size.
+ */
+size_t bt_mmap_get_offset_align_size(int log_level);
+
#else /* __MINGW32__ */
#include <sys/mman.h>
+#include "common/common.h"
static inline
void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
{
return munmap(addr, length);
}
+
+/*
+ * On other platforms the memory mapping offset must be aligned to the
+ * page size.
+ */
+static inline
+size_t bt_mmap_get_offset_align_size(int log_level)
+{
+ return bt_common_get_page_size(log_level);
+}
#endif /* __MINGW32__ */
#ifndef MAP_ANONYMOUS
map_requested_offset:
offset_in_mapping = offset %
- bt_common_get_page_size(ds_file->log_level);
+ bt_mmap_get_offset_align_size(ds_file->log_level);
ds_file->mmap_offset = offset - offset_in_mapping;
ds_file->request_offset = offset_in_mapping;
bt_logging_level log_level)
{
int ret;
- const size_t page_size = bt_common_get_page_size(log_level);
+ const size_t offset_align = bt_mmap_get_offset_align_size(log_level);
struct ctf_fs_ds_file *ds_file = g_new0(struct ctf_fs_ds_file, 1);
if (!ds_file) {
goto error;
}
- ds_file->mmap_max_len = page_size * 2048;
+ ds_file->mmap_max_len = offset_align * 2048;
goto end;