1 /* 2 ** Licensed under the Apache License, Version 2.0 (the "License"); 3 ** you may not use this file except in compliance with the License. 4 ** You may obtain a copy of the License at 5 ** 6 ** http://www.apache.org/licenses/LICENSE-2.0 7 ** 8 ** Unless required by applicable law or agreed to in writing, software 9 ** distributed under the License is distributed on an "AS IS" BASIS, 10 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 ** See the License for the specific language governing permissions and 12 ** limitations under the License. 13 ** 14 ** Copyright 2021 NXP 15 ** 16 */ 17 18 #ifndef __SIGNALHANDLER_H__ 19 #define __SIGNALHANDLER_H__ 20 21 #include <signal.h> 22 23 namespace keymint::javacard { 24 25 class SignalHandler { 26 public: 27 /** 28 * Retrieve instance of SignalHandler class 29 */ 30 static SignalHandler* getInstance(); 31 /** 32 * register signal Handler. 33 * Use mPtrContext to pass handle which might be required in signal Handler 34 */ 35 void installHandler(void* mPtrContext); 36 37 /** 38 * block Signals to prevent interrupts during critical parts of code 39 */ 40 void blockSignals(); 41 42 /** 43 * Unblock signal previously blocked using blockSignals() 44 * Pending signals are delivered after they are unblocked. 45 */ 46 void unblockSignals(); 47 48 /** 49 * Check if Signal handler is registered 50 */ 51 bool isHandlerRegistered(); 52 53 private: 54 SignalHandler(); 55 bool isRegistered; 56 void* mContext; 57 static SignalHandler* instance; 58 sigset_t blockedSignals, oldMask; 59 }; 60 61 } // namespace keymint::javacard 62 #endif // __SIGNALHANDLER_H__ 63