diff --git a/sys/amd64/include/proc.h b/sys/amd64/include/proc.h index 6181df35261e..8015fe5da81a 100644 --- a/sys/amd64/include/proc.h +++ b/sys/amd64/include/proc.h @@ -97,15 +97,6 @@ struct mdproc { #ifdef _KERNEL -/* 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; \ -} while (0) - struct proc_ldt *user_ldt_alloc(struct proc *, int); void user_ldt_free(struct thread *); struct sysarch_args; diff --git a/sys/amd64/include/stack.h b/sys/amd64/include/stack.h index 091ae33893d4..ff21ee28b5a3 100644 --- a/sys/amd64/include/stack.h +++ b/sys/amd64/include/stack.h @@ -3,4 +3,28 @@ */ /* $FreeBSD$ */ +#ifndef _MACHINE_STACK_H_ +#define _MACHINE_STACK_H_ + #include + +#ifdef _SYS_PROC_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; \ +} while (0) + +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); +} +#endif /* _SYS_PROC_H_ */ + +#endif diff --git a/sys/arm/arm/ptrace_machdep.c b/sys/arm/arm/ptrace_machdep.c index 3edadbd72ddf..a347a1dfac95 100644 --- a/sys/arm/arm/ptrace_machdep.c +++ b/sys/arm/arm/ptrace_machdep.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef VFP #include #endif diff --git a/sys/arm/include/proc.h b/sys/arm/include/proc.h index 76b05b335420..9db28358cc39 100644 --- a/sys/arm/include/proc.h +++ b/sys/arm/include/proc.h @@ -56,15 +56,4 @@ struct mdproc { #define KINFO_PROC_SIZE 816 -#ifdef _KERNEL -#include - -/* 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 - sizeof(struct pcb); \ - (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ -} while (0) - -#endif /* _KERNEL */ #endif /* !_MACHINE_PROC_H_ */ diff --git a/sys/arm/include/stack.h b/sys/arm/include/stack.h index 4bc384f775bc..e8d130517be5 100644 --- a/sys/arm/include/stack.h +++ b/sys/arm/include/stack.h @@ -63,6 +63,25 @@ struct linker_file; void unwind_module_loaded(struct linker_file *); void unwind_module_unloaded(struct linker_file *); +#ifdef _SYS_PROC_H_ + +#include + +/* 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 - sizeof(struct pcb); \ + (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ +} while (0) + +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); +} +#endif /* _SYS_PROC_H_ */ + #endif #endif /* !_MACHINE_STACK_H_ */ diff --git a/sys/arm64/arm64/debug_monitor.c b/sys/arm64/arm64/debug_monitor.c index 2ec76c9a2f33..52bcf1e5e603 100644 --- a/sys/arm64/arm64/debug_monitor.c +++ b/sys/arm64/arm64/debug_monitor.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef DDB #include diff --git a/sys/arm64/arm64/elf32_machdep.c b/sys/arm64/arm64/elf32_machdep.c index 627973ecfd3d..7b346ed81b2c 100644 --- a/sys/arm64/arm64/elf32_machdep.c +++ b/sys/arm64/arm64/elf32_machdep.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #ifdef VFP #include #endif diff --git a/sys/arm64/arm64/freebsd32_machdep.c b/sys/arm64/arm64/freebsd32_machdep.c index 9b62802efbc5..5fadef74df87 100644 --- a/sys/arm64/arm64/freebsd32_machdep.c +++ b/sys/arm64/arm64/freebsd32_machdep.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef VFP #include #endif diff --git a/sys/arm64/arm64/ptrace_machdep.c b/sys/arm64/arm64/ptrace_machdep.c index 01135978b39a..079391ac102c 100644 --- a/sys/arm64/arm64/ptrace_machdep.c +++ b/sys/arm64/arm64/ptrace_machdep.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include /* Only used to get/set 32bits VFP regs */ int diff --git a/sys/arm64/include/proc.h b/sys/arm64/include/proc.h index 15361a0e3788..9a22fe43833a 100644 --- a/sys/arm64/include/proc.h +++ b/sys/arm64/include/proc.h @@ -72,16 +72,4 @@ struct mdproc { #define KINFO_PROC_SIZE 1088 #define KINFO_PROC32_SIZE 816 -#ifdef _KERNEL - -#include - -#define GET_STACK_USAGE(total, used) do { \ - struct thread *td = curthread; \ - (total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb); \ - (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ -} while (0) - -#endif - #endif /* !_MACHINE_PROC_H_ */ diff --git a/sys/arm64/include/stack.h b/sys/arm64/include/stack.h index 4b1d190df595..4c4c41bf9516 100644 --- a/sys/arm64/include/stack.h +++ b/sys/arm64/include/stack.h @@ -39,4 +39,22 @@ struct unwind_state { bool unwind_frame(struct thread *, struct unwind_state *); +#ifdef _SYS_PROC_H_ + +#include + +#define GET_STACK_USAGE(total, used) do { \ + struct thread *td = curthread; \ + (total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb); \ + (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ +} while (0) + +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); +} +#endif /* _SYS_PROC_H_ */ + #endif /* !_MACHINE_STACK_H_ */ diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c index 41ac2912be29..9a82dc94b6ac 100644 --- a/sys/arm64/linux/linux_sysvec.c +++ b/sys/arm64/linux/linux_sysvec.c @@ -71,7 +71,7 @@ __FBSDID("$FreeBSD$"); #include #include - +#include #ifdef VFP #include #endif diff --git a/sys/ddb/db_ps.c b/sys/ddb/db_ps.c index a5245528ca83..5d713264d975 100644 --- a/sys/ddb/db_ps.c +++ b/sys/ddb/db_ps.c @@ -49,6 +49,8 @@ __FBSDID("$FreeBSD$"); #include +#include + #define PRINT_NONE 0 #define PRINT_ARGS 1 diff --git a/sys/geom/geom_io.c b/sys/geom/geom_io.c index 20e31b9b921b..777f698b6f1f 100644 --- a/sys/geom/geom_io.c +++ b/sys/geom/geom_io.c @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/i386/include/proc.h b/sys/i386/include/proc.h index 7affe60edab9..d693500f2c3e 100644 --- a/sys/i386/include/proc.h +++ b/sys/i386/include/proc.h @@ -66,13 +66,6 @@ struct mdproc { #include -/* Get the current kernel thread stack usage. */ -#define GET_STACK_USAGE(total, used) do { \ - struct thread *td = curthread; \ - (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 *); struct proc_ldt *user_ldt_alloc(struct mdproc *, int); void user_ldt_free(struct thread *); diff --git a/sys/i386/include/stack.h b/sys/i386/include/stack.h index 091ae33893d4..773aca1c66d9 100644 --- a/sys/i386/include/stack.h +++ b/sys/i386/include/stack.h @@ -3,4 +3,27 @@ */ /* $FreeBSD$ */ +#ifndef _MACHINE_STACK_H_ +#define _MACHINE_STACK_H_ + #include + +#ifdef _SYS_PROC_H_ + +/* Get the current kernel thread stack usage. */ +#define GET_STACK_USAGE(total, used) do { \ + struct thread *td = curthread; \ + (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) + +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); +} + +#endif /* _SYS_PROC_H_ */ + +#endif diff --git a/sys/kern/subr_epoch.c b/sys/kern/subr_epoch.c index 98a560e44c9d..2a0144412399 100644 --- a/sys/kern/subr_epoch.c +++ b/sys/kern/subr_epoch.c @@ -56,6 +56,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #ifdef __amd64__ diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index 092231850f18..205b6041053b 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -66,6 +66,8 @@ #include #include +#include + #include #include diff --git a/sys/powerpc/include/proc.h b/sys/powerpc/include/proc.h index 2c6a00536b8a..0f8d36bfe856 100644 --- a/sys/powerpc/include/proc.h +++ b/sys/powerpc/include/proc.h @@ -59,16 +59,4 @@ struct mdproc { #define KINFO_PROC_SIZE 816 #endif -#ifdef _KERNEL - -#include - -/* 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 - sizeof(struct pcb); \ - (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ -} while (0) -#endif - #endif /* !_MACHINE_PROC_H_ */ diff --git a/sys/powerpc/include/stack.h b/sys/powerpc/include/stack.h index c433a9fe09eb..953afd6f0aa4 100644 --- a/sys/powerpc/include/stack.h +++ b/sys/powerpc/include/stack.h @@ -33,4 +33,23 @@ extern int trapexit[]; extern int asttrapexit[]; extern int end[]; +#ifdef _SYS_PROC_H_ + +#include + +/* 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 - sizeof(struct pcb); \ + (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ +} while (0) + +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); +} +#endif /* _SYS_PROC_H_ */ + #endif /* !_MACHINE_STACK_H_ */ diff --git a/sys/riscv/include/proc.h b/sys/riscv/include/proc.h index 648c529f4322..ce0a62675308 100644 --- a/sys/riscv/include/proc.h +++ b/sys/riscv/include/proc.h @@ -45,15 +45,4 @@ struct mdproc { #define KINFO_PROC_SIZE 1088 -#ifdef _KERNEL -#include - -/* 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 - sizeof(struct pcb); \ - (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ -} while (0) - -#endif /* _KERNEL */ #endif /* !_MACHINE_PROC_H_ */ diff --git a/sys/riscv/include/stack.h b/sys/riscv/include/stack.h index 82f851096d7b..566081c3ebd0 100644 --- a/sys/riscv/include/stack.h +++ b/sys/riscv/include/stack.h @@ -48,4 +48,23 @@ struct unwind_state { bool unwind_frame(struct thread *, struct unwind_state *); +#ifdef _SYS_PROC_H_ + +#include + +/* 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 - sizeof(struct pcb); \ + (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ +} while (0) + +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); +} +#endif /* _SYS_PROC_H_ */ + #endif /* !_MACHINE_STACK_H_ */ diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 2da5d8edee6d..2ad4505405c8 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1324,13 +1324,6 @@ curthread_pflags2_restore(int save) curthread->td_pflags2 &= save; } -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); -} - static __inline __pure2 struct td_sched * td_get_sched(struct thread *td) { diff --git a/sys/x86/x86/stack_machdep.c b/sys/x86/x86/stack_machdep.c index 1243137d2ea0..5d7dfd251b0d 100644 --- a/sys/x86/x86/stack_machdep.c +++ b/sys/x86/x86/stack_machdep.c @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #ifdef __i386__ #define PCB_FP(pcb) ((pcb)->pcb_ebp)