day10-内核实验项目概述与内核信号

1.在系统中什么是信号,都有什么信号

2.在系统接收到信号后,他是如何处理的

3.信号作用

信号处理流程:

_system_call:

          call _sys_call_table(,%eax,4)

                sys_signal

 sys_signal

int sys_signal(int signum, long handler, long restorer)
{
    //分配一个信号结构体
	struct sigaction tmp;
    //确定信号的范围
	if (signum<1 || signum>32 || signum==SIGKILL)
		return -1;
    //指定信号处理句柄
	tmp.sa_handler = (void (*)(int)) handler;
    //设置屏蔽码
	tmp.sa_mask = 0;
    //将该信号设置为执行一次就恢复
	tmp.sa_flags = SA_ONESHOT | SA_NOMASK;
    //保存回复函数指针
	tmp.sa_restorer = (void (*)(void)) restorer;
	handler = (long) current->sigaction[signum-1].sa_handler;
	current->sigaction[signum-1] = tmp;
	return handler;
}

do_signal函数

void do_signal(long signr,long eax, long ebx, long ecx, long edx,
	long fs, long es, long ds,
	long eip, long cs, long eflags,
	unsigned long * esp, long ss)
{
	unsigned long sa_handler;
	long old_eip=eip;
	struct sigaction * sa = current->sigaction + signr - 1;
	int longs;
	unsigned long * tmp_esp;

	sa_handler = (unsigned long) sa->sa_handler;

	/*
		mark #define SIG_DFL		((void (*)(int))0)	default signal handling 
		mark #define SIG_IGN		((void (*)(int))1)	ignore signal
	*/
	if (sa_handler==1)
		return;
	if (!sa_handler) {
		if (signr==SIGCHLD)
			return;
		else
			do_exit(1<<(signr-1));
	}
	if (sa->sa_flags & SA_ONESHOT)
		sa->sa_handler = NULL;
	*(&eip) = sa_handler;
	longs = (sa->sa_flags & SA_NOMASK)?7:8;
	*(&esp) -= longs;
	verify_area(esp,longs*4);
	tmp_esp=esp;
	put_fs_long((long) sa->sa_restorer,tmp_esp++);
	put_fs_long(signr,tmp_esp++);
	if (!(sa->sa_flags & SA_NOMASK))
		put_fs_long(current->blocked,tmp_esp++);
	put_fs_long(eax,tmp_esp++);
	put_fs_long(ecx,tmp_esp++);
	put_fs_long(edx,tmp_esp++);
	put_fs_long(eflags,tmp_esp++);
	put_fs_long(old_eip,tmp_esp++);
	current->blocked |= sa->sa_mask;
}

主要作用:

day10-内核实验项目概述与内核信号_第1张图片

你可能感兴趣的:(linux内核,java,前端,linux)