1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_LIBPANDABASE_OS_UNIX_SIGHOOKLIB_SIGHOOK_H_ 17 #define PANDA_LIBPANDABASE_OS_UNIX_SIGHOOKLIB_SIGHOOK_H_ 18 19 #include <signal.h> // NOLINTNEXTLINE(modernize-deprecated-headers) 20 #include <stdint.h> // NOLINTNEXTLINE(modernize-deprecated-headers) 21 22 namespace panda { 23 24 #if PANDA_TARGET_MACOS && !defined _NSIG 25 #define _NSIG NSIG 26 #endif 27 28 static constexpr uint64_t SIGHOOK_ALLOW_NORETURN = 0x1UL; 29 30 struct SighookAction { 31 bool (*sc_sigaction)(int, siginfo_t *, void *); 32 sigset_t sc_mask; 33 uint64_t sc_flags; 34 }; 35 36 extern "C" void RegisterHookHandler(int signal, const SighookAction *sa); 37 extern "C" void RemoveHookHandler(int signal, bool (*action)(int, siginfo_t *, void *)); 38 extern "C" void CheckOldHookHandler(int signal); 39 void ClearSignalHooksHandlersArray(); 40 41 // actually use sigchain, here provide sigchain stub to make sure complier success 42 // the real used function is in libsigchain.a 43 struct SigchainAction { 44 bool (*sc_sigaction)(int, siginfo_t *, void *); 45 sigset_t sc_mask; 46 uint64_t sc_flags; 47 }; 48 49 extern "C" void AddSpecialSignalHandlerFn(int signal, SigchainAction *sa); 50 extern "C" void RemoveSpecialSignalHandlerFn(int signal, bool (*fn)(int, siginfo_t *, void *)); 51 extern "C" void EnsureFrontOfChain(int signal); 52 53 } // namespace panda 54 55 #endif // PANDA_LIBPANDABASE_OS_UNIX_SIGHOOKLIB_SIGHOOK_H_ 56