#include <assert.h>
#include <ctype.h>
#include <glib.h>
+#include <stdlib.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/common-internal.h>
+#include <babeltrace/compat/unistd-internal.h>
#define SYSTEM_PLUGIN_PATH INSTALL_LIBDIR "/babeltrace/plugins"
#define HOME_ENV_VAR "HOME"
return norm_path;
}
+
+BT_HIDDEN
+size_t bt_common_get_page_size(void)
+{
+ int page_size;
+
+ page_size = bt_sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ printf_error("Cannot get system page size.");
+ abort();
+ }
+
+ return page_size;
+}
babeltrace/compat/stdio-internal.h \
babeltrace/compat/stdlib-internal.h \
babeltrace/compat/string-internal.h \
+ babeltrace/compat/unistd-internal.h \
babeltrace/compat/utc-internal.h \
babeltrace/compat/uuid-internal.h \
babeltrace/compiler-internal.h \
*/
#include <babeltrace/compiler-internal.h>
-#include <unistd.h>
#include <babeltrace/compat/limits-internal.h>
-#ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE */
-#define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
-#endif
-
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#define PTR_ALIGN(p, a) ((typeof(p)) ALIGN((unsigned long) (p), a))
BT_HIDDEN
GString *bt_common_normalize_path(const char *path, const char *wd);
+/*
+ * Return the system page size.
+ */
+BT_HIDDEN
+size_t bt_common_get_page_size(void);
+
#endif /* BABELTRACE_COMMON_INTERNAL_H */
--- /dev/null
+#ifndef _BABELTRACE_COMPAT_UNISTD_H
+#define _BABELTRACE_COMPAT_UNISTD_H
+
+/*
+ * babeltrace/compat/unistd.h
+ *
+ * (C) Copyright 2016 - Michael Jeanson <mjeanson@efficios.com>
+ *
+ * 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.
+ */
+
+
+#include <unistd.h>
+
+#ifdef __MINGW32__
+#include <windows.h>
+#include <errno.h>
+
+#define _SC_PAGESIZE 30
+
+static inline
+long bt_sysconf(int name)
+{
+ SYSTEM_INFO si;
+
+ switch(name) {
+ case _SC_PAGESIZE:
+ GetNativeSystemInfo(&si);
+ return si.dwPageSize;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+}
+
+#else
+
+static inline
+long bt_sysconf(int name)
+{
+ return sysconf(name);
+}
+
+#endif
+#endif /* _BABELTRACE_COMPAT_UNISTD_H */
#include <babeltrace/ctf-ir/fields.h>
#include <babeltrace/ctf-ir/fields-internal.h>
#include <babeltrace/align-internal.h>
+#include <babeltrace/common-internal.h>
#include <babeltrace/mmap-align-internal.h>
#include <babeltrace/types.h>
+#define PACKET_LEN_INCREMENT (bt_common_get_page_size() * 8 * CHAR_BIT)
+
struct bt_ctf_stream_pos {
int fd;
int prot; /* mmap protection */
#include <stdlib.h>
#include <stdint.h>
#include <sys/mman.h>
+#include <babeltrace/common-internal.h>
/*
* This header implements a wrapper over mmap (mmap_align) that memory
{
struct mmap_align *mma;
off_t page_aligned_offset; /* mmap offset, aligned to floor */
+ size_t page_size;
+
+ page_size = bt_common_get_page_size();
mma = malloc(sizeof(*mma));
if (!mma)
return MAP_FAILED;
mma->length = length;
- page_aligned_offset = ALIGN_FLOOR(offset, PAGE_SIZE);
+ page_aligned_offset = ALIGN_FLOOR(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
* require a 2 pages page_aligned_length if the range crosses a page
* boundary.
*/
- mma->page_aligned_length = ALIGN(length + offset - page_aligned_offset, PAGE_SIZE);
+ 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) {
#include <babeltrace/align-internal.h>
#include <inttypes.h>
-#define PACKET_LEN_INCREMENT (getpagesize() * 8 * CHAR_BIT)
-
static
struct bt_ctf_field *bt_ctf_field_integer_create(struct bt_ctf_field_type *);
static
#include <babeltrace/bitfield-internal.h>
#include <babeltrace/compat/fcntl-internal.h>
#include <babeltrace/types.h>
+#include <babeltrace/common-internal.h>
#include <glib.h>
#if (FLT_RADIX != 2)
/* The writer will add padding */
pos->mmap_offset += pos->packet_size / CHAR_BIT;
- pos->packet_size = getpagesize() * 8 * CHAR_BIT;
+ pos->packet_size = PACKET_LEN_INCREMENT;
do {
ret = bt_posix_fallocate(pos->fd, pos->mmap_offset,
pos->packet_size / CHAR_BIT);
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
-#include <unistd.h>
#include "fs.h"
#include "metadata.h"
#include "data-stream-file.h"
}
ctf_fs->error_fp = stderr;
- ctf_fs->page_size = (size_t) getpagesize();
+ ctf_fs->page_size = bt_common_get_page_size();
ctf_fs->port_data = g_ptr_array_new_with_free_func(port_data_destroy);
if (!ctf_fs->port_data) {
goto error;