diff options
author | Zachary Turner <zturner@google.com> | 2016-07-29 20:56:36 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-07-29 20:56:36 +0000 |
commit | a3225b0451cc68788db10c62a66bb189817658b1 (patch) | |
tree | 8e91ca1dab5f2c9a04964eaa93fa0db40688ffaf /llvm/lib/DebugInfo/MSF/MSFCommon.cpp | |
parent | ecbe2ea002cdc4c1da279121ed66c459f0c5a3e2 (diff) | |
download | bcm5719-llvm-a3225b0451cc68788db10c62a66bb189817658b1.tar.gz bcm5719-llvm-a3225b0451cc68788db10c62a66bb189817658b1.zip |
[msf] Resubmit "Rename Msf -> MSF".
Previously this change was submitted from a Windows machine, so
changes made to the case of filenames and directory names did
not survive the commit, and as a result the CMake source file
names and the on-disk file names did not match on case-sensitive
file systems.
I'm resubmitting this patch from a Linux system, which hopefully
allows the case changes to make it through unfettered.
llvm-svn: 277213
Diffstat (limited to 'llvm/lib/DebugInfo/MSF/MSFCommon.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/MSF/MSFCommon.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/MSF/MSFCommon.cpp b/llvm/lib/DebugInfo/MSF/MSFCommon.cpp new file mode 100644 index 00000000000..d79ccafe898 --- /dev/null +++ b/llvm/lib/DebugInfo/MSF/MSFCommon.cpp @@ -0,0 +1,48 @@ +//===- MSFCommon.cpp - Common types and functions for MSF files -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/MSF/MSFCommon.h" +#include "llvm/DebugInfo/MSF/MSFError.h" + +using namespace llvm; +using namespace llvm::msf; + +Error llvm::msf::validateSuperBlock(const SuperBlock &SB) { + // Check the magic bytes. + if (std::memcmp(SB.MagicBytes, Magic, sizeof(Magic)) != 0) + return make_error<MSFError>(msf_error_code::invalid_format, + "MSF magic header doesn't match"); + + if (!isValidBlockSize(SB.BlockSize)) + return make_error<MSFError>(msf_error_code::invalid_format, + "Unsupported block size."); + + // We don't support directories whose sizes aren't a multiple of four bytes. + if (SB.NumDirectoryBytes % sizeof(support::ulittle32_t) != 0) + return make_error<MSFError>(msf_error_code::invalid_format, + "Directory size is not multiple of 4."); + + // The number of blocks which comprise the directory is a simple function of + // the number of bytes it contains. + uint64_t NumDirectoryBlocks = + bytesToBlocks(SB.NumDirectoryBytes, SB.BlockSize); + + // The directory, as we understand it, is a block which consists of a list of + // block numbers. It is unclear what would happen if the number of blocks + // couldn't fit on a single block. + if (NumDirectoryBlocks > SB.BlockSize / sizeof(support::ulittle32_t)) + return make_error<MSFError>(msf_error_code::invalid_format, + "Too many directory blocks."); + + if (SB.BlockMapAddr == 0) + return make_error<MSFError>(msf_error_code::invalid_format, + "Block 0 is reserved"); + + return Error::success(); +} |