Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

回收线程时,先释放了PCB的物理页面,然后再回收pid(还会用到PCB物理页面中的内容),这应该会导致PAGE FAULT,实际上并没有产生 #13

Open
Ares-bit opened this issue Dec 7, 2024 · 1 comment

Comments

@Ares-bit
Copy link

Ares-bit commented Dec 7, 2024

No description provided.

@Ares-bit
Copy link
Author

Ares-bit commented Dec 7, 2024

问题已解决,原因为刷TLB时,使用m约束传递vaddr,这会导致invlpg指令实际上刷的是vaddr变量在栈上存储的地址,并非把vaddr本身当做地址去刷TLB,需要修改内联汇编。

具体原理请见:https://stackoverflow.com/questions/79251944/why-this-wont-cause-page-fault/79256771#79256771

static void page_table_pte_remove(uint32_t vaddr)
{
uint32_t* pte = pte_ptr(vaddr);
*pte &= ~PG_P_1;
//asm volatile("invlpg %0" : : "m"(vaddr) : "memory");//这种并未真正刷TLB,不会产生page fault
//asm volatile("invlpg %0" : : "m"(*(char *)vaddr) : "memory");//解决方法1,修改后不要忘了将thread_exit中释放pid放到释放PCB之前,否则会出现PAGE FAULT
asm volatile("invlpg (%0)" : : "r"(vaddr) : "memory");//解决方法2,修改后不要忘了将thread_exit中释放pid放到释放PCB之前,否则会出现PAGE FAULT
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant