1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2020 Loongson Technology Corporation Limited
4 * Authors: Hanlu Li <lihanlu@loongson.cn>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11 #include <linux/syscalls.h>
12
13 typedef struct {
14 uint32_t sig[2];
15 } latx_sigset_t;
16
17 typedef uint32_t latx_size_t;
18
latx_sig_setmask(sigset_t * blocked,old_sigset_t set)19 static inline void latx_sig_setmask(sigset_t *blocked, old_sigset_t set)
20 {
21 memcpy(blocked->sig, &set, sizeof(set));
22 }
23
24 /* This is for latx-i386 */
SYSCALL_DEFINE4(latx_rt_sigprocmask,int,how,latx_sigset_t __user *,nset,latx_sigset_t __user *,oset,latx_size_t,sigsetsize)25 SYSCALL_DEFINE4(latx_rt_sigprocmask, int, how, latx_sigset_t __user *, nset,
26 latx_sigset_t __user *, oset, latx_size_t, sigsetsize)
27 {
28 old_sigset_t old_set, new_set;
29 sigset_t new_blocked;
30
31 /* XXX: Don't preclude handling different sized sigset_t's. */
32 if (sigsetsize != sizeof(latx_sigset_t))
33 return -EINVAL;
34
35 old_set = current->blocked.sig[0];
36
37 if (nset) {
38 if (copy_from_user(&new_set, nset, sizeof(latx_sigset_t)))
39 return -EFAULT;
40 new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP));
41
42 new_blocked = current->blocked;
43
44 switch (how) {
45 case SIG_BLOCK:
46 sigaddsetmask(&new_blocked, new_set);
47 break;
48 case SIG_UNBLOCK:
49 sigdelsetmask(&new_blocked, new_set);
50 break;
51 case SIG_SETMASK:
52 latx_sig_setmask(&new_blocked, new_set);
53 break;
54 default:
55 return -EINVAL;
56 }
57 set_current_blocked(&new_blocked);
58
59 if (copy_to_user(nset, &(current->blocked),
60 sizeof(latx_sigset_t)))
61 return -EFAULT;
62 }
63
64 if (oset) {
65 if (copy_to_user(oset, &old_set, sizeof(latx_sigset_t)))
66 return -EFAULT;
67 }
68
69 return 0;
70 }
71