2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
7 #include "linux/sched.h"
8 #include "asm/pgalloc.h"
9 #include "asm/pgtable.h"
10 #include "as-layout.h"
14 extern int __syscall_stub_start
;
16 static int init_stub_pte(struct mm_struct
*mm
, unsigned long proc
,
24 pgd
= pgd_offset(mm
, proc
);
25 pud
= pud_alloc(mm
, pgd
, proc
);
29 pmd
= pmd_alloc(mm
, pud
, proc
);
33 pte
= pte_alloc_map(mm
, pmd
, proc
);
37 *pte
= mk_pte(virt_to_page(kernel
), __pgprot(_PAGE_PRESENT
));
38 *pte
= pte_mkread(*pte
);
49 int init_new_context(struct task_struct
*task
, struct mm_struct
*mm
)
51 struct mm_context
*from_mm
= NULL
;
52 struct mm_context
*to_mm
= &mm
->context
;
53 unsigned long stack
= 0;
56 if (skas_needs_stub
) {
57 stack
= get_zeroed_page(GFP_KERNEL
);
62 to_mm
->id
.stack
= stack
;
63 if (current
->mm
!= NULL
&& current
->mm
!= &init_mm
)
64 from_mm
= ¤t
->mm
->context
;
69 printk(KERN_ERR
"init_new_context_skas - "
70 "new_mm failed, errno = %d\n", ret
);
73 to_mm
->id
.u
.mm_fd
= ret
;
77 to_mm
->id
.u
.pid
= copy_context_skas0(stack
,
79 else to_mm
->id
.u
.pid
= start_userspace(stack
);
81 if (to_mm
->id
.u
.pid
< 0) {
82 ret
= to_mm
->id
.u
.pid
;
87 ret
= init_new_ldt(to_mm
, from_mm
);
89 printk(KERN_ERR
"init_new_context_skas - init_ldt"
90 " failed, errno = %d\n", ret
);
94 to_mm
->stub_pages
= NULL
;
99 if (to_mm
->id
.stack
!= 0)
100 free_page(to_mm
->id
.stack
);
105 void arch_dup_mmap(struct mm_struct
*oldmm
, struct mm_struct
*mm
)
110 if (!skas_needs_stub
)
113 ret
= init_stub_pte(mm
, STUB_CODE
,
114 (unsigned long) &__syscall_stub_start
);
118 ret
= init_stub_pte(mm
, STUB_DATA
, mm
->context
.id
.stack
);
122 pages
= kmalloc(2 * sizeof(struct page
*), GFP_KERNEL
);
124 printk(KERN_ERR
"arch_dup_mmap failed to allocate 2 page "
129 pages
[0] = virt_to_page(&__syscall_stub_start
);
130 pages
[1] = virt_to_page(mm
->context
.id
.stack
);
131 mm
->context
.stub_pages
= pages
;
133 /* dup_mmap already holds mmap_sem */
134 err
= install_special_mapping(mm
, STUB_START
, STUB_END
- STUB_START
,
135 VM_READ
| VM_MAYREAD
| VM_EXEC
|
136 VM_MAYEXEC
| VM_DONTCOPY
, pages
);
138 printk(KERN_ERR
"install_special_mapping returned %d\n", err
);
146 force_sigsegv(SIGSEGV
, current
);
149 void arch_exit_mmap(struct mm_struct
*mm
)
153 if (mm
->context
.stub_pages
!= NULL
)
154 kfree(mm
->context
.stub_pages
);
155 pte
= virt_to_pte(mm
, STUB_CODE
);
157 pte_clear(mm
, STUB_CODE
, pte
);
159 pte
= virt_to_pte(mm
, STUB_DATA
);
163 pte_clear(mm
, STUB_DATA
, pte
);
166 void destroy_context(struct mm_struct
*mm
)
168 struct mm_context
*mmu
= &mm
->context
;
171 os_close_file(mmu
->id
.u
.mm_fd
);
174 * If init_new_context wasn't called, this will be
175 * zero, resulting in a kill(0), which will result in the
176 * whole UML suddenly dying. Also, cover negative and
177 * 1 cases, since they shouldn't happen either.
179 if (mmu
->id
.u
.pid
< 2) {
180 printk(KERN_ERR
"corrupt mm_context - pid = %d\n",
184 os_kill_ptraced_process(mmu
->id
.u
.pid
, 1);
188 free_page(mmu
->id
.stack
);