-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsigaction.c
151 lines (129 loc) · 2.62 KB
/
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef mini_sigaction_c
#define mini_sigaction_c
//+header signal.h
//+include
//+inline
static int sigemptyset(sigset_t *set){
#ifdef X64
set->sig=0;
#else
set->sig[0]=0;
if ((8/sizeof(long)) > 1)
set->sig[1]=0;
#endif
return 0;
}
#if 1
//+inline
static int sigfillset(sigset_t *set){
#ifdef X64
set->sig=0x7FFFFFFF; // doesn't work. ?
#else
#error implemented only for X64
// set->sig[0]=0x1FFFFFFF;
// if ((8/sizeof(long)) > 1)
// set->sig[1]=0;
#endif
return 0;
}
#endif
//+def
int sigaddset(sigset_t *set, int sig){
unsigned s = sig-1;
if (sig >= _NSIG-1 || sig <0 ) {
#ifdef mini_errno
errno = EINVAL;
#endif
return -1;
}
#ifdef X64
set->sig |= (1<<s);
#else
#error implemented only for X64
#endif
return(0);
}
#ifdef mini_sigsuspend
//+depends rt_sigsuspend
//+def
static int sigsuspend( const sigset_t *mask ){
return( rt_sigsuspend( mask, sizeof(sigset_t) ) );
}
#endif
#ifdef mini_sigprocmask
//+depends rt_sigprocmask
//+def
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset){
return( rt_sigprocmask( how, (sigset_t*)set, oldset, sizeof(sigset_t) ) );
}
#endif
//+def
int sigdelset(sigset_t *set, int sig){
unsigned s = sig-1;
if (sig >= _NSIG-1 || sig <0 ) {
#ifdef mini_errno
errno = EINVAL;
#endif
return -1;
}
#ifdef X64
set->sig &= ~(1<<s);
#else
#error implemented only for X64
#endif
return(0);
}
//+def
int sigismember(sigset_t *set, int sig){
unsigned s = sig-1;
if (sig >= _NSIG-1 || sig <0 ) {
#ifdef mini_errno
errno = EINVAL;
#endif
return -1;
}
#ifdef X64
return( set->sig & (1<<s) );
#else
#error implemented only for X64
return(-1);
#endif
}
#ifdef mini_sigaction
extern void _sigrestore();
__asm__ ( "\
.global _sigrestore\n\
_sigrestore:\n\
mov $15,%rax\n\
syscall");
//+header signal.h
//+include
//+depends memcpy rt_sigaction
//+def
static int volatile sigaction(int sig, const struct sigaction *act, struct sigaction *oact){
struct sigaction sa;
//memcpy(&sa,act,sizeof(sigaction));
#ifdef X64
sa.sa_mask.sig=act->sa_mask.sig;
#else
sa.sa_mask.sig[0]=act->sa_mask.sig[0];
if ((8/sizeof(long)) > 1)
sa.sa_mask.sig[1]=act->sa_mask.sig[1];
#endif
sa.sa_handler=act->sa_handler;
sa.sa_flags = act->sa_flags | SA_RESTORER;
sa.restorer = &_sigrestore;
return( rt_sigaction( sig, &sa, oact, sizeof(sigset_t) ) );
}
#endif
// memo: needs static definition, cause the +include
// (meaning, including the definition into the header.
// What is the right thing to do for a wrapper call.)
#ifdef mini_raise
//+depends getpid kill
//+def
static inline int raise(int signr){
return(kill(getpid(),signr));
}
#endif
#endif