Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys Expand the support of __no[sanitizer] attributes



details:   https://anonhg.NetBSD.org/src/rev/af3da4a53d08
branches:  trunk
changeset: 970362:af3da4a53d08
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Mar 21 22:45:47 2020 +0000

description:
Expand the support of __no[sanitizer] attributes

Add support for RUMPKERNEL that can reuse these attributes in the same code.
These macros are not intended to be used by userland and are still disabled
there. They are a NetBSD specific extension.

Add proper support for clang and GCC.

Set __no[sanitizer] only under a sanitizer, as otherwise there are build
warnings about unused compiler attributes.

Reviewed by <maxv>

diffstat:

 sys/sys/cdefs.h |  23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diffs (59 lines):

diff -r de24b4ce9d7a -r af3da4a53d08 sys/sys/cdefs.h
--- a/sys/sys/cdefs.h   Sat Mar 21 20:20:59 2020 +0000
+++ b/sys/sys/cdefs.h   Sat Mar 21 22:45:47 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cdefs.h,v 1.150 2019/12/08 11:48:15 maxv Exp $ */
+/*     $NetBSD: cdefs.h,v 1.151 2020/03/21 22:45:47 kamil Exp $        */
 
 /* * Copyright (c) 1991, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -38,9 +38,6 @@
 
 #ifdef _KERNEL_OPT
 #include "opt_diagnostic.h"
-#include "opt_kasan.h"
-#include "opt_kcsan.h"
-#include "opt_kmsan.h"
 #endif
 
 /*
@@ -336,28 +333,32 @@
 #define        __unreachable() do {} while (/*CONSTCOND*/0)
 #endif
 
-#if defined(_KERNEL)
-#if __GNUC_PREREQ__(4, 9) && defined(KASAN)
+#if defined(_KERNEL) || defined(_RUMPKERNEL)
+#if defined(__clang__) && __has_feature(address_sanitizer)
+#define        __noasan        __attribute__((no_sanitize("kernel-address", "address")))
+#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_ADDRESS__)
 #define        __noasan        __attribute__((no_sanitize_address))
 #else
 #define        __noasan        /* nothing */
 #endif
 
-#if __GNUC_PREREQ__(4, 9) && defined(KCSAN)
+#if defined(__clang__) && __has_feature(thread_sanitizer)
+#define        __nocsan        __attribute__((no_sanitize("thread")))
+#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_THREAD__)
 #define        __nocsan        __attribute__((no_sanitize_thread))
 #else
 #define        __nocsan        /* nothing */
 #endif
 
-#if defined(__clang__) && defined(KMSAN)
-#define        __nomsan        __attribute__((no_sanitize("kernel-memory")))
+#if defined(__clang__) && __has_feature(memory_sanitizer)
+#define        __nomsan        __attribute__((no_sanitize("kernel-memory", "memory")))
 #else
 #define        __nomsan        /* nothing */
 #endif
 
-#if defined(__clang__)
+#if defined(__clang__) && __has_feature(undefined_behavior_sanitizer)
 #define __noubsan      __attribute__((no_sanitize("undefined")))
-#elif __GNUC_PREREQ__(4, 9)
+#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_UNDEFINED__)
 #define __noubsan      __attribute__((no_sanitize_undefined))
 #else
 #define __noubsan      /* nothing */



Home | Main Index | Thread Index | Old Index