From 8d98f3084e71a3269491358ba51a8f1a24815412 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 9 Nov 2020 18:03:26 +0100
Subject: [PATCH 1/2] WIP __dead2 for the kernel

---
 sys/ddb/ddb.h                           | 2 +-
 sys/dev/drm/include/linux/rbtree.h      | 2 +-
 sys/dev/netif/ath/ath_hal/ah_internal.h | 2 +-
 sys/dev/netif/ath/ath_hal/ah_osdep.c    | 2 +-
 sys/dev/raid/aac/aacvar.h               | 2 +-
 sys/libkern/stack_protector.c           | 5 ++++-
 sys/net/ipfw3_basic/ip_fw3_sync.h       | 2 +-
 sys/net/pf/pfvar.h                      | 2 +-
 sys/netproto/smb/smb_subr.h             | 2 +-
 sys/platform/pc64/include/md_var.h      | 2 +-
 sys/platform/pc64/include/pcb_ext.h     | 6 +++---
 sys/platform/pc64/x86_64/trap.c         | 2 +-
 sys/platform/pc64/x86_64/vm_machdep.c   | 2 +-
 sys/platform/vkernel64/include/md_var.h | 2 +-
 sys/sys/systm.h                         | 4 ++--
 sys/sys/taskqueue.h                     | 2 +-
 16 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/sys/ddb/ddb.h b/sys/ddb/ddb.h
index d7d4b881ea..95d8473c84 100644
--- a/sys/ddb/ddb.h
+++ b/sys/ddb/ddb.h
@@ -92,7 +92,7 @@ void		db_check_interrupt (void);
 void		db_clear_watchpoints (void);
 db_addr_t	db_disasm (db_addr_t loc, boolean_t altfmt, db_regs_t *regs);
 				/* instruction disassembler */
-void		db_error (char *s);
+void		db_error (char *s) __dead2;
 int		db_expression (db_expr_t *valuep);
 int		db_get_variable (db_expr_t *valuep);
 void		db_iprintf (const char *,...) __printflike(1, 2);
diff --git a/sys/dev/drm/include/linux/rbtree.h b/sys/dev/drm/include/linux/rbtree.h
index 4d94509a17..2d42178895 100644
--- a/sys/dev/drm/include/linux/rbtree.h
+++ b/sys/dev/drm/include/linux/rbtree.h
@@ -54,7 +54,7 @@ struct rb_root {
 /*
  * In linux all of the comparisons are done by the caller.
  */
-int panic_cmp(struct rb_node *one, struct rb_node *two);
+int panic_cmp(struct rb_node *one, struct rb_node *two) __dead2;
 
 RB_HEAD(linux_root, rb_node);
 RB_PROTOTYPE(linux_root, rb_node, __entry, panic_cmp);
diff --git a/sys/dev/netif/ath/ath_hal/ah_internal.h b/sys/dev/netif/ath/ath_hal/ah_internal.h
index f0638c8d0a..4824a48317 100644
--- a/sys/dev/netif/ath/ath_hal/ah_internal.h
+++ b/sys/dev/netif/ath/ath_hal/ah_internal.h
@@ -664,7 +664,7 @@ extern	void DO_HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...)
  */
 #ifdef AH_ASSERT
 extern	void ath_hal_assert_failed(const char* filename,
-		int lineno, const char* msg);
+		int lineno, const char* msg) __dead2;
 
 #define	HALASSERT(_x) do {					\
 	if (!(_x)) {						\
diff --git a/sys/dev/netif/ath/ath_hal/ah_osdep.c b/sys/dev/netif/ath/ath_hal/ah_osdep.c
index 55dc4d96bf..3205ed836a 100644
--- a/sys/dev/netif/ath/ath_hal/ah_osdep.c
+++ b/sys/dev/netif/ath/ath_hal/ah_osdep.c
@@ -97,7 +97,7 @@ extern	void *ath_hal_malloc(size_t);
 extern	void ath_hal_free(void *);
 #ifdef AH_ASSERT
 extern	void ath_hal_assert_failed(const char* filename,
-		int lineno, const char* msg);
+		int lineno, const char* msg) __dead2;
 #endif
 #ifdef AH_DEBUG
 extern	void DO_HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...)
diff --git a/sys/dev/raid/aac/aacvar.h b/sys/dev/raid/aac/aacvar.h
index 298541281b..425cf11509 100644
--- a/sys/dev/raid/aac/aacvar.h
+++ b/sys/dev/raid/aac/aacvar.h
@@ -487,7 +487,7 @@ do {									\
 } while(0)
 
 extern void	aac_print_queues(struct aac_softc *sc);
-extern void	aac_panic(struct aac_softc *sc, char *reason);
+extern void	aac_panic(struct aac_softc *sc, char *reason) __dead2;
 extern void	aac_print_fib(struct aac_softc *sc, struct aac_fib *fib,
 			      const char *caller);
 extern void	aac_print_aif(struct aac_softc *sc,
diff --git a/sys/libkern/stack_protector.c b/sys/libkern/stack_protector.c
index ada08b1b87..5bffb0f100 100644
--- a/sys/libkern/stack_protector.c
+++ b/sys/libkern/stack_protector.c
@@ -28,9 +28,12 @@
 #include <sys/endian.h>
 #ifndef _KERNEL
 extern void panic(const char *, ...);
+#define	ATTRIBUTE_NORETURN
+#else
+#define	ATTRIBUTE_NORETURN	__dead2
 #endif
 
-void __stack_smash_handler(char[], int);
+void __stack_smash_handler(char[], int) ATTRIBUTE_NORETURN;
 
 #if BYTE_ORDER == LITTLE_ENDIAN
 int __guard = 0x00000aff;
diff --git a/sys/net/ipfw3_basic/ip_fw3_sync.h b/sys/net/ipfw3_basic/ip_fw3_sync.h
index eb5fa4d95f..83fdafd767 100644
--- a/sys/net/ipfw3_basic/ip_fw3_sync.h
+++ b/sys/net/ipfw3_basic/ip_fw3_sync.h
@@ -120,7 +120,7 @@ int 	ip_fw3_ctl_sync_centre_conf(struct sockopt *sopt);
 int 	ip_fw3_ctl_sync_show_conf(struct sockopt *sopt);
 int 	ip_fw3_ctl_sync_show_status(struct sockopt *sopt);
 int 	ip_fw3_ctl_sync_edge_conf(struct sockopt *sopt);
-void 	ip_fw3_sync_edge_socket_handler(void *dummy);
+void 	ip_fw3_sync_edge_socket_handler(void *dummy) __dead2;
 int 	ip_fw3_ctl_sync_edge_start(struct sockopt *sopt);
 int 	ip_fw3_ctl_sync_edge_test(struct sockopt *sopt);
 int 	ip_fw3_ctl_sync_centre_start(struct sockopt *sopt);
diff --git a/sys/net/pf/pfvar.h b/sys/net/pf/pfvar.h
index f09d9faabd..65d0bc08f5 100644
--- a/sys/net/pf/pfvar.h
+++ b/sys/net/pf/pfvar.h
@@ -1793,7 +1793,7 @@ extern struct malloc_type	*pfr_kentry_pl2;
 extern struct malloc_type	*pf_cache_pl, *pf_cent_pl;
 extern struct malloc_type	*pf_state_scrub_pl;
 extern struct malloc_type	*pfi_addr_pl;
-extern void			 pf_purge_thread(void *);
+extern void			 pf_purge_thread(void *) __dead2;
 extern int			 pf_purge_expired_src_nodes(int);
 extern int			 pf_purge_expired_states(u_int32_t, int);
 extern void			 pf_unlink_state(struct pf_state *);
diff --git a/sys/netproto/smb/smb_subr.h b/sys/netproto/smb/smb_subr.h
index ba22cdde8e..c92344affa 100644
--- a/sys/netproto/smb/smb_subr.h
+++ b/sys/netproto/smb/smb_subr.h
@@ -138,7 +138,7 @@ int  smb_rq_verify(struct smb_rq *rqp);
 int smb_kthread_create(void (*func)(void *), void *arg,
 	struct proc **newpp, int flags, const char *fmt, ...)
 	__printflike(5, 6);
-void smb_kthread_exit(void);
+void smb_kthread_exit(void) __dead2;
 int smb_sleep(void *chan, struct smb_slock *sl, int slpflags, const char *wmesg, int timo);
 
 
diff --git a/sys/platform/pc64/include/md_var.h b/sys/platform/pc64/include/md_var.h
index e3a77b85a4..565f888863 100644
--- a/sys/platform/pc64/include/md_var.h
+++ b/sys/platform/pc64/include/md_var.h
@@ -44,7 +44,6 @@
 extern	u_long	atdevbase;	/* offset in virtual memory of ISA io mem */
 extern	int	busdma_swi_pending;
 extern	void	(*cpu_idle_hook)(void);
-void		cpu_idle(void);
 extern	u_int	cpu_exthigh;
 extern	u_int	via_feature_rng;
 extern	u_int	via_feature_xcrypt;
@@ -83,6 +82,7 @@ struct dumperinfo;
 
 void	busdma_swi(void);
 void	cpu_gdinit (struct mdglobaldata *gd, int cpu);
+void	cpu_idle(void) __dead2;
 void	cpu_idle_restore (void);	/* cannot be called from C */
 void	cpu_setregs(void);
 void	doreti_iret(void) __asm(__STRING(doreti_iret));
diff --git a/sys/platform/pc64/include/pcb_ext.h b/sys/platform/pc64/include/pcb_ext.h
index 70621187e0..2e4a39d404 100644
--- a/sys/platform/pc64/include/pcb_ext.h
+++ b/sys/platform/pc64/include/pcb_ext.h
@@ -59,9 +59,9 @@ struct pcb_ldt {
 
 struct pcb;
 
-void set_user_ldt (struct pcb *);
-struct pcb_ldt *user_ldt_alloc (struct pcb *, int);
-void user_ldt_free (struct pcb *);
+void set_user_ldt(struct pcb *) __dead2;
+struct pcb_ldt *user_ldt_alloc(struct pcb *, int) __dead2;
+void user_ldt_free(struct pcb *);
 
 #endif
 
diff --git a/sys/platform/pc64/x86_64/trap.c b/sys/platform/pc64/x86_64/trap.c
index 6e0973904a..d0fa1aa8c1 100644
--- a/sys/platform/pc64/x86_64/trap.c
+++ b/sys/platform/pc64/x86_64/trap.c
@@ -100,7 +100,7 @@ extern void trap(struct trapframe *frame);
 
 static int trap_pfault(struct trapframe *, int);
 static void trap_fatal(struct trapframe *, vm_offset_t);
-void dblfault_handler(struct trapframe *frame);
+void dblfault_handler(struct trapframe *frame) __dead2;
 
 #define MAX_TRAP_MSG		30
 static char *trap_msg[] = {
diff --git a/sys/platform/pc64/x86_64/vm_machdep.c b/sys/platform/pc64/x86_64/vm_machdep.c
index 19b01697b8..3cfc0c856d 100644
--- a/sys/platform/pc64/x86_64/vm_machdep.c
+++ b/sys/platform/pc64/x86_64/vm_machdep.c
@@ -78,7 +78,7 @@
 
 #include <bus/isa/isa.h>
 
-static void	cpu_reset_real (void);
+static void	cpu_reset_real(void) __dead2;
 
 static int spectre_mitigation = -1;
 static int spectre_support = 0;
diff --git a/sys/platform/vkernel64/include/md_var.h b/sys/platform/vkernel64/include/md_var.h
index ecb57ac4f0..2ef8aa4994 100644
--- a/sys/platform/vkernel64/include/md_var.h
+++ b/sys/platform/vkernel64/include/md_var.h
@@ -103,7 +103,7 @@ void cpu_idle_restore(void);    /* cannot be called from C */
 void cpu_kthread_restore(void);	/* cannot be called from C */
 thread_t cpu_exit_switch (struct thread *next);
 void cpu_setregs (void);
-void cpu_idle (void);
+void cpu_idle (void) __dead2;
 void cpu_mask_all_signals (void);
 void cpu_unmask_all_signals (void);
 void go_user (struct intrframe *frame);
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 91f56ab350..c264d00920 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -178,7 +178,7 @@ int	cpu_sanitize_tls (struct savetls *);
 void	cpu_spinlock_contested(void);
 void	cpu_halt (void) __dead2;
 void	cpu_idle_halt (void);
-void	cpu_reset (void);
+void	cpu_reset (void) __dead2;
 void	cpu_boot (int);
 void	cpu_rootconf (void);
 void	cpu_vmspace_alloc(struct vmspace *);
@@ -347,7 +347,7 @@ extern char *kern_envp;
 #include <sys/libkern.h>
 
 /* Initialize the world */
-void	mi_startup (void);
+void	mi_startup (void) __dead2;
 void	nchinit (void);
 
 /* Finalize the world. */
diff --git a/sys/sys/taskqueue.h b/sys/sys/taskqueue.h
index 3788de3a7f..10e4fb9ec0 100644
--- a/sys/sys/taskqueue.h
+++ b/sys/sys/taskqueue.h
@@ -105,7 +105,7 @@ void	taskqueue_unblock(struct taskqueue *queue);
 /*
  * Functions for dedicated thread taskqueues
  */
-void	taskqueue_thread_loop(void *arg);
+void	taskqueue_thread_loop(void *arg) __dead2;
 void	taskqueue_thread_enqueue(void *context);
 
 /*
-- 
2.28.0

