Line data Source code
1 : //===- MsfCommon.h - 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 : #ifndef LLVM_DEBUGINFO_MSF_MSFCOMMON_H
11 : #define LLVM_DEBUGINFO_MSF_MSFCOMMON_H
12 :
13 : #include "llvm/ADT/ArrayRef.h"
14 :
15 : #include "llvm/Support/Endian.h"
16 : #include "llvm/Support/Error.h"
17 : #include "llvm/Support/MathExtras.h"
18 :
19 : #include <vector>
20 :
21 : namespace llvm {
22 : namespace msf {
23 : static const char Magic[] = {'M', 'i', 'c', 'r', 'o', 's', 'o', 'f',
24 : 't', ' ', 'C', '/', 'C', '+', '+', ' ',
25 : 'M', 'S', 'F', ' ', '7', '.', '0', '0',
26 : '\r', '\n', '\x1a', 'D', 'S', '\0', '\0', '\0'};
27 :
28 : // The superblock is overlaid at the beginning of the file (offset 0).
29 : // It starts with a magic header and is followed by information which
30 : // describes the layout of the file system.
31 9 : struct SuperBlock {
32 : char MagicBytes[sizeof(Magic)];
33 : // The file system is split into a variable number of fixed size elements.
34 : // These elements are referred to as blocks. The size of a block may vary
35 : // from system to system.
36 : support::ulittle32_t BlockSize;
37 : // The index of the free block map.
38 : support::ulittle32_t FreeBlockMapBlock;
39 : // This contains the number of blocks resident in the file system. In
40 : // practice, NumBlocks * BlockSize is equivalent to the size of the MSF
41 : // file.
42 : support::ulittle32_t NumBlocks;
43 : // This contains the number of bytes which make up the directory.
44 : support::ulittle32_t NumDirectoryBytes;
45 : // This field's purpose is not yet known.
46 : support::ulittle32_t Unknown1;
47 : // This contains the block # of the block map.
48 : support::ulittle32_t BlockMapAddr;
49 : };
50 :
51 23 : struct MsfLayout {
52 40 : MsfLayout() : SB(nullptr) {}
53 : const SuperBlock *SB;
54 : ArrayRef<support::ulittle32_t> DirectoryBlocks;
55 : ArrayRef<support::ulittle32_t> StreamSizes;
56 : std::vector<ArrayRef<support::ulittle32_t>> StreamMap;
57 : };
58 :
59 : inline bool isValidBlockSize(uint32_t Size) {
60 9 : switch (Size) {
61 : case 512:
62 : case 1024:
63 : case 2048:
64 : case 4096:
65 : return true;
66 : }
67 : return false;
68 : }
69 :
70 : // Super Block, Fpm0, Fpm1, and Block Map
71 : inline uint32_t getMinimumBlockCount() { return 4; }
72 :
73 : // Super Block, Fpm0, and Fpm1 are reserved. The Block Map, although required
74 : // need not be at block 3.
75 : inline uint32_t getFirstUnreservedBlock() { return 3; }
76 :
77 : inline uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {
78 241 : return alignTo(NumBytes, BlockSize) / BlockSize;
79 : }
80 :
81 : inline uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {
82 29891 : return BlockNumber * BlockSize;
83 : }
84 :
85 : Error validateSuperBlock(const SuperBlock &SB);
86 : } // namespace msf
87 : } // namespace llvm
88 :
89 : #endif // LLVM_DEBUGINFO_MSF_MSFCOMMON_H
|