signal相关数据结构&代码结构优化 (#84)

* 解决由于spinlock.h中包含preempt_enable()带来的循环include问题

* new: 初步实现signal的数据结构
This commit is contained in:
login
2022-11-16 15:18:03 +08:00
committed by GitHub
parent fb6c29d01d
commit cffd7144fb
33 changed files with 549 additions and 281 deletions

View File

@ -1,10 +1,7 @@
#pragma once
#if ARCH(X86_64)
#include <arch/x86_64/current.h>
#else
#error Unsupported architecture!
#endif
#include <asm/current.h>
#include "proc-types.h"
/**

View File

@ -1,6 +1,7 @@
#pragma once
#include <common/wait_queue.h>
#include <DragonOS/signal.h>
// 进程最大可拥有的文件描述符数量
#define PROC_MAX_FD_NUM 16
@ -73,7 +74,7 @@ struct process_control_block
// 进程标志:进程、线程、内核线程
unsigned long flags;
int64_t preempt_count; // 持有的自旋锁的数量
long signal;
long cpu_id; // 当前进程在哪个CPU核心上运行
char name[PCB_NAME_LEN];
@ -114,6 +115,15 @@ struct process_control_block
/* PF_kTHREAD | PF_IO_WORKER 的进程worker_private不为NULL*/
void *worker_private;
// ==== 信号处理相关 =====
struct signal_struct *signal;
struct sighand_struct *sighand;
// 一个bitmap表示被阻塞的信号
sigset_t blocked;
// 正在等待的信号的标志位,表示某个信号正在等待处理
struct sigpending sig_pending;
};
// 将进程的pcb和内核栈融合到一起,8字节对齐

View File

@ -9,45 +9,27 @@
*/
#pragma once
#include <common/cpu.h>
#include <common/glib.h>
#include <syscall/syscall.h>
#include "ptrace.h"
#include <common/cpu.h>
#include <common/errno.h>
#include <filesystem/VFS/VFS.h>
#include <common/glib.h>
#include <common/wait_queue.h>
#include <filesystem/VFS/VFS.h>
#include <mm/mm-types.h>
#include <syscall/syscall.h>
#if ARCH(I386) || ARCH(X86_64)
#include <arch/x86_64/current.h>
#else
#error Unsupported architecture!
#endif
#include <asm/current.h>
#include "proc-types.h"
// 设置初始进程的PCB
#define INITIAL_PROC(proc) \
{ \
.state = PROC_UNINTERRUPTIBLE, \
.flags = PF_KTHREAD, \
.preempt_count = 0, \
.signal = 0, \
.cpu_id = 0, \
.mm = &initial_mm, \
.thread = &initial_thread, \
.addr_limit = 0xffffffffffffffff, \
.pid = 0, \
.priority = 2, \
.virtual_runtime = 0, \
.fds = {0}, \
.next_pcb = &proc, \
.parent_pcb = &proc, \
.exit_code = 0, \
.wait_child_proc_exit = 0, \
.worker_private = NULL, \
.policy = SCHED_NORMAL \
}
#define INITIAL_PROC(proc) \
{ \
.state = PROC_UNINTERRUPTIBLE, .flags = PF_KTHREAD, .preempt_count = 0, .signal = 0, .cpu_id = 0, \
.mm = &initial_mm, .thread = &initial_thread, .addr_limit = 0xffffffffffffffff, .pid = 0, .priority = 2, \
.virtual_runtime = 0, .fds = {0}, .next_pcb = &proc, .parent_pcb = &proc, .exit_code = 0, \
.wait_child_proc_exit = 0, .worker_private = NULL, .policy = SCHED_NORMAL \
}
/**
* @brief 任务状态段结构体
@ -55,28 +37,19 @@
*/
// 设置初始进程的tss
#define INITIAL_TSS \
{ \
.reserved0 = 0, \
.rsp0 = (ul)(initial_proc_union.stack + STACK_SIZE / sizeof(ul)), \
.rsp1 = (ul)(initial_proc_union.stack + STACK_SIZE / sizeof(ul)), \
.rsp2 = (ul)(initial_proc_union.stack + STACK_SIZE / sizeof(ul)), \
.reserved1 = 0, \
.ist1 = 0xffff800000007c00, \
.ist2 = 0xffff800000007c00, \
.ist3 = 0xffff800000007c00, \
.ist4 = 0xffff800000007c00, \
.ist5 = 0xffff800000007c00, \
.ist6 = 0xffff800000007c00, \
.ist7 = 0xffff800000007c00, \
.reserved2 = 0, \
.reserved3 = 0, \
.io_map_base_addr = 0 \
}
#define INITIAL_TSS \
{ \
.reserved0 = 0, .rsp0 = (ul)(initial_proc_union.stack + STACK_SIZE / sizeof(ul)), \
.rsp1 = (ul)(initial_proc_union.stack + STACK_SIZE / sizeof(ul)), \
.rsp2 = (ul)(initial_proc_union.stack + STACK_SIZE / sizeof(ul)), .reserved1 = 0, .ist1 = 0xffff800000007c00, \
.ist2 = 0xffff800000007c00, .ist3 = 0xffff800000007c00, .ist4 = 0xffff800000007c00, \
.ist5 = 0xffff800000007c00, .ist6 = 0xffff800000007c00, .ist7 = 0xffff800000007c00, .reserved2 = 0, \
.reserved3 = 0, .io_map_base_addr = 0 \
}
#define GET_CURRENT_PCB \
"movq %rsp, %rbx \n\t" \
"andq $-32768, %rbx\n\t"
#define GET_CURRENT_PCB \
"movq %rsp, %rbx \n\t" \
"andq $-32768, %rbx\n\t"
/**
* @brief 切换进程上下文
@ -84,24 +57,24 @@
* 然后调用__switch_to切换栈配置其他信息最后恢复下一个进程的rax rbp。
*/
#define switch_proc(prev, next) \
do \
{ \
__asm__ __volatile__("pushq %%rbp \n\t" \
"pushq %%rax \n\t" \
"movq %%rsp, %0 \n\t" \
"movq %2, %%rsp \n\t" \
"leaq switch_proc_ret_addr(%%rip), %%rax \n\t" \
"movq %%rax, %1 \n\t" \
"pushq %3 \n\t" \
"jmp __switch_to \n\t" \
"switch_proc_ret_addr: \n\t" \
"popq %%rax \n\t" \
"popq %%rbp \n\t" \
: "=m"(prev->thread->rsp), "=m"(prev->thread->rip) \
: "m"(next->thread->rsp), "m"(next->thread->rip), "D"(prev), "S"(next) \
: "memory"); \
} while (0)
#define switch_proc(prev, next) \
do \
{ \
__asm__ __volatile__("pushq %%rbp \n\t" \
"pushq %%rax \n\t" \
"movq %%rsp, %0 \n\t" \
"movq %2, %%rsp \n\t" \
"leaq switch_proc_ret_addr(%%rip), %%rax \n\t" \
"movq %%rax, %1 \n\t" \
"pushq %3 \n\t" \
"jmp __switch_to \n\t" \
"switch_proc_ret_addr: \n\t" \
"popq %%rax \n\t" \
"popq %%rbp \n\t" \
: "=m"(prev->thread->rsp), "=m"(prev->thread->rip) \
: "m"(next->thread->rsp), "m"(next->thread->rip), "D"(prev), "S"(next) \
: "memory"); \
} while (0)
/**
* @brief 初始化系统的第一个进程
@ -118,7 +91,8 @@ void process_init();
* @param stack_size 堆栈大小
* @return unsigned long
*/
unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned long stack_start, unsigned long stack_size);
unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned long stack_start,
unsigned long stack_size);
/**
* @brief 根据pid获取进程的pcb
@ -196,12 +170,11 @@ int process_release_pcb(struct process_control_block *pcb);
* @param next 下一个进程的pcb
*
*/
#define process_switch_mm(next_pcb) \
do \
{ \
asm volatile("movq %0, %%cr3 \n\t" ::"r"(next_pcb->mm->pgd) \
: "memory"); \
} while (0)
#define process_switch_mm(next_pcb) \
do \
{ \
asm volatile("movq %0, %%cr3 \n\t" ::"r"(next_pcb->mm->pgd) : "memory"); \
} while (0)
// flush_tlb();
// 获取当前cpu id