xref: /freebsd/sys/powerpc/include/stack.h (revision 2555f175b368569dd98e1bd2b6bd095c933faed7)
13c90d1eaSRobert Watson /*-
23c90d1eaSRobert Watson  * Mach Operating System
33c90d1eaSRobert Watson  * Copyright (c) 1992 Carnegie Mellon University
43c90d1eaSRobert Watson  * All Rights Reserved.
53c90d1eaSRobert Watson  *
63c90d1eaSRobert Watson  * Permission to use, copy, modify and distribute this software and its
73c90d1eaSRobert Watson  * documentation is hereby granted, provided that both the copyright
83c90d1eaSRobert Watson  * notice and this permission notice appear in all copies of the
93c90d1eaSRobert Watson  * software, derivative works or modified versions, and any portions
103c90d1eaSRobert Watson  * thereof, and that both notices appear in supporting documentation.
113c90d1eaSRobert Watson  *
123c90d1eaSRobert Watson  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
133c90d1eaSRobert Watson  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
143c90d1eaSRobert Watson  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
153c90d1eaSRobert Watson  *
163c90d1eaSRobert Watson  * Carnegie Mellon requests users of this software to return to
173c90d1eaSRobert Watson  *
183c90d1eaSRobert Watson  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
193c90d1eaSRobert Watson  *  School of Computer Science
203c90d1eaSRobert Watson  *  Carnegie Mellon University
213c90d1eaSRobert Watson  *  Pittsburgh PA 15213-3890
223c90d1eaSRobert Watson  *
233c90d1eaSRobert Watson  * any improvements or extensions that they make and grant Carnegie Mellon
243c90d1eaSRobert Watson  * the rights to redistribute these changes.
253c90d1eaSRobert Watson  *
263c90d1eaSRobert Watson  * $FreeBSD$
273c90d1eaSRobert Watson  */
283c90d1eaSRobert Watson 
293c90d1eaSRobert Watson #ifndef _MACHINE_STACK_H_
303c90d1eaSRobert Watson #define	_MACHINE_STACK_H_
313c90d1eaSRobert Watson 
323c90d1eaSRobert Watson extern int trapexit[];
333c90d1eaSRobert Watson extern int asttrapexit[];
343c90d1eaSRobert Watson extern int end[];
353c90d1eaSRobert Watson 
36*2555f175SKonstantin Belousov #ifdef _SYS_PROC_H_
37*2555f175SKonstantin Belousov 
38*2555f175SKonstantin Belousov #include <machine/pcb.h>
39*2555f175SKonstantin Belousov 
40*2555f175SKonstantin Belousov /* Get the current kernel thread stack usage. */
41*2555f175SKonstantin Belousov #define	GET_STACK_USAGE(total, used) do {				\
42*2555f175SKonstantin Belousov 	struct thread *td = curthread;					\
43*2555f175SKonstantin Belousov 	(total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb);	\
44*2555f175SKonstantin Belousov 	(used) = td->td_kstack + (total) - (vm_offset_t)&td;		\
45*2555f175SKonstantin Belousov } while (0)
46*2555f175SKonstantin Belousov 
47*2555f175SKonstantin Belousov static __inline bool
48*2555f175SKonstantin Belousov kstack_contains(struct thread *td, vm_offset_t va, size_t len)
49*2555f175SKonstantin Belousov {
50*2555f175SKonstantin Belousov 	return (va >= td->td_kstack && va + len >= va &&
51*2555f175SKonstantin Belousov 	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE);
52*2555f175SKonstantin Belousov }
53*2555f175SKonstantin Belousov #endif	/* _SYS_PROC_H_ */
54*2555f175SKonstantin Belousov 
553c90d1eaSRobert Watson #endif /* !_MACHINE_STACK_H_ */
56