blob: 5d97f33e1103fb577c2755c02d0eb16790901e2e [file] [log] [blame]
Zachary Turnerf52a8992016-07-15 20:43:38 +00001//===- 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/PDB/Raw/MsfCommon.h"
11#include "llvm/DebugInfo/PDB/Raw/RawError.h"
12
13using namespace llvm;
14using namespace llvm::pdb::msf;
15
16Error llvm::pdb::msf::validateSuperBlock(const SuperBlock &SB) {
17 // Check the magic bytes.
18 if (std::memcmp(SB.MagicBytes, Magic, sizeof(Magic)) != 0)
19 return make_error<RawError>(raw_error_code::corrupt_file,
20 "MSF magic header doesn't match");
21
22 if (!isValidBlockSize(SB.BlockSize))
23 return make_error<RawError>(raw_error_code::corrupt_file,
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<RawError>(raw_error_code::corrupt_file,
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<RawError>(raw_error_code::corrupt_file,
41 "Too many directory blocks.");
42
43 if (SB.BlockMapAddr == 0)
44 return make_error<RawError>(raw_error_code::corrupt_file,
45 "Block 0 is reserved");
46
47 return Error::success();
48}