Author: imp
Date: Fri Sep 25 20:51:07 2020
New Revision: 366173
URL: https://svnweb.freebsd.org/changeset/base/366173

Log:
  Adjustments to includes for openzfs in _STANDALONE
  
  Allow the necessary parts of systm.h to be visible in the _STANDALONE
  environnment. Limit the reset to only being visible for _KERNEL
  builds.  Map KASSERT, etc to printf on failure in the bootloader until
  we have more confidence things won't break and leave systems
  unbootable. Eventually, this should map to a full panic in the
  bootloader, but that also needs some enhancement to be more useful.
  
  Reviewed by: tsoome, jhb
  Differential Revision:  https://reviews.freebsd.org/D26543

Modified:
  head/sys/sys/systm.h

Modified: head/sys/sys/systm.h
==============================================================================
--- head/sys/sys/systm.h        Fri Sep 25 20:39:20 2020        (r366172)
+++ head/sys/sys/systm.h        Fri Sep 25 20:51:07 2020        (r366173)
@@ -49,6 +49,7 @@
 
 __NULLABILITY_PRAGMA_PUSH
 
+#ifdef _KERNEL
 extern int cold;               /* nonzero if we are doing a cold boot */
 extern int suspend_blocked;    /* block suspend due to pending shutdown */
 extern int rebooting;          /* kern_reboot() has been called. */
@@ -83,28 +84,7 @@ enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST
                VM_GUEST_VMWARE, VM_GUEST_KVM, VM_GUEST_BHYVE, VM_GUEST_VBOX,
                VM_GUEST_PARALLELS, VM_LAST };
 
-/*
- * These functions need to be declared before the KASSERT macro is invoked in
- * !KASSERT_PANIC_OPTIONAL builds, so their declarations are sort of out of
- * place compared to other function definitions in this header.  On the other
- * hand, this header is a bit disorganized anyway.
- */
-void   panic(const char *, ...) __dead2 __printflike(1, 2);
-void   vpanic(const char *, __va_list) __dead2 __printflike(1, 0);
-
-#if defined(WITNESS) || defined(INVARIANT_SUPPORT)
-#ifdef KASSERT_PANIC_OPTIONAL
-void   kassert_panic(const char *fmt, ...)  __printflike(1, 2);
-#else
-#define kassert_panic  panic
-#endif
-#endif
-
 #ifdef INVARIANTS              /* The option is always available */
-#define        KASSERT(exp,msg) do {                                           
\
-       if (__predict_false(!(exp)))                                    \
-               kassert_panic msg;                                      \
-} while (0)
 #define        VNASSERT(exp, vp, msg) do {                                     
\
        if (__predict_false(!(exp))) {                                  \
                vn_printf(vp, "VNASSERT failed: %s not true at %s:%d (%s)\n",\
@@ -121,9 +101,6 @@ void        kassert_panic(const char *fmt, ...)  
__printflike
        panic("executing segment marked as unreachable at %s:%d (%s)\n", \
            __FILE__, __LINE__, __func__)
 #else
-#define        KASSERT(exp,msg) do { \
-} while (0)
-
 #define        VNASSERT(exp, vp, msg) do { \
 } while (0)
 #define        VNPASS(exp, vp) do { \
@@ -134,14 +111,49 @@ void      kassert_panic(const char *fmt, ...)  
__printflike
 #ifndef CTASSERT       /* Allow lint to override */
 #define        CTASSERT(x)     _Static_assert(x, "compile-time assertion 
failed")
 #endif
+#endif /* KERNEL */
 
-#if defined(_KERNEL)
-#include <sys/param.h>         /* MAXCPU */
-#include <sys/pcpu.h>          /* curthread */
-#include <sys/kpilite.h>
-#endif
+/*
+ * These functions need to be declared before the KASSERT macro is invoked in
+ * !KASSERT_PANIC_OPTIONAL builds, so their declarations are sort of out of
+ * place compared to other function definitions in this header.  On the other
+ * hand, this header is a bit disorganized anyway.
+ */
+void   panic(const char *, ...) __dead2 __printflike(1, 2);
+void   vpanic(const char *, __va_list) __dead2 __printflike(1, 0);
 
+
+#if defined(_STANDALONE)
 /*
+ * Until we have more experience with KASSERTS that are called
+ * from the boot loader, they are off. The bootloader does this
+ * a little differently than the kernel (we just call printf atm).
+ * we avoid most of the common functions in the boot loader, so
+ * declare printf() here too.
+ */
+int    printf(const char *, ...) __printflike(1, 2);
+#  define kassert_panic printf
+#else /* !_STANDALONE */
+#  if defined(WITNESS) || defined(INVARIANT_SUPPORT)
+#    ifdef KASSERT_PANIC_OPTIONAL
+void   kassert_panic(const char *fmt, ...)  __printflike(1, 2);
+#    else
+#      define kassert_panic    panic
+#    endif /* KASSERT_PANIC_OPTIONAL */
+#  endif /* defined(WITNESS) || defined(INVARIANT_SUPPORT) */
+#endif /* _STANDALONE */
+
+#if defined(INVARIANTS) || defined(_STANDALONE)
+#define        KASSERT(exp,msg) do {                                           
\
+       if (__predict_false(!(exp)))                                    \
+               kassert_panic msg;                                      \
+} while (0)
+#else /* !INVARIANTS && !_STANDALONE */
+#define        KASSERT(exp,msg) do { \
+} while (0)
+#endif /* INVARIANTS || _STANDALONE */
+
+/*
  * Helpful macros for quickly coming up with assertions with informative
  * panic messages.
  */
@@ -152,6 +164,18 @@ void       kassert_panic(const char *fmt, ...)  
__printflike
        KASSERT((ex), ("Assertion %s failed at %s:%d", what, file, line))
 
 /*
+ * Align variables.
+ */
+#define        __read_mostly           __section(".data.read_mostly")
+#define        __read_frequently       __section(".data.read_frequently")
+#define        __exclusive_cache_line  __aligned(CACHE_LINE_SIZE) \
+                                   __section(".data.exclusive_cache_line")
+#ifdef _KERNEL
+#include <sys/param.h>         /* MAXCPU */
+#include <sys/pcpu.h>          /* curthread */
+#include <sys/kpilite.h>
+
+/*
  * Assert that a pointer can be loaded from memory atomically.
  *
  * This assertion enforces stronger alignment than necessary.  For example,
@@ -181,13 +205,6 @@ void       kassert_panic(const char *fmt, ...)  
__printflike
 #define        SCHEDULER_STOPPED() SCHEDULER_STOPPED_TD(curthread)
 
 /*
- * Align variables.
- */
-#define        __read_mostly           __section(".data.read_mostly")
-#define        __read_frequently       __section(".data.read_frequently")
-#define        __exclusive_cache_line  __aligned(CACHE_LINE_SIZE) \
-                                   __section(".data.exclusive_cache_line")
-/*
  * XXX the hints declarations are even more misplaced than most declarations
  * in this file, since they are needed in one file (per arch) and only used
  * in two files.
@@ -626,6 +643,7 @@ void _gone_in_dev(struct device *dev, int major, const
 #endif
 #define gone_in(major, msg)            __gone_ok(major, msg) _gone_in(major, 
msg)
 #define gone_in_dev(dev, major, msg)   __gone_ok(major, msg) _gone_in_dev(dev, 
major, msg)
+#endif /* _KERNEL */
 
 __NULLABILITY_PRAGMA_POP
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to