1 /** 2 * Copyright (c) 2021-2024 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_SIGHOOK_H_ 17 #define PANDA_LIBPANDABASE_OS_UNIX_SIGHOOK_H_ 18 19 #include <csignal> 20 #include <cstdint> 21 #include "libpandabase/macros.h" 22 23 namespace ark { 24 25 #if PANDA_TARGET_MACOS && !defined _NSIG 26 #define _NSIG NSIG 27 #endif 28 29 static constexpr uint64_t SIGHOOK_ALLOW_NORETURN = 0x1UL; 30 31 struct SighookAction { 32 bool (*scSigaction)(int, siginfo_t *, void *); 33 sigset_t scMask; 34 uint64_t scFlags; 35 }; 36 37 extern "C" void RegisterHookHandler(int signal, const SighookAction *sa); 38 extern "C" void RemoveHookHandler(int signal, bool (*action)(int, siginfo_t *, void *)); 39 extern "C" void CheckOldHookHandler(int signal); 40 PANDA_PUBLIC_API void ClearSignalHooksHandlersArray(); 41 42 // running on mobile, actually use sigchain, here provide sigchain stub to make sure complier success 43 // the real used function is in libsigchain.a 44 struct SigchainAction { 45 bool (*scSigaction)(int, siginfo_t *, void *); 46 sigset_t scMask; 47 uint64_t scFlags; 48 }; 49 50 extern "C" PANDA_PUBLIC_API void AddSpecialSignalHandlerFn(int signal, SigchainAction *sa); 51 extern "C" PANDA_PUBLIC_API void RemoveSpecialSignalHandlerFn(int signal, bool (*fn)(int, siginfo_t *, void *)); 52 extern "C" void EnsureFrontOfChain(int signal); 53 54 } // namespace ark 55 56 #endif // PANDA_LIBPANDABASE_OS_UNIX_SIGHOOK_H_ 57