pos->packet_size = 0;
pos->content_size = 0;
pos->content_size_loc = NULL;
- pos->base = NULL;
+ pos->base_mma = NULL;
pos->offset = 0;
pos->dummy = false;
pos->cur_index = 0;
if (pos->prot == PROT_WRITE && pos->content_size_loc)
*pos->content_size_loc = pos->offset;
- if (pos->base) {
+ if (pos->base_mma) {
/* unmap old base */
- ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
+ ret = munmap_align(pos->base_mma);
if (ret) {
fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
if (pos->prot == PROT_WRITE && pos->content_size_loc)
*pos->content_size_loc = pos->offset;
- if (pos->base) {
+ if (pos->base_mma) {
/* unmap old base */
- ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
+ ret = munmap_align(pos->base_mma);
if (ret) {
fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
assert(0);
}
- pos->base = NULL;
+ pos->base_mma = NULL;
}
/*
}
}
/* map new base. Need mapping length from header. */
- pos->base = mmap(NULL, pos->packet_size / CHAR_BIT, pos->prot,
- pos->flags, pos->fd, pos->mmap_offset);
- if (pos->base == MAP_FAILED) {
+ pos->base_mma = mmap_align(pos->packet_size / CHAR_BIT, pos->prot,
+ pos->flags, pos->fd, pos->mmap_offset);
+ if (pos->base_mma == MAP_FAILED) {
fprintf(stderr, "[error] mmap error %s.\n",
strerror(errno));
assert(0);
for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
uint64_t stream_id = 0;
- if (pos->base) {
+ if (pos->base_mma) {
/* unmap old base */
- ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
+ ret = munmap_align(pos->base_mma);
if (ret) {
fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
return ret;
}
- pos->base = NULL;
+ pos->base_mma = NULL;
}
/* map new base. Need mapping length from header. */
- pos->base = mmap(NULL, MAX_PACKET_HEADER_LEN / CHAR_BIT, PROT_READ,
+ pos->base_mma = mmap_align(MAX_PACKET_HEADER_LEN / CHAR_BIT, PROT_READ,
MAP_PRIVATE, pos->fd, pos->mmap_offset);
+ assert(pos->base_mma != MAP_FAILED);
pos->content_size = MAX_PACKET_HEADER_LEN; /* Unknown at this point */
pos->packet_size = MAX_PACKET_HEADER_LEN; /* Unknown at this point */
pos->offset = 0; /* Position of the packet header */
pos->content_size = 0;
pos->content_size_loc = NULL;
pos->fd = mmap_info->fd;
- pos->base = 0;
+ pos->base_mma = NULL;
pos->offset = 0;
pos->dummy = false;
pos->cur_index = 0;
struct definition *tmpdef;
struct definition_float *tmpfloat;
struct ctf_stream_pos destp;
+ struct mmap_align mma;
int ret;
switch (float_declaration->mantissa->len + 1) {
}
tmpfloat = container_of(tmpdef, struct definition_float, p);
ctf_init_pos(&destp, -1, O_RDWR);
- destp.base = (char *) u.bits;
+ mmap_align_set_addr(&mma, (char *) u.bits);
+ destp.base_mma = &mma;
destp.packet_size = sizeof(u) * CHAR_BIT;
ctf_align_pos(pos, float_declaration->p.alignment);
ret = _ctf_float_copy(&destp.parent, tmpfloat, ppos, float_definition);
struct definition *tmpdef;
struct definition_float *tmpfloat;
struct ctf_stream_pos srcp;
+ struct mmap_align mma;
int ret;
switch (float_declaration->mantissa->len + 1) {
}
tmpfloat = container_of(tmpdef, struct definition_float, p);
ctf_init_pos(&srcp, -1, O_RDONLY);
- srcp.base = (char *) u.bits;
+ mmap_align_set_addr(&mma, (char *) u.bits);
+ srcp.base_mma = &mma;
srcp.packet_size = sizeof(u) * CHAR_BIT;
switch (float_declaration->mantissa->len + 1) {
case FLT_MANT_DIG:
if (!integer_declaration->signedness) {
if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_read_le(pos->base, unsigned long,
+ bt_bitfield_read_le(mmap_align_addr(pos->base_mma), unsigned long,
pos->offset, integer_declaration->len,
&integer_definition->value._unsigned);
else
- bt_bitfield_read_be(pos->base, unsigned long,
+ bt_bitfield_read_be(mmap_align_addr(pos->base_mma), unsigned long,
pos->offset, integer_declaration->len,
&integer_definition->value._unsigned);
} else {
if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_read_le(pos->base, unsigned long,
+ bt_bitfield_read_le(mmap_align_addr(pos->base_mma), unsigned long,
pos->offset, integer_declaration->len,
&integer_definition->value._signed);
else
- bt_bitfield_read_be(pos->base, unsigned long,
+ bt_bitfield_read_be(mmap_align_addr(pos->base_mma), unsigned long,
pos->offset, integer_declaration->len,
&integer_definition->value._signed);
}
goto end;
if (!integer_declaration->signedness) {
if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_write_le(pos->base, unsigned long,
+ bt_bitfield_write_le(mmap_align_addr(pos->base_mma), unsigned long,
pos->offset, integer_declaration->len,
integer_definition->value._unsigned);
else
- bt_bitfield_write_be(pos->base, unsigned long,
+ bt_bitfield_write_be(mmap_align_addr(pos->base_mma), unsigned long,
pos->offset, integer_declaration->len,
integer_definition->value._unsigned);
} else {
if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_write_le(pos->base, unsigned long,
+ bt_bitfield_write_le(mmap_align_addr(pos->base_mma), unsigned long,
pos->offset, integer_declaration->len,
integer_definition->value._signed);
else
- bt_bitfield_write_be(pos->base, unsigned long,
+ bt_bitfield_write_be(mmap_align_addr(pos->base_mma), unsigned long,
pos->offset, integer_declaration->len,
integer_definition->value._signed);
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <sys/mman.h>
#include <errno.h>
#include <stdint.h>
#include <unistd.h>
#include <glib.h>
#include <stdio.h>
+#include <babeltrace/mmap-align.h>
struct bt_stream_callbacks;
size_t packet_size; /* current packet size, in bits */
size_t content_size; /* current content size, in bits */
uint32_t *content_size_loc; /* pointer to current content size */
- char *base; /* mmap base address */
+ struct mmap_align *base_mma;/* mmap base address */
ssize_t offset; /* offset from base, in bits. EOF for end of file. */
ssize_t last_offset; /* offset before the last read_event */
size_t cur_index; /* current index in packet index */
{
/* Only makes sense to get the address after aligning on CHAR_BIT */
assert(!(pos->offset % CHAR_BIT));
- return pos->base + (pos->offset / CHAR_BIT);
+ return mmap_align_addr(pos->base_mma) + (pos->offset / CHAR_BIT);
}
static inline