CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
72 lines
2.6 KiB
C++
72 lines
2.6 KiB
C++
//===- FileHeaderReader.cpp - XRay File Header Reader --------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#include "llvm/XRay/FileHeaderReader.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::xray;
|
|
|
|
// Populates the FileHeader reference by reading the first 32 bytes of the file.
|
|
Expected<XRayFileHeader>
|
|
xray::readBinaryFormatHeader(DataExtractor &HeaderExtractor,
|
|
uint64_t &OffsetPtr) {
|
|
// FIXME: Maybe deduce whether the data is little or big-endian using some
|
|
// magic bytes in the beginning of the file?
|
|
|
|
// First 32 bytes of the file will always be the header. We assume a certain
|
|
// format here:
|
|
//
|
|
// (2) uint16 : version
|
|
// (2) uint16 : type
|
|
// (4) uint32 : bitfield
|
|
// (8) uint64 : cycle frequency
|
|
// (16) - : padding
|
|
XRayFileHeader FileHeader;
|
|
auto PreReadOffset = OffsetPtr;
|
|
FileHeader.Version = HeaderExtractor.getU16(&OffsetPtr);
|
|
if (OffsetPtr == PreReadOffset)
|
|
return createStringError(
|
|
std::make_error_code(std::errc::invalid_argument),
|
|
"Failed reading version from file header at offset %" PRId64 ".",
|
|
OffsetPtr);
|
|
|
|
PreReadOffset = OffsetPtr;
|
|
FileHeader.Type = HeaderExtractor.getU16(&OffsetPtr);
|
|
if (OffsetPtr == PreReadOffset)
|
|
return createStringError(
|
|
std::make_error_code(std::errc::invalid_argument),
|
|
"Failed reading file type from file header at offset %" PRId64 ".",
|
|
OffsetPtr);
|
|
|
|
PreReadOffset = OffsetPtr;
|
|
uint32_t Bitfield = HeaderExtractor.getU32(&OffsetPtr);
|
|
if (OffsetPtr == PreReadOffset)
|
|
return createStringError(
|
|
std::make_error_code(std::errc::invalid_argument),
|
|
"Failed reading flag bits from file header at offset %" PRId64 ".",
|
|
OffsetPtr);
|
|
|
|
FileHeader.ConstantTSC = Bitfield & 1uL;
|
|
FileHeader.NonstopTSC = Bitfield & 1uL << 1;
|
|
PreReadOffset = OffsetPtr;
|
|
FileHeader.CycleFrequency = HeaderExtractor.getU64(&OffsetPtr);
|
|
if (OffsetPtr == PreReadOffset)
|
|
return createStringError(
|
|
std::make_error_code(std::errc::invalid_argument),
|
|
"Failed reading cycle frequency from file header at offset %" PRId64
|
|
".",
|
|
OffsetPtr);
|
|
|
|
std::memcpy(&FileHeader.FreeFormData,
|
|
HeaderExtractor.getData().bytes_begin() + OffsetPtr, 16);
|
|
|
|
// Manually advance the offset pointer 16 bytes, after getting a raw memcpy
|
|
// from the underlying data.
|
|
OffsetPtr += 16;
|
|
return std::move(FileHeader);
|
|
}
|