修复用户进程页表还原问题

This commit is contained in:
XIAOYI12 2024-09-08 10:03:05 +08:00
parent c372bc177a
commit 0d5299a94f
8 changed files with 30 additions and 10 deletions

View File

@ -3,6 +3,10 @@
int main(){
printf("Init service launched.\n");
exec_elf("shell.bin");
int pid = exec_elf("shell.bin");
if(pid != 0){
printf("Shell process launched [PID: %d]\n",pid);
} else printf("Cannot launch shell\n");
return 0;
}

View File

@ -79,11 +79,13 @@ int input_char_inSM() {
int i;
struct task_struct *task = get_current();
if (task->tty->is_using == false) {
} else {
do{
i = fifo8_get(task->tty->fifo);
} while (i == -1);
}
return i;
}

View File

@ -2,8 +2,8 @@
#define CRASHPOWEROS_COMMON_H
#define OS_NAME "CoolPotOS"
#define OS_VERSION "v0.3.1"
#define KERNEL_NAME "CP_Kernel-i386-0.3.1"
#define OS_VERSION "v0.3.2"
#define KERNEL_NAME "CP_Kernel-i386-0.3.2"
// b 0x211972
// b 0x20d0a6

View File

@ -74,13 +74,18 @@ int check_task(int *pid){
int check_task_usershell(int *pid){
struct task_struct *shell = found_task_pid(*pid);
while (1){
if(shell->state == TASK_DEATH){
io_sti();
screen_clear();
int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");
kernel_thread(check_task,&pid,"CPOS-CK");
break;
}
}
while (1);
return 0;
}
@ -113,7 +118,6 @@ void kernel_main(multiboot_t *multiboot) {
init_page(multiboot);
init_sched();
//proc_install();
init_keyboard();
init_pit();
@ -160,8 +164,7 @@ void kernel_main(multiboot_t *multiboot) {
vfs_change_path("apps");
klogf(user_process("init.bin","InitService") != -1,"Init service process init.\n");
//int pid = user_process("shell.bin","UserShell");
// int pid = user_process("shell.bin","UserShell");
//kernel_thread(check_task_usershell,&pid,"CTU");
// int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");

View File

@ -52,6 +52,7 @@ static void syscall_get_cd(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,u
}
static int syscall_vfs_filesize(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
io_sti();
return vfs_filesize(ebx);
}
@ -119,8 +120,8 @@ static void* syscall_sysinfo(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi
return info;
}
static int syscall_exec(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
int pid = user_process(ebx,ebx);
static uint32_t syscall_exec(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
uint32_t pid = user_process(ebx,ebx);
return pid;
}
@ -142,9 +143,11 @@ void *sycall_handlers[MAX_SYSCALLS] = {
};
typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t);
extern int can_sche; //进程调度器 0 禁用 | 1 启用
size_t syscall() {
io_cli();
// can_sche = 0;
volatile size_t eax, ebx, ecx, edx, esi, edi;
asm("mov %%eax, %0\n\t" : "=r"(eax));
asm("mov %%ebx, %0\n\t" : "=r"(ebx));
@ -157,6 +160,8 @@ size_t syscall() {
} else {
eax = -1;
}
can_sche = 1;
io_sti();
return eax;
}

View File

@ -200,6 +200,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
uint32_t size = vfs_filesize(path);
if(size == -1){
can_sche = 1;
return NULL;
}
@ -232,7 +233,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
char* ker_path = kmalloc(strlen(path) + 1);
strcpy(ker_path,path);
page_directory_t *cur_page_dir = get_current()->pgd_dir;
page_switch(page);
@ -256,6 +257,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
if(!elf32Validate(ehdr)){
printf("Unknown exec file format.\n");
kfree(ker_path);
can_sche = 1;
return NULL;
}
uint32_t main = ehdr->e_entry;
@ -276,7 +278,8 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
new_task->next = running_proc_head;
kfree(ker_path);
page_switch(kernel_directory);
page_switch(cur_page_dir);
can_sche = 1;
// 找到当前进任务队列,插入到末尾
struct task_struct *tailt = running_proc_head;

View File

@ -354,6 +354,7 @@ char *user() {
}
void setup_shell() {
asm("sti");
printf("Welcome to %s %s (CPOS Kernel i386)\n"
"\n"
" * SourceCode: https://github.com/xiaoyi1212/CoolPotOS\n"

View File

@ -318,11 +318,13 @@ void screen_clear(){
}
void putchar(char c){
/*
struct task_struct *task = get_current();
if(task != NULL){
task->tty->putchar(task->tty,c);
return;
}
*/
if(vbe_status){
vbe_putchar(c);