X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fbabeltrace%2Fmmap-align-internal.h;h=e87f4a98efc297110700314914654aa3568d128f;hb=8f76831a6491cf9d2ce3827563a2777d608019b1;hp=0667ab0c8933ad7a8db91c659fd0977c3294ae9e;hpb=d4c6eae570130d24328a0a9b0e5c9024457ce9ab;p=babeltrace.git diff --git a/include/babeltrace/mmap-align-internal.h b/include/babeltrace/mmap-align-internal.h index 0667ab0c..e87f4a98 100644 --- a/include/babeltrace/mmap-align-internal.h +++ b/include/babeltrace/mmap-align-internal.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include /* @@ -48,6 +48,30 @@ struct mmap_align { size_t length; /* virtual mmap length */ }; +#ifdef __WIN32__ +#include + +/* + * 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) +{ + return ALIGN_FLOOR(offset, page_size); +} +#endif + static inline struct mmap_align *mmap_align(size_t length, int prot, int flags, int fd, off_t offset) @@ -62,7 +86,7 @@ struct mmap_align *mmap_align(size_t length, int prot, if (!mma) return MAP_FAILED; mma->length = length; - page_aligned_offset = ALIGN_FLOOR(offset, page_size); + page_aligned_offset = get_page_aligned_offset(offset, page_size); /* * Page aligned length needs to contain the requested range. * E.g., for a small range that fits within a single page, we might @@ -72,7 +96,7 @@ struct mmap_align *mmap_align(size_t length, int prot, mma->page_aligned_length = ALIGN(length + offset - page_aligned_offset, page_size); mma->page_aligned_addr = mmap(NULL, mma->page_aligned_length, prot, flags, fd, page_aligned_offset); - if (mma->page_aligned_addr == (void *) -1UL) { + if (mma->page_aligned_addr == MAP_FAILED) { free(mma); return MAP_FAILED; }