xref: /freebsd/sys/powerpc/include/stack.h (revision 37c8ee8847faa53432809cae2ecc11b80c4eab2f)
1 /*-
2  * Mach Operating System
3  * Copyright (c) 1992 Carnegie Mellon University
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify and distribute this software and its
7  * documentation is hereby granted, provided that both the copyright
8  * notice and this permission notice appear in all copies of the
9  * software, derivative works or modified versions, and any portions
10  * thereof, and that both notices appear in supporting documentation.
11  *
12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15  *
16  * Carnegie Mellon requests users of this software to return to
17  *
18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
19  *  School of Computer Science
20  *  Carnegie Mellon University
21  *  Pittsburgh PA 15213-3890
22  *
23  * any improvements or extensions that they make and grant Carnegie Mellon
24  * the rights to redistribute these changes.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _MACHINE_STACK_H_
30 #define	_MACHINE_STACK_H_
31 
32 extern int trapexit[];
33 extern int asttrapexit[];
34 extern int end[];
35 
36 #ifdef _SYS_PROC_H_
37 
38 #include <machine/pcb.h>
39 
40 /* Get the current kernel thread stack usage. */
41 #define	GET_STACK_USAGE(total, used) do {				\
42 	struct thread *td = curthread;					\
43 	(total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb);	\
44 	(used) = td->td_kstack + (total) - (vm_offset_t)&td;		\
45 } while (0)
46 
47 static __inline bool
48 kstack_contains(struct thread *td, vm_offset_t va, size_t len)
49 {
50 	return (va >= td->td_kstack && va + len >= va &&
51 	    va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
52 	    sizeof(struct pcb));
53 }
54 #endif	/* _SYS_PROC_H_ */
55 
56 #endif /* !_MACHINE_STACK_H_ */
57