Module Name:    src
Committed By:   kamil
Date:           Sat Mar 21 22:45:47 UTC 2020

Modified Files:
        src/sys/sys: cdefs.h

Log Message:
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>


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/sys/cdefs.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/cdefs.h
diff -u src/sys/sys/cdefs.h:1.150 src/sys/sys/cdefs.h:1.151
--- src/sys/sys/cdefs.h:1.150	Sun Dec  8 11:48:15 2019
+++ src/sys/sys/cdefs.h	Sat Mar 21 22:45:47 2020
@@ -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 */

Reply via email to