• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef BERBERIS_BASE_HOST_SIGNAL_H_
18 #define BERBERIS_BASE_HOST_SIGNAL_H_
19 
20 #include <signal.h>
21 #include <sys/syscall.h>
22 
23 #include "berberis/base/checks.h"
24 
25 namespace berberis {
26 
27 #if defined(__BIONIC__) && !defined(__LP64__)
28 
29 using HostSigset = sigset64_t;
30 using HostStructSigaction = struct sigaction64;
31 
32 #define HostSigaddset sigaddset64
33 #define HostSigfillset sigfillset64
34 #define HostSigaction sigaction64
35 
36 #else
37 
38 using HostSigset = sigset_t;
39 using HostStructSigaction = struct sigaction;
40 
41 #define HostSigaddset sigaddset
42 #define HostSigfillset sigfillset
43 #define HostSigaction sigaction
44 
45 #endif
46 
47 // Use syscall to avoid libc (filters out TIMER) or libsigchain (filters out SIGSEGV).
RTSigprocmaskSyscallOrDie(int how,const HostSigset * new_set,HostSigset * old_set)48 inline void RTSigprocmaskSyscallOrDie(int how, const HostSigset* new_set, HostSigset* old_set) {
49   // Note that we cannot use sizeof(HostSigset) as the last argument here since
50   // Glibc's sizeof(sigset_t) is 128 bytes, while kernel only supports 8 bytes.
51   long res = syscall(SYS_rt_sigprocmask, how, new_set, old_set, _NSIG / 8);
52   // CHECK_EQ() formatting doesn't support long.
53   CHECK(res == 0);
54 }
55 
56 }  // namespace berberis
57 
58 #endif  // BERBERIS_BASE_HOST_SIGNAL_H_
59