Merge branch 'linus' into perf/urgent, to synchronize UAPI headers
[linux-2.6-microblaze.git] / drivers / staging / lustre / lnet / libcfs / linux / linux-prim.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * GPL HEADER START
4  *
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 only,
9  * as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License version 2 for more details (a copy is included
15  * in the LICENSE file that accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License
18  * version 2 along with this program; If not, see
19  * http://www.gnu.org/licenses/gpl-2.0.html
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25  * Use is subject to license terms.
26  *
27  * Copyright (c) 2011, 2012, Intel Corporation.
28  */
29 /*
30  * This file is part of Lustre, http://www.lustre.org/
31  * Lustre is a trademark of Sun Microsystems, Inc.
32  */
33
34 #define DEBUG_SUBSYSTEM S_LNET
35 #include <linux/module.h>
36 #include <linux/kernel.h>
37 #include <linux/fs_struct.h>
38 #include <linux/sched/signal.h>
39
40 #include <linux/libcfs/libcfs.h>
41
42 #if defined(CONFIG_KGDB)
43 #include <linux/kgdb.h>
44 #endif
45
46 sigset_t
47 cfs_block_allsigs(void)
48 {
49         unsigned long flags;
50         sigset_t old;
51
52         spin_lock_irqsave(&current->sighand->siglock, flags);
53         old = current->blocked;
54         sigfillset(&current->blocked);
55         recalc_sigpending();
56         spin_unlock_irqrestore(&current->sighand->siglock, flags);
57
58         return old;
59 }
60 EXPORT_SYMBOL(cfs_block_allsigs);
61
62 sigset_t cfs_block_sigs(unsigned long sigs)
63 {
64         unsigned long flags;
65         sigset_t old;
66
67         spin_lock_irqsave(&current->sighand->siglock, flags);
68         old = current->blocked;
69         sigaddsetmask(&current->blocked, sigs);
70         recalc_sigpending();
71         spin_unlock_irqrestore(&current->sighand->siglock, flags);
72         return old;
73 }
74 EXPORT_SYMBOL(cfs_block_sigs);
75
76 /* Block all signals except for the @sigs */
77 sigset_t cfs_block_sigsinv(unsigned long sigs)
78 {
79         unsigned long flags;
80         sigset_t old;
81
82         spin_lock_irqsave(&current->sighand->siglock, flags);
83         old = current->blocked;
84         sigaddsetmask(&current->blocked, ~sigs);
85         recalc_sigpending();
86         spin_unlock_irqrestore(&current->sighand->siglock, flags);
87
88         return old;
89 }
90 EXPORT_SYMBOL(cfs_block_sigsinv);
91
92 void
93 cfs_restore_sigs(sigset_t old)
94 {
95         unsigned long flags;
96
97         spin_lock_irqsave(&current->sighand->siglock, flags);
98         current->blocked = old;
99         recalc_sigpending();
100         spin_unlock_irqrestore(&current->sighand->siglock, flags);
101 }
102 EXPORT_SYMBOL(cfs_restore_sigs);
103
104 void
105 cfs_clear_sigpending(void)
106 {
107         unsigned long flags;
108
109         spin_lock_irqsave(&current->sighand->siglock, flags);
110         clear_tsk_thread_flag(current, TIF_SIGPENDING);
111         spin_unlock_irqrestore(&current->sighand->siglock, flags);
112 }
113 EXPORT_SYMBOL(cfs_clear_sigpending);