-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathdo_sigaction.c
75 lines (58 loc) · 1.76 KB
/
do_sigaction.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Syscall in this file: sigaction
* Input:
*
* Return: reply_res: syscall status
*
* @author Bruce Tan
* @email brucetansh@gmail.com
*
* @author Paul Monigatti
* @email paulmoni@waikato.ac.nz
*
* @create date 2017-08-23 06:10:09
*
*/
#include <kernel/kernel.h>
int sys_sigaction(struct proc* who, int signum, struct sigaction* act, struct sigaction* oact){
if(signum < 1 || signum >= _NSIG)
return -EINVAL;
if(signum == SIGKILL || signum == SIGSTOP)
return -EINVAL;
if(act->sa_handler == SIG_IGN){
if(signum == SIGSEGV)
return -EINVAL;
sigdelset(&who->sig_pending, signum);
}
if(oact){
memcpy(oact, &who->sig_table[signum], sizeof(struct sigaction));
}
sigdelset(&act->sa_mask, SIGKILL);
sigdelset(&act->sa_mask, SIGSTOP);
memcpy(&who->sig_table[signum], act, sizeof(struct sigaction));
return 0;
}
int do_sigaction(struct proc *who, struct message *m){
int signum = m->m1_i1;
struct sigaction* act = m->m1_p1;
struct sigaction* oact = m->m1_p2;
if(!is_vaddr_accessible(act, who))
return -EFAULT;
if(oact && !is_vaddr_accessible(oact, who))
return -EFAULT;
act = (struct sigaction*)get_physical_addr(act, who);
if(oact){
oact = (struct sigaction*)get_physical_addr(oact, who);
}
return sys_sigaction(who, signum, act, oact);
}
int do_signal(struct proc* who, struct message *m){
struct sigaction sa, oldsa;
int signum = m->m1_i1;
sa.sa_handler = (sighandler_t)(unsigned long)m->m1_p1;
sa.sa_flags = SA_RESETHAND;
sa.sa_mask = 0xffff;
if(sys_sigaction(who, signum, &sa, &oldsa))
return (int)((unsigned long)SIG_ERR);
return (int)((unsigned long)oldsa.sa_handler);
}