| 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 | |
| 27 | #ifndef _MACHINE_STACK_H_ |
| 28 | #define	_MACHINE_STACK_H_ |
| 29 | |
| 30 | extern int trapexit[]; |
| 31 | extern int asttrapexit[]; |
| 32 | extern int end[]; |
| 33 | |
| 34 | #ifdef _SYS_PROC_H_ |
| 35 | |
| 36 | #include <machine/pcb.h> |
| 37 | |
| 38 | /* Get the current kernel thread stack usage. */ |
| 39 | #define	GET_STACK_USAGE(total, used) do {				\ |
| 40 | 	struct thread *td = curthread;					\ |
| 41 | 	(total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb);	\ |
| 42 | 	(used) = td->td_kstack + (total) - (vm_offset_t)&td;		\ |
| 43 | } while (0) |
| 44 | |
| 45 | static __inline bool |
| 46 | kstack_contains(struct thread *td, vm_offset_t va, size_t len) |
| 47 | { |
| 48 | 	return (va >= td->td_kstack && va + len >= va && |
| 49 | 	 va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE - |
| 50 | 	 sizeof(struct pcb)); |
| 51 | } |
| 52 | #endif	/* _SYS_PROC_H_ */ |
| 53 | |
| 54 | #endif /* !_MACHINE_STACK_H_ */ |