1 /*
2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #ifndef OS_POSIX_SIGNALS_POSIX_HPP
26 #define OS_POSIX_SIGNALS_POSIX_HPP
27 
28 #include "memory/allocation.hpp"
29 #include "utilities/globalDefinitions.hpp"
30 
31 class outputStream;
32 class Thread;
33 class OSThread;
34 
35 class PosixSignals : public AllStatic {
36 
37 public:
38 
39   // Signal number used to suspend/resume a thread
40   static int SR_signum;
41 
42   static int init();
43   // The platform dependent parts of the central hotspot signal handler.
44   // Returns true if the signal had been recognized and handled, false if not. If true, caller should
45   // return from signal handling.
46   static bool pd_hotspot_signal_handler(int sig, siginfo_t* info, ucontext_t* uc, JavaThread* thread);
47 
48   static bool is_sig_ignored(int sig);
49 
50   static void hotspot_sigmask(Thread* thread);
51 
52   static void print_signal_handler(outputStream* st, int sig, char* buf, size_t buflen);
53 
54   // Suspend-resume
55   static bool do_suspend(OSThread* osthread);
56   static void do_resume(OSThread* osthread);
57 
58   // For signal-chaining
59   static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
60 
61   // Unblock all signals whose delivery cannot be deferred and which, if they happen
62   //  while delivery is blocked, would cause crashes or hangs (see JDK-8252533).
63   static void unblock_error_signals();
64 };
65 
66 #endif // OS_POSIX_SIGNALS_POSIX_HPP
67