git: b02908b051c8 - main - arm64, powerpc: fix calculation of 'used' in GET_STACK_USAGE

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Tue, 30 Nov 2021 15:16:19 UTC
The branch main has been updated by mhorne:

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

commit b02908b051c897117ebbc3dcb55848383b17c435
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2021-11-30 15:15:44 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2021-11-30 15:15:44 +0000

    arm64, powerpc: fix calculation of 'used' in GET_STACK_USAGE
    
    We do not consider the space reserved for the pcb to be part of the
    total kstack size, so it should not be included in the calculation of
    the used stack size.
    
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
---
 sys/arm64/include/proc.h   | 4 +---
 sys/powerpc/include/proc.h | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/sys/arm64/include/proc.h b/sys/arm64/include/proc.h
index 43200fd115fc..95485483084a 100644
--- a/sys/arm64/include/proc.h
+++ b/sys/arm64/include/proc.h
@@ -62,9 +62,7 @@ struct syscall_args {
 #define	GET_STACK_USAGE(total, used) do {				\
 	struct thread *td = curthread;					\
 	(total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb);	\
-	(used) = (char *)td->td_kstack +				\
-	    td->td_kstack_pages * PAGE_SIZE -				\
-	    (char *)&td;						\
+	(used) = td->td_kstack + (total) - (vm_offset_t)&td;		\
 } while (0)
 
 #endif
diff --git a/sys/powerpc/include/proc.h b/sys/powerpc/include/proc.h
index aac4e66b39fc..1dd52895bb9e 100644
--- a/sys/powerpc/include/proc.h
+++ b/sys/powerpc/include/proc.h
@@ -75,9 +75,7 @@ struct syscall_args {
 #define	GET_STACK_USAGE(total, used) do {				\
 	struct thread *td = curthread;					\
 	(total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb);	\
-	(used) = (char *)td->td_kstack +				\
-	    td->td_kstack_pages * PAGE_SIZE -				\
-	    (char *)&td;						\
+	(used) = td->td_kstack + (total) - (vm_offset_t)&td;		\
 } while (0)
 #endif