signal的发送(暂时父子进程之间共享信号及相应的结构体) (#89)

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

* new: 初步实现signal的数据结构

* new:signal相关数据结构

* fix: 解决bindings.rs报一堆警告的问题

* new: rust下的kdebug kinfo kwarn kBUG kerror宏

* 移动asm.h和cmpxchg.h

* new: signal的发送(暂时只支持父子进程共享信号及处理函数)
This commit is contained in:
login
2022-11-23 11:38:20 +08:00
committed by GitHub
parent 3d729e2069
commit 66f67c6a95
44 changed files with 1677 additions and 472 deletions

View File

@ -4,6 +4,7 @@
#include <libc/dirent.h>
#include <libc/errno.h>
#include <libc/fcntl.h>
#include <libc/include/signal.h>
#include <libc/stddef.h>
#include <libc/stdio.h>
#include <libc/stdlib.h>
@ -23,7 +24,7 @@ struct built_in_cmd_t shell_cmds[] = {
{"cd", shell_cmd_cd}, {"cat", shell_cmd_cat}, {"exec", shell_cmd_exec}, {"ls", shell_cmd_ls},
{"mkdir", shell_cmd_mkdir}, {"pwd", shell_cmd_pwd}, {"rm", shell_cmd_rm}, {"rmdir", shell_cmd_rmdir},
{"reboot", shell_cmd_reboot}, {"touch", shell_cmd_touch}, {"about", shell_cmd_about}, {"free", shell_cmd_free},
{"help", shell_help}, {"pipe", shell_pipe_test},
{"help", shell_help}, {"pipe", shell_pipe_test}, {"kill", shell_cmd_kill},
};
// 总共的内建命令数量
@ -331,11 +332,14 @@ int shell_cmd_touch(int argc, char **argv)
{
int path_len = 0;
char *file_path;
bool alloc_full_path=false;
bool alloc_full_path = false;
if (argv[1][0] == '/')
file_path = argv[1];
else
{file_path = get_target_filepath(argv[1], &path_len);alloc_full_path=true;}
{
file_path = get_target_filepath(argv[1], &path_len);
alloc_full_path = true;
}
// 打开文件
int fd = open(file_path, O_CREAT);
@ -351,7 +355,7 @@ int shell_cmd_touch(int argc, char **argv)
close(fd);
if (argv != NULL)
free(argv);
if(alloc_full_path)
if (alloc_full_path)
free(file_path);
return 0;
}
@ -425,7 +429,7 @@ int shell_cmd_rmdir(int argc, char **argv)
*/
int shell_cmd_rm(int argc, char **argv)
{
char *full_path = NULL;
char *full_path = NULL;
int result_path_len = -1;
int retval = 0;
bool alloc_full_path = false;
@ -472,7 +476,7 @@ int shell_cmd_exec(int argc, char **argv)
execv(file_path, argv);
free(argv);
free(file_path);
exit(-1);
}
else
@ -498,7 +502,24 @@ int shell_cmd_about(int argc, char **argv)
parse_command(input_buffer, &aac, &aav);
shell_cmd_exec(aac, aav);
return shell_cmd_exec(aac, aav);
}
int shell_cmd_kill(int argc, char **argv)
{
int retval = 0;
if (argc < 2)
{
printf("Usage: Kill <pid>\n");
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);
return retval;
}
/**

View File

@ -149,4 +149,6 @@ int shell_cmd_free(int argc, char **argv);
* @param argv 返回值:参数列表
* @return int
*/
int parse_command(char *buf, int *argc, char ***argv);
int parse_command(char *buf, int *argc, char ***argv);
int shell_cmd_kill(int argc, char **argv);

View File

@ -0,0 +1,40 @@
#pragma once
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGIO 29
#define SIGPOLL SIGIO
#define SIGPWR 30
#define SIGSYS 31
/* These should not be considered constants from userland. */
#define SIGRTMIN 32
#define SIGRTMAX MAX_SIG_NUM

View File

@ -28,6 +28,7 @@
#define SYS_MSTAT 21 // 获取系统的内存状态信息
#define SYS_UNLINK_AT 22 // 删除文件夹/删除文件链接
#define SYS_KILL 23 // kill一个进程(向这个进程发出信号)
/**
* @brief 用户态系统调用函数