signal的处理(kill命令)以及一些其他的改进 (#100)

* 将entry.S中冗余的ret_from_syscall代码删除,改为jmp Restore_all

* new: 增加判断pt_regs是否来自用户态的函数

* new: rust的cli和sti封装

* 将原有的判断pt_regs是否来自用户态的代码,统一改为调用user_mode函数

* ffz函数:获取u64中的第一个值为0的bit

* spinlock增加 spinlock irq spin_unlock_irq

* 临时解决显示刷新线程迟迟不运行的问题

* 更改ffi_convert的生命周期标签

* new: 测试signal用的app

* 解决由于编译器优化导致local_irq_restore无法获取到正确的rflags的值的问题

* new: exec命令增加"&"后台运行选项

* procfs->status增加显示preempt和虚拟运行时间

* 更改引用计数的FFIBind2Rust trait中的生命周期标签

* new: signal处理(kill)

* 更正在review中发现的一些细节问题
This commit is contained in:
login
2022-12-08 22:59:51 +08:00
committed by GitHub
parent f8b55f6d3f
commit 1a2eaa402f
30 changed files with 1002 additions and 192 deletions

View File

@ -1,5 +1,5 @@
user_apps_sub_dirs=shell about
user_apps_sub_dirs=shell about test_signal
ECHO:
@echo "$@"

View File

@ -467,7 +467,7 @@ int shell_cmd_exec(int argc, char **argv)
if (pid == 0)
{
// printf("child proc\n");
// 子进程
int path_len = 0;
char *file_path = get_target_filepath(argv[1], &path_len);
@ -480,10 +480,13 @@ int shell_cmd_exec(int argc, char **argv)
}
else
{
// printf("parent process wait for pid:[ %d ]\n", pid);
waitpid(pid, &retval, 0);
// printf("parent process wait pid [ %d ], exit code=%d\n", pid, retval);
// 如果不指定后台运行,则等待退出
if (strcmp(argv[argc - 1], "&") != 0)
waitpid(pid, &retval, 0);
else{
// 输出子进程的pid
printf("[1] %d\n", pid);
}
free(argv);
}
}
@ -513,8 +516,6 @@ int shell_cmd_kill(int argc, char **argv)
retval = -EINVAL;
goto out;
}
printf("argc = %d, argv[1]=%s\n", argc, argv[1]);
printf("atoi(argv[1])=%d\n", atoi(argv[1]));
retval = syscall_invoke(SYS_KILL, atoi(argv[1]), SIGKILL, 0, 0, 0, 0, 0, 0);
out:;
free(argv);

View File

@ -0,0 +1,7 @@
all: main.o
ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/test_signal $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T link.lds
objcopy -I elf64-x86-64 -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/test_signal $(output_dir)/test_signal.elf
main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o

View File

@ -0,0 +1,50 @@
OUTPUT_FORMAT("elf64-x86-64","elf64-x86-64","elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SECTIONS
{
. = 0x800000;
.text :
{
_text = .;
*(.text)
_etext = .;
}
. = ALIGN(8);
.data :
{
_data = .;
*(.data)
_edata = .;
}
rodata_start_pa = .;
.rodata :
{
_rodata = .;
*(.rodata)
_erodata = .;
}
.bss :
{
_bss = .;
*(.bss)
_ebss = .;
}
_end = .;
}

View File

@ -0,0 +1,38 @@
/**
* @file main.c
* @author longjin (longjin@RinGoTek.cn)
* @brief 测试signal用的程序
* @version 0.1
* @date 2022-12-06
*
* @copyright Copyright (c) 2022
*
*/
/**
* 测试signal的kill命令的方法:
* 1.在DragonOS的控制台输入 exec bin/test_signal.elf &
* 请注意,一定要输入末尾的 '&',否则进程不会后台运行
* 2.然后kill对应的进程的pid (上一条命令执行后,将会输出这样一行:"[1] 生成的pid")
*
*/
#include <libc/math.h>
#include <libc/stdio.h>
#include <libc/stdlib.h>
#include <libc/time.h>
#include <libc/unistd.h>
int main()
{
printf("Test signal running...\n");
clock_t last = clock();
while (1)
{
if ((clock()-last)/CLOCKS_PER_SEC >= 1){
// printf("Test signal running\n");
last = clock();
}
}
return 0;
}