signals.h 860 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. *
  3. * Nim's Runtime Library
  4. * (c) Copyright 2022 Emery Hemingway
  5. *
  6. * See the file "copying.txt", included in this
  7. * distribution, for details about the copyright.
  8. *
  9. */
  10. #ifndef _NIM_SIGNALS_H_
  11. #define _NIM_SIGNALS_H_
  12. #include <libc/component.h>
  13. #include <base/signal.h>
  14. #include <util/reconstructible.h>
  15. // Symbol for calling back into Nim
  16. extern "C" void nimHandleSignal(void *arg);
  17. namespace Nim { struct SignalHandler; }
  18. struct Nim::SignalHandler
  19. {
  20. // Pointer to the Nim handler object.
  21. void *arg;
  22. void handle_signal() {
  23. Libc::with_libc([this] () { nimHandleSignal(arg); }); }
  24. Genode::Signal_handler<SignalHandler> handler;
  25. SignalHandler(Genode::Entrypoint *ep, void *arg)
  26. : arg(arg), handler(*ep, *this, &SignalHandler::handle_signal) { }
  27. Genode::Signal_context_capability cap() { return handler; }
  28. };
  29. #endif