1 //===- MSFCommon.cpp - Common types and functions for MSF files -*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/DebugInfo/MSF/MSFCommon.h" 11 #include "llvm/DebugInfo/MSF/MSFError.h" 12 13 using namespace llvm; 14 using namespace llvm::msf; 15 16 Error llvm::msf::validateSuperBlock(const SuperBlock &SB) { 17 // Check the magic bytes. 18 if (std::memcmp(SB.MagicBytes, Magic, sizeof(Magic)) != 0) 19 return make_error<MSFError>(msf_error_code::invalid_format, 20 "MSF magic header doesn't match"); 21 22 if (!isValidBlockSize(SB.BlockSize)) 23 return make_error<MSFError>(msf_error_code::invalid_format, 24 "Unsupported block size."); 25 26 // We don't support directories whose sizes aren't a multiple of four bytes. 27 if (SB.NumDirectoryBytes % sizeof(support::ulittle32_t) != 0) 28 return make_error<MSFError>(msf_error_code::invalid_format, 29 "Directory size is not multiple of 4."); 30 31 // The number of blocks which comprise the directory is a simple function of 32 // the number of bytes it contains. 33 uint64_t NumDirectoryBlocks = 34 bytesToBlocks(SB.NumDirectoryBytes, SB.BlockSize); 35 36 // The directory, as we understand it, is a block which consists of a list of 37 // block numbers. It is unclear what would happen if the number of blocks 38 // couldn't fit on a single block. 39 if (NumDirectoryBlocks > SB.BlockSize / sizeof(support::ulittle32_t)) 40 return make_error<MSFError>(msf_error_code::invalid_format, 41 "Too many directory blocks."); 42 43 if (SB.BlockMapAddr == 0) 44 return make_error<MSFError>(msf_error_code::invalid_format, 45 "Block 0 is reserved"); 46 47 return Error::success(); 48 } 49