- Enable kernel stack guard page.

- Unmap the unused kernel stack page that we cannot use because it is
  not aligned on a (PAGE_SIZE * 2) boundary.
This commit is contained in:
neel 2010-03-12 07:08:20 +00:00
parent 4bb7c695aa
commit 68a0cae516
2 changed files with 23 additions and 8 deletions

View File

@ -128,14 +128,13 @@
#define MAXDUMPPGS 1 /* xxx: why is this only one? */
/*
* NOTE: In FreeBSD, Uarea's don't have a fixed address.
* Therefore, any code imported from OpenBSD which depends on
* UADDR, UVPN and KERNELSTACK requires porting.
* XXX: 3 stack pages? Not 4 which would be more efficient from a tlb
* XXX: point of view.
* The kernel stack needs to be aligned on a (PAGE_SIZE * 2) boundary.
*
* Although we allocate 3 pages for the kernel stack we end up using
* only the 2 pages that are aligned on a (PAGE_SIZE * 2) boundary.
*/
#define KSTACK_PAGES 3 /* kernel stack*/
#define KSTACK_GUARD_PAGES 0 /* pages of kstack guard; 0 disables */
#define KSTACK_GUARD_PAGES 1 /* pages of kstack guard; 0 disables */
#define UPAGES 2

View File

@ -214,6 +214,16 @@ cpu_thread_swapin(struct thread *td)
{
pt_entry_t *pte;
int i;
vm_offset_t unused_kstack_page;
/*
* Unmap the unused kstack page.
*/
unused_kstack_page = td->td_kstack;
if (td->td_md.md_realstack == td->td_kstack)
unused_kstack_page += (KSTACK_PAGES - 1) * PAGE_SIZE;
pmap_kremove(unused_kstack_page);
/*
* The kstack may be at a different physical address now.
@ -239,13 +249,19 @@ cpu_thread_swapout(struct thread *td)
void
cpu_thread_alloc(struct thread *td)
{
vm_offset_t unused_kstack_page;
pt_entry_t *pte;
int i;
if(td->td_kstack & (1 << PAGE_SHIFT))
if (td->td_kstack & (1 << PAGE_SHIFT)) {
td->td_md.md_realstack = td->td_kstack + PAGE_SIZE;
else
unused_kstack_page = td->td_kstack;
} else {
td->td_md.md_realstack = td->td_kstack;
unused_kstack_page = td->td_kstack +
(KSTACK_PAGES - 1) * PAGE_SIZE;
}
pmap_kremove(unused_kstack_page);
td->td_pcb = (struct pcb *)(td->td_md.md_realstack +
(td->td_kstack_pages - 1) * PAGE_SIZE) - 1;