This source file includes following definitions.
- stash_usr_regs
- restore_usr_regs
- is_do_ss_needed
- SYSCALL_DEFINE0
- get_sigframe
- setup_rt_frame
- arc_restart_syscall
- handle_signal
- do_signal
- do_notify_resume
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 #include <linux/signal.h>
48 #include <linux/ptrace.h>
49 #include <linux/personality.h>
50 #include <linux/uaccess.h>
51 #include <linux/syscalls.h>
52 #include <linux/tracehook.h>
53 #include <linux/sched/task_stack.h>
54
55 #include <asm/ucontext.h>
56
57 struct rt_sigframe {
58 struct siginfo info;
59 struct ucontext uc;
60 #define MAGIC_SIGALTSTK 0x07302004
61 unsigned int sigret_magic;
62 };
63
64 static int
65 stash_usr_regs(struct rt_sigframe __user *sf, struct pt_regs *regs,
66 sigset_t *set)
67 {
68 int err;
69 struct user_regs_struct uregs;
70
71 uregs.scratch.bta = regs->bta;
72 uregs.scratch.lp_start = regs->lp_start;
73 uregs.scratch.lp_end = regs->lp_end;
74 uregs.scratch.lp_count = regs->lp_count;
75 uregs.scratch.status32 = regs->status32;
76 uregs.scratch.ret = regs->ret;
77 uregs.scratch.blink = regs->blink;
78 uregs.scratch.fp = regs->fp;
79 uregs.scratch.gp = regs->r26;
80 uregs.scratch.r12 = regs->r12;
81 uregs.scratch.r11 = regs->r11;
82 uregs.scratch.r10 = regs->r10;
83 uregs.scratch.r9 = regs->r9;
84 uregs.scratch.r8 = regs->r8;
85 uregs.scratch.r7 = regs->r7;
86 uregs.scratch.r6 = regs->r6;
87 uregs.scratch.r5 = regs->r5;
88 uregs.scratch.r4 = regs->r4;
89 uregs.scratch.r3 = regs->r3;
90 uregs.scratch.r2 = regs->r2;
91 uregs.scratch.r1 = regs->r1;
92 uregs.scratch.r0 = regs->r0;
93 uregs.scratch.sp = regs->sp;
94
95 err = __copy_to_user(&(sf->uc.uc_mcontext.regs.scratch), &uregs.scratch,
96 sizeof(sf->uc.uc_mcontext.regs.scratch));
97 err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(sigset_t));
98
99 return err;
100 }
101
102 static int restore_usr_regs(struct pt_regs *regs, struct rt_sigframe __user *sf)
103 {
104 sigset_t set;
105 int err;
106 struct user_regs_struct uregs;
107
108 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
109 err |= __copy_from_user(&uregs.scratch,
110 &(sf->uc.uc_mcontext.regs.scratch),
111 sizeof(sf->uc.uc_mcontext.regs.scratch));
112 if (err)
113 return err;
114
115 set_current_blocked(&set);
116 regs->bta = uregs.scratch.bta;
117 regs->lp_start = uregs.scratch.lp_start;
118 regs->lp_end = uregs.scratch.lp_end;
119 regs->lp_count = uregs.scratch.lp_count;
120 regs->status32 = uregs.scratch.status32;
121 regs->ret = uregs.scratch.ret;
122 regs->blink = uregs.scratch.blink;
123 regs->fp = uregs.scratch.fp;
124 regs->r26 = uregs.scratch.gp;
125 regs->r12 = uregs.scratch.r12;
126 regs->r11 = uregs.scratch.r11;
127 regs->r10 = uregs.scratch.r10;
128 regs->r9 = uregs.scratch.r9;
129 regs->r8 = uregs.scratch.r8;
130 regs->r7 = uregs.scratch.r7;
131 regs->r6 = uregs.scratch.r6;
132 regs->r5 = uregs.scratch.r5;
133 regs->r4 = uregs.scratch.r4;
134 regs->r3 = uregs.scratch.r3;
135 regs->r2 = uregs.scratch.r2;
136 regs->r1 = uregs.scratch.r1;
137 regs->r0 = uregs.scratch.r0;
138 regs->sp = uregs.scratch.sp;
139
140 return 0;
141 }
142
143 static inline int is_do_ss_needed(unsigned int magic)
144 {
145 if (MAGIC_SIGALTSTK == magic)
146 return 1;
147 else
148 return 0;
149 }
150
151 SYSCALL_DEFINE0(rt_sigreturn)
152 {
153 struct rt_sigframe __user *sf;
154 unsigned int magic;
155 struct pt_regs *regs = current_pt_regs();
156
157
158 current->restart_block.fn = do_no_restart_syscall;
159
160
161
162
163
164 if (regs->sp & 3)
165 goto badframe;
166
167 sf = (struct rt_sigframe __force __user *)(regs->sp);
168
169 if (!access_ok(sf, sizeof(*sf)))
170 goto badframe;
171
172 if (__get_user(magic, &sf->sigret_magic))
173 goto badframe;
174
175 if (unlikely(is_do_ss_needed(magic)))
176 if (restore_altstack(&sf->uc.uc_stack))
177 goto badframe;
178
179 if (restore_usr_regs(regs, sf))
180 goto badframe;
181
182
183 syscall_wont_restart(regs);
184
185
186
187
188
189
190
191
192 regs->status32 |= STATUS_U_MASK;
193
194 return regs->r0;
195
196 badframe:
197 force_sig(SIGSEGV);
198 return 0;
199 }
200
201
202
203
204 static inline void __user *get_sigframe(struct ksignal *ksig,
205 struct pt_regs *regs,
206 unsigned long framesize)
207 {
208 unsigned long sp = sigsp(regs->sp, ksig);
209 void __user *frame;
210
211
212
213
214
215
216 frame = (void __user *)((sp - framesize) & ~7);
217
218
219 if (!access_ok(frame, framesize))
220 frame = NULL;
221
222 return frame;
223 }
224
225 static int
226 setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
227 {
228 struct rt_sigframe __user *sf;
229 unsigned int magic = 0;
230 int err = 0;
231
232 sf = get_sigframe(ksig, regs, sizeof(struct rt_sigframe));
233 if (!sf)
234 return 1;
235
236
237
238
239
240
241
242
243 err |= stash_usr_regs(sf, regs, set);
244
245
246
247
248
249
250
251 if (unlikely(ksig->ka.sa.sa_flags & SA_SIGINFO)) {
252 err |= copy_siginfo_to_user(&sf->info, &ksig->info);
253 err |= __put_user(0, &sf->uc.uc_flags);
254 err |= __put_user(NULL, &sf->uc.uc_link);
255 err |= __save_altstack(&sf->uc.uc_stack, regs->sp);
256
257
258 regs->r1 = (unsigned long)&sf->info;
259 regs->r2 = (unsigned long)&sf->uc;
260
261
262
263
264
265 magic = MAGIC_SIGALTSTK;
266 }
267
268 err |= __put_user(magic, &sf->sigret_magic);
269 if (err)
270 return err;
271
272
273 regs->r0 = ksig->sig;
274
275
276 regs->ret = (unsigned long)ksig->ka.sa.sa_handler;
277
278
279
280
281
282 if(!(ksig->ka.sa.sa_flags & SA_RESTORER))
283 return 1;
284
285 regs->blink = (unsigned long)ksig->ka.sa.sa_restorer;
286
287
288 regs->sp = (unsigned long)sf;
289
290
291
292
293
294 regs->status32 &= ~STATUS_DE_MASK;
295 regs->status32 |= STATUS_L_MASK;
296
297 return err;
298 }
299
300 static void arc_restart_syscall(struct k_sigaction *ka, struct pt_regs *regs)
301 {
302 switch (regs->r0) {
303 case -ERESTART_RESTARTBLOCK:
304 case -ERESTARTNOHAND:
305
306
307
308
309
310
311 regs->r0 = -EINTR;
312 break;
313
314 case -ERESTARTSYS:
315
316
317
318
319
320 if (!(ka->sa.sa_flags & SA_RESTART)) {
321 regs->r0 = -EINTR;
322 break;
323 }
324
325
326 case -ERESTARTNOINTR:
327
328
329
330
331
332
333
334
335
336
337 regs->r0 = regs->orig_r0;
338 regs->ret -= is_isa_arcv2() ? 2 : 4;
339 break;
340 }
341 }
342
343
344
345
346 static void
347 handle_signal(struct ksignal *ksig, struct pt_regs *regs)
348 {
349 sigset_t *oldset = sigmask_to_save();
350 int failed;
351
352
353 failed = setup_rt_frame(ksig, oldset, regs);
354
355 signal_setup_done(failed, ksig, 0);
356 }
357
358 void do_signal(struct pt_regs *regs)
359 {
360 struct ksignal ksig;
361 int restart_scall;
362
363 restart_scall = in_syscall(regs) && syscall_restartable(regs);
364
365 if (get_signal(&ksig)) {
366 if (restart_scall) {
367 arc_restart_syscall(&ksig.ka, regs);
368 syscall_wont_restart(regs);
369 }
370 handle_signal(&ksig, regs);
371 return;
372 }
373
374 if (restart_scall) {
375
376 if (regs->r0 == -ERESTARTNOHAND ||
377 regs->r0 == -ERESTARTSYS || regs->r0 == -ERESTARTNOINTR) {
378 regs->r0 = regs->orig_r0;
379 regs->ret -= is_isa_arcv2() ? 2 : 4;
380 } else if (regs->r0 == -ERESTART_RESTARTBLOCK) {
381 regs->r8 = __NR_restart_syscall;
382 regs->ret -= is_isa_arcv2() ? 2 : 4;
383 }
384 syscall_wont_restart(regs);
385 }
386
387
388 restore_saved_sigmask();
389 }
390
391 void do_notify_resume(struct pt_regs *regs)
392 {
393
394
395
396
397 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
398 tracehook_notify_resume(regs);
399 }