2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
6 #include "linux/config.h"
7 #include "linux/sched.h"
8 #include "linux/list.h"
9 #include "linux/spinlock.h"
10 #include "linux/slab.h"
11 #include "linux/errno.h"
13 #include "asm/current.h"
14 #include "asm/segment.h"
16 #include "asm/pgalloc.h"
17 #include "asm/pgtable.h"
21 extern int __syscall_stub_start;
23 static int init_stub_pte(struct mm_struct *mm, unsigned long proc,
31 spin_lock(&mm->page_table_lock);
32 pgd = pgd_offset(mm, proc);
33 pud = pud_alloc(mm, pgd, proc);
37 pmd = pmd_alloc(mm, pud, proc);
41 pte = pte_alloc_map(mm, pmd, proc);
45 /* There's an interaction between the skas0 stub pages, stack
46 * randomization, and the BUG at the end of exit_mmap. exit_mmap
47 * checks that the number of page tables freed is the same as had
48 * been allocated. If the stack is on the last page table page,
49 * then the stack pte page will be freed, and if not, it won't. To
50 * avoid having to know where the stack is, or if the process mapped
51 * something at the top of its address space for some other reason,
52 * we set TASK_SIZE to end at the start of the last page table.
53 * This keeps exit_mmap off the last page, but introduces a leak
54 * of that page. So, we hang onto it here and free it in
55 * destroy_context_skas.
58 mm->context.skas.last_page_table = pmd_page_kernel(*pmd);
60 *pte = mk_pte(virt_to_page(kernel), __pgprot(_PAGE_PRESENT));
61 *pte = pte_mkexec(*pte);
62 *pte = pte_wrprotect(*pte);
63 spin_unlock(&mm->page_table_lock);
71 spin_unlock(&mm->page_table_lock);
75 int init_new_context_skas(struct task_struct *task, struct mm_struct *mm)
77 struct mm_struct *cur_mm = current->mm;
78 struct mm_id *cur_mm_id = &cur_mm->context.skas.id;
79 struct mm_id *mm_id = &mm->context.skas.id;
84 if((cur_mm != NULL) && (cur_mm != &init_mm))
85 from = cur_mm->context.skas.id.u.mm_fd;
90 printk("init_new_context_skas - new_mm failed, "
97 /* This zeros the entry that pgd_alloc didn't, needed since
98 * we are about to reinitialize it, and want mm.nr_ptes to
101 mm->pgd[USER_PTRS_PER_PGD] = __pgd(0);
103 ret = init_stub_pte(mm, CONFIG_STUB_CODE,
104 (unsigned long) &__syscall_stub_start);
109 stack = get_zeroed_page(GFP_KERNEL);
112 mm_id->stack = stack;
114 ret = init_stub_pte(mm, CONFIG_STUB_DATA, stack);
120 if((cur_mm != NULL) && (cur_mm != &init_mm))
121 mm_id->u.pid = copy_context_skas0(stack,
123 else mm_id->u.pid = start_userspace(stack);
129 free_page(mm_id->stack);
134 void destroy_context_skas(struct mm_struct *mm)
136 struct mmu_context_skas *mmu = &mm->context.skas;
139 os_close_file(mmu->id.u.mm_fd);
141 os_kill_ptraced_process(mmu->id.u.pid, 1);
142 free_page(mmu->id.stack);
143 free_page(mmu->last_page_table);