修复init进程忘记设定fs gs寄存器的问题。 (#132)

This commit is contained in:
login 2022-12-31 18:43:05 +08:00 committed by GitHub
parent 74bde36e01
commit 843e442971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,8 +21,8 @@
#include <exception/gate.h>
#include <filesystem/devfs/devfs.h>
#include <filesystem/fat32/fat32.h>
#include <filesystem/rootfs/rootfs.h>
#include <filesystem/procfs/procfs.h>
#include <filesystem/rootfs/rootfs.h>
#include <ktest/ktest.h>
#include <mm/slab.h>
#include <sched/sched.h>
@ -123,6 +123,18 @@ void __switch_to(struct process_control_block *prev, struct process_control_bloc
}
#pragma GCC pop_options
/**
* @brief fsgs寄存器
* fsgs的值在return的时候才会生效
* @param fs fs值
* @param gs gs值
*/
void process_switch_fsgs(uint64_t fs, uint64_t gs)
{
asm volatile("movq %0, %%fs \n\t" ::"a"(fs));
asm volatile("movq %0, %%gs \n\t" ::"a"(gs));
}
/**
* @brief
*
@ -504,6 +516,7 @@ ul initial_kernel_thread(ul arg)
current_pcb->thread->fs = USER_DS | 0x3;
barrier();
current_pcb->thread->gs = USER_DS | 0x3;
process_switch_fsgs(current_pcb->thread->fs, current_pcb->thread->gs);
// 主动放弃内核线程身份
current_pcb->flags &= (~PF_KTHREAD);