release the resources of the process at exit(2)/exit_group(2).

This commit is contained in:
NAKAMURA Gou
2013-05-28 10:49:33 +09:00
parent 9354c82ee7
commit fa1be382c7
8 changed files with 140 additions and 27 deletions

View File

@ -4,8 +4,14 @@
(X86_CPU_LOCAL_OFFSET_TSS + X86_TSS_OFFSET_SP0)
.text
.globl ihk_mc_switch_context
ihk_mc_switch_context:
/*
* rdi - ihk_mc_kernel_context_t *old_ctx
* rsi - ihk_mc_kernel_context_t *new_ctx
* rdx - void *prev
*/
pushfq
popq %rax
testq %rdi, %rdi
@ -35,4 +41,5 @@ ihk_mc_switch_context:
popfq
movq 8(%rsi), %rbp
movq 24(%rsi), %rsi
movq %rdx,%rax
retq

View File

@ -42,6 +42,12 @@
#define PT_ENTRIES 512
/* mask of the physical address of the entry to the page table */
#define PT_PHYSMASK (((1UL << 52) - 1) & PAGE_MASK)
#define PF_PRESENT 0x01 /* entry is valid */
#define PF_SIZE 0x80 /* entry points large page */
#define PFL4_PRESENT 0x01
#define PFL4_WRITABLE 0x02
#define PFL4_USER 0x04

View File

@ -557,6 +557,50 @@ struct page_table *ihk_mc_pt_create(void)
return pt;
}
static void destroy_page_table(int level, struct page_table *pt)
{
int ix;
unsigned long entry;
struct page_table *lower;
if ((level < 1) || (4 < level)) {
panic("destroy_page_table: level is out of range");
}
if (pt == NULL) {
panic("destroy_page_table: pt is NULL");
}
if (level > 1) {
for (ix = 0; ix < PT_ENTRIES; ++ix) {
entry = pt->entry[ix];
if (!(entry & PF_PRESENT)) {
/* entry is not valid */
continue;
}
if (entry & PF_SIZE) {
/* not a page table */
continue;
}
lower = (struct page_table *)phys_to_virt(entry & PT_PHYSMASK);
destroy_page_table(level-1, lower);
}
}
arch_free_page(pt);
return;
}
void ihk_mc_pt_destroy(struct page_table *pt)
{
const int level = 4; /* PML4 */
/* clear shared entry */
memset(pt->entry + PT_ENTRIES / 2, 0, sizeof(pt->entry[0]) * PT_ENTRIES / 2);
destroy_page_table(level, pt);
return;
}
int ihk_mc_pt_clear_page(page_table_t pt, void *virt)
{
return __clear_pt_page(pt, virt, 0);