[compiler-rt] [CompilerRT] Add numerical sanitizer (PR #94322)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 12 14:35:43 PDT 2024
================
@@ -0,0 +1,135 @@
+//===------------------------ nsan_platform.h -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Platform specific information for NSan.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef NSAN_PLATFORM_H
+#define NSAN_PLATFORM_H
+
+namespace __nsan {
+
+// NSan uses two regions of memory to store information:
+// - 'shadow memory' stores the shadow copies of numerical values stored in
+// application memory.
+// - 'shadow types' is used to determine which value type each byte of memory
+// belongs to. This makes sure that we always know whether a shadow value is
+// valid. Shadow values may be tampered with using access through other
+// pointer types (type punning). Each byte stores:
+// - bit 1-0: whether the corresponding value is of unknown (00),
+// float (01), double (10), or long double (11) type.
+// - bit 5-2: the index of this byte in the value, or 0000 if type is
+// unknown.
+// This allows handling unaligned loat load/stores by checking that a load
+// with a given alignment corresponds to the alignment of the store.
+// Any store of a non-floating point type invalidates the corresponding
+// bytes, so that subsequent overlapping loads (aligned or not) know that
+// the corresponding shadow value is no longer valid.
+
+// On Linux/x86_64, memory is laid out as follows:
+//
+// +--------------------+ 0x800000000000 (top of memory)
----------------
vitalybuka wrote:
Maybe @thurstond can provide a feedback for these mappings?
https://github.com/llvm/llvm-project/pull/94322
More information about the llvm-commits
mailing list