Move kstack_contains() and GET_STACK_USAGE() to MD machine/stack.h

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38320
This commit is contained in:
Konstantin Belousov 2023-02-01 00:47:40 +02:00
parent 6cc52efa13
commit 2555f175b3
24 changed files with 136 additions and 71 deletions

View File

@ -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;

View File

@ -3,4 +3,28 @@
*/
/* $FreeBSD$ */
#ifndef _MACHINE_STACK_H_
#define _MACHINE_STACK_H_
#include <x86/stack.h>
#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

View File

@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/ptrace.h>
#include <sys/reg.h>
#include <machine/pcb.h>
#ifdef VFP
#include <machine/vfp.h>
#endif

View File

@ -56,15 +56,4 @@ struct mdproc {
#define KINFO_PROC_SIZE 816
#ifdef _KERNEL
#include <machine/pcb.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 - sizeof(struct pcb); \
(used) = td->td_kstack + (total) - (vm_offset_t)&td; \
} while (0)
#endif /* _KERNEL */
#endif /* !_MACHINE_PROC_H_ */

View File

@ -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 <machine/pcb.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 - 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_ */

View File

@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <machine/cpu.h>
#include <machine/debug_monitor.h>
#include <machine/kdb.h>
#include <machine/pcb.h>
#ifdef DDB
#include <ddb/ddb.h>

View File

@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include <sys/vnode.h>
#include <machine/elf.h>
#include <machine/pcb.h>
#ifdef VFP
#include <machine/vfp.h>
#endif

View File

@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <machine/armreg.h>
#include <machine/pcb.h>
#ifdef VFP
#include <machine/vfp.h>
#endif

View File

@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <sys/ucontext.h>
#include <machine/armreg.h>
#include <machine/pcb.h>
/* Only used to get/set 32bits VFP regs */
int

View File

@ -72,16 +72,4 @@ struct mdproc {
#define KINFO_PROC_SIZE 1088
#define KINFO_PROC32_SIZE 816
#ifdef _KERNEL
#include <machine/pcb.h>
#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_ */

View File

@ -39,4 +39,22 @@ struct unwind_state {
bool unwind_frame(struct thread *, struct unwind_state *);
#ifdef _SYS_PROC_H_
#include <machine/pcb.h>
#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_ */

View File

@ -71,7 +71,7 @@ __FBSDID("$FreeBSD$");
#include <arm64/linux/linux_sigframe.h>
#include <machine/md_var.h>
#include <machine/pcb.h>
#ifdef VFP
#include <machine/vfp.h>
#endif

View File

@ -49,6 +49,8 @@ __FBSDID("$FreeBSD$");
#include <ddb/ddb.h>
#include <machine/stack.h>
#define PRINT_NONE 0
#define PRINT_ARGS 1

View File

@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
#include <sys/stack.h>
#include <sys/sysctl.h>
#include <sys/vmem.h>
#include <machine/stack.h>
#include <machine/stdarg.h>
#include <sys/errno.h>

View File

@ -66,13 +66,6 @@ struct mdproc {
#include <machine/md_var.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)
void set_user_ldt(struct mdproc *);
struct proc_ldt *user_ldt_alloc(struct mdproc *, int);
void user_ldt_free(struct thread *);

View File

@ -3,4 +3,27 @@
*/
/* $FreeBSD$ */
#ifndef _MACHINE_STACK_H_
#define _MACHINE_STACK_H_
#include <x86/stack.h>
#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

View File

@ -56,6 +56,8 @@ __FBSDID("$FreeBSD$");
#include <vm/vm_kern.h>
#include <vm/uma.h>
#include <machine/stack.h>
#include <ck_epoch.h>
#ifdef __amd64__

View File

@ -66,6 +66,8 @@
#include <machine/cpu.h>
#include <vm/uma.h>
#include <machine/stack.h>
#include <net/netisr.h>
#include <net/vnet.h>

View File

@ -59,16 +59,4 @@ struct mdproc {
#define KINFO_PROC_SIZE 816
#endif
#ifdef _KERNEL
#include <machine/pcb.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 - sizeof(struct pcb); \
(used) = td->td_kstack + (total) - (vm_offset_t)&td; \
} while (0)
#endif
#endif /* !_MACHINE_PROC_H_ */

View File

@ -33,4 +33,23 @@ extern int trapexit[];
extern int asttrapexit[];
extern int end[];
#ifdef _SYS_PROC_H_
#include <machine/pcb.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 - 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_ */

View File

@ -45,15 +45,4 @@ struct mdproc {
#define KINFO_PROC_SIZE 1088
#ifdef _KERNEL
#include <machine/pcb.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 - sizeof(struct pcb); \
(used) = td->td_kstack + (total) - (vm_offset_t)&td; \
} while (0)
#endif /* _KERNEL */
#endif /* !_MACHINE_PROC_H_ */

View File

@ -48,4 +48,23 @@ struct unwind_state {
bool unwind_frame(struct thread *, struct unwind_state *);
#ifdef _SYS_PROC_H_
#include <machine/pcb.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 - 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_ */

View File

@ -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)
{

View File

@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$");
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <x86/stack.h>
#include <machine/stack.h>
#ifdef __i386__
#define PCB_FP(pcb) ((pcb)->pcb_ebp)