1 /*
2 * Copyright (C) 2012 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 #pragma once
18
19 #include <signal.h>
20 #include <string.h>
21
22 #if !defined(__BIONIC__)
23 #define posix_spawnattr_getsigdefault64 posix_spawnattr_getsigdefault
24 #define posix_spawnattr_getsigmask64 posix_spawnattr_getsigmask
25 #define posix_spawnattr_setsigdefault64 posix_spawnattr_setsigdefault
26 #define posix_spawnattr_setsigmask64 posix_spawnattr_setsigmask
27 #define pthread_sigmask64 pthread_sigmask
28 #define sigaction64 sigaction
29 #define sigaddset64 sigaddset
30 #define sigdelset64 sigdelset
31 #define sigemptyset64 sigemptyset
32 #define sigfillset64 sigfillset
33 #define sigismember64 sigismember
34 #define sigpending64 sigpending
35 #define sigprocmask64 sigprocmask
36 #define sigset64_t sigset_t
37 #define sigsuspend64 sigsuspend
38 #define sigtimedwait64 sigtimedwait
39 #define sigwait64 sigwait
40 #define sigwaitinfo64 sigwaitinfo
41 #endif
42
43 #include "private/ScopedSignalHandler.h"
44
45 class SignalMaskRestorer {
46 public:
SignalMaskRestorer()47 SignalMaskRestorer() {
48 sigprocmask64(SIG_SETMASK, nullptr, &old_mask_);
49 }
50
~SignalMaskRestorer()51 ~SignalMaskRestorer() {
52 sigprocmask64(SIG_SETMASK, &old_mask_, nullptr);
53 }
54
55 private:
56 sigset64_t old_mask_;
57 };
58
59 // uint64_t equivalents of sigsetops.
SignalSetAdd(uint64_t * sigset,int signo)60 static inline void SignalSetAdd(uint64_t* sigset, int signo) {
61 *sigset |= 1ULL << (signo - 1);
62 }
63
SignalSetDel(uint64_t * sigset,int signo)64 static inline void SignalSetDel(uint64_t* sigset, int signo) {
65 *sigset &= ~(1ULL << (signo - 1));
66 }
67