summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lib/DebugInfo/MSF/MSFCommon.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2017-01-24 08:32:59 +0000
committerpatrick <patrick@openbsd.org>2017-01-24 08:32:59 +0000
commit53d771aafdbe5b919f264f53cba3788e2c4cffd2 (patch)
tree7eca39498be0ff1e3a6daf583cd9ca5886bb2636 /gnu/llvm/lib/DebugInfo/MSF/MSFCommon.cpp
parentIn preparation of compiling our kernels with -ffreestanding, explicitly map (diff)
downloadwireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.tar.xz
wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.zip
Import LLVM 4.0.0 rc1 including clang and lld to help the current
development effort on OpenBSD/arm64.
Diffstat (limited to 'gnu/llvm/lib/DebugInfo/MSF/MSFCommon.cpp')
-rw-r--r--gnu/llvm/lib/DebugInfo/MSF/MSFCommon.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/gnu/llvm/lib/DebugInfo/MSF/MSFCommon.cpp b/gnu/llvm/lib/DebugInfo/MSF/MSFCommon.cpp
new file mode 100644
index 00000000000..fdab7884646
--- /dev/null
+++ b/gnu/llvm/lib/DebugInfo/MSF/MSFCommon.cpp
@@ -0,0 +1,57 @@
+//===- 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");
+
+ if (SB.BlockMapAddr >= SB.NumBlocks)
+ return make_error<MSFError>(msf_error_code::invalid_format,
+ "Block map address is invalid.");
+
+ if (SB.FreeBlockMapBlock != 1 && SB.FreeBlockMapBlock != 2)
+ return make_error<MSFError>(
+ msf_error_code::invalid_format,
+ "The free block map isn't at block 1 or block 2.");
+
+ return Error::success();
+}