git: 83a49712afa2 - main - kstack_contains(): account for struct pcb on stack

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 01 Feb 2023 23:41:36 UTC
The branch main has been updated by kib:

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

commit 83a49712afa276b7f320e0dd669c8dfd33f9a5ac
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-01-31 23:49:54 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-02-01 22:59:27 +0000

    kstack_contains(): account for struct pcb on stack
    
    for arm64, arm, powerpc, and riscv
    
    Reviewed by:    jhb
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D38320
---
 sys/arm/include/stack.h     | 3 ++-
 sys/arm64/include/stack.h   | 3 ++-
 sys/powerpc/include/stack.h | 3 ++-
 sys/riscv/include/stack.h   | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/sys/arm/include/stack.h b/sys/arm/include/stack.h
index e8d130517be5..748ef35a444e 100644
--- a/sys/arm/include/stack.h
+++ b/sys/arm/include/stack.h
@@ -78,7 +78,8 @@ static __inline bool
 kstack_contains(struct thread *td, vm_offset_t va, size_t len)
 {
 	return (va >= td->td_kstack && va + len >= va &&
-	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE);
+	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
+	    sizeof(struct pcb));
 }
 #endif	/* _SYS_PROC_H_ */
 
diff --git a/sys/arm64/include/stack.h b/sys/arm64/include/stack.h
index 4c4c41bf9516..58fb2cf0e8a5 100644
--- a/sys/arm64/include/stack.h
+++ b/sys/arm64/include/stack.h
@@ -53,7 +53,8 @@ static __inline bool
 kstack_contains(struct thread *td, vm_offset_t va, size_t len)
 {
 	return (va >= td->td_kstack && va + len >= va &&
-	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE);
+	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
+	    sizeof(struct pcb));
 }
 #endif	/* _SYS_PROC_H_ */
 
diff --git a/sys/powerpc/include/stack.h b/sys/powerpc/include/stack.h
index 953afd6f0aa4..53ea0fc3bc54 100644
--- a/sys/powerpc/include/stack.h
+++ b/sys/powerpc/include/stack.h
@@ -48,7 +48,8 @@ static __inline bool
 kstack_contains(struct thread *td, vm_offset_t va, size_t len)
 {
 	return (va >= td->td_kstack && va + len >= va &&
-	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE);
+	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
+	    sizeof(struct pcb));
 }
 #endif	/* _SYS_PROC_H_ */
 
diff --git a/sys/riscv/include/stack.h b/sys/riscv/include/stack.h
index 566081c3ebd0..1f6907742b6a 100644
--- a/sys/riscv/include/stack.h
+++ b/sys/riscv/include/stack.h
@@ -63,7 +63,8 @@ static __inline bool
 kstack_contains(struct thread *td, vm_offset_t va, size_t len)
 {
 	return (va >= td->td_kstack && va + len >= va &&
-	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE);
+	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
+	    sizeof(struct pcb));
 }
 #endif	/* _SYS_PROC_H_ */