- /* map new base. Need mapping length from header. */
- 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 */
-
- packet_index.offset = pos->mmap_offset;
- packet_index.content_size = 0;
- packet_index.packet_size = 0;
- packet_index.timestamp_begin = 0;
- packet_index.timestamp_end = 0;
- packet_index.events_discarded = 0;
- packet_index.events_discarded_len = 0;
-
- /* read and check header, set stream id (and check) */
- if (file_stream->parent.trace_packet_header) {
- /* Read packet header */
- ret = generic_rw(&pos->parent, &file_stream->parent.trace_packet_header->p);
- if (ret)
- return ret;
- len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("magic"));
- if (len_index >= 0) {
- struct bt_definition *field;
- uint64_t magic;
-
- field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
- magic = bt_get_unsigned_int(field);
- if (magic != CTF_MAGIC) {
- fprintf(stderr, "[error] Invalid magic number 0x%" PRIX64 " at packet %u (file offset %zd).\n",
- magic,
- file_stream->pos.packet_cycles_index->len,
- (ssize_t) pos->mmap_offset);
- return -EINVAL;
- }
+ pos->base_mma = NULL;
+ }
+ /* map new base. Need mapping length from header. */
+ pos->base_mma = mmap_align(packet_map_len >> LOG2_CHAR_BIT, PROT_READ,
+ MAP_PRIVATE, pos->fd, pos->mmap_offset);
+ assert(pos->base_mma != MAP_FAILED);
+ /*
+ * Use current mapping size as temporary content and packet
+ * size.
+ */
+ pos->content_size = packet_map_len;
+ pos->packet_size = packet_map_len;
+ pos->offset = 0; /* Position of the packet header */
+
+ packet_index.offset = pos->mmap_offset;
+ packet_index.content_size = 0;
+ packet_index.packet_size = 0;
+ packet_index.timestamp_begin = 0;
+ packet_index.timestamp_end = 0;
+ packet_index.events_discarded = 0;
+ packet_index.events_discarded_len = 0;
+
+ /* read and check header, set stream id (and check) */
+ if (file_stream->parent.trace_packet_header) {
+ /* Read packet header */
+ ret = generic_rw(&pos->parent, &file_stream->parent.trace_packet_header->p);
+ if (ret) {
+ if (ret == -EFAULT)
+ goto retry;
+ return ret;
+ }
+ len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("magic"));
+ if (len_index >= 0) {
+ struct bt_definition *field;
+ uint64_t magic;
+
+ field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
+ magic = bt_get_unsigned_int(field);
+ if (magic != CTF_MAGIC) {
+ fprintf(stderr, "[error] Invalid magic number 0x%" PRIX64 " at packet %u (file offset %zd).\n",
+ magic,
+ file_stream->pos.packet_cycles_index->len,
+ (ssize_t) pos->mmap_offset);
+ return -EINVAL;