git: 2bb54c1646c7 - stable/12 - i386: take pcb and fpu area into account in GET_STACK_USAGE

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Tue, 07 Dec 2021 18:19:37 UTC
The branch stable/12 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=2bb54c1646c7f28460d18a21289587523ac6aef9

commit 2bb54c1646c7f28460d18a21289587523ac6aef9
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2021-11-25 15:54:33 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2021-12-07 18:15:58 +0000

    i386: take pcb and fpu area into account in GET_STACK_USAGE
    
    On this platform, the pcb and FPU save area are allocated from the top
    of each kernel stack, so they should be excluded from the calculation of
    the total and used stack sizes.
    
    Reviewed by:    kib
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D32581
    
    (cherry picked from commit 8bc792b3845ecf64145fda7964a7b5cc54dea777)
---
 sys/i386/include/proc.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sys/i386/include/proc.h b/sys/i386/include/proc.h
index 71b199603f51..f7b5db555c29 100644
--- a/sys/i386/include/proc.h
+++ b/sys/i386/include/proc.h
@@ -71,13 +71,13 @@ struct syscall_args {
 
 #ifdef	_KERNEL
 
+#include <machine/md_var.h>
+
 /* Get the current kernel thread stack usage. */
 #define GET_STACK_USAGE(total, used) do {				\
 	struct thread	*td = curthread;				\
-	(total) = td->td_kstack_pages * PAGE_SIZE;			\
-	(used) = (char *)td->td_kstack +				\
-	    td->td_kstack_pages * PAGE_SIZE -				\
-	    (char *)&td;						\
+	(total) = (vm_offset_t)get_pcb_td(td) - td->td_kstack;		\
+	(used) = (vm_offset_t)get_pcb_td(td) - (vm_offset_t)&td;	\
 } while (0)
 
 void 	set_user_ldt(struct mdproc *);