exception.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * exception.h
  3. *
  4. * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __MONOLITHIUM_EXCEPTION_H__
  20. #define __MONOLITHIUM_EXCEPTION_H__
  21. #include "defs.h"
  22. #include "cpu.h"
  23. #include "object.h"
  24. #ifdef __MONOLITIHUM_KERNEL_MODE__
  25. #define EH_TRY if (get_current_thread() != NULL) { exception_handler_t ___handler; if (save_kernel_handler(&___handler) == 0)
  26. #else
  27. #define EH_TRY if (TRUE) { exception_handler_t ___handler; if (syscall(SYSCALL_SAVE_EXCEPTION_HANDLER, &___handler) == 0)
  28. #endif
  29. #define EH_CATCH else
  30. #define EH_DONE syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, &___handler); }
  31. #define EH_ESCAPE(x) do { syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, &___handler); x; } while (FALSE)
  32. typedef registers_t exception_handler_t;
  33. typedef enum
  34. {
  35. EXCEPTION_BREAKPOINT,
  36. EXCEPTION_ARITHMETIC,
  37. EXCEPTION_ASSERTION,
  38. EXCEPTION_BAD_OPERATION,
  39. EXCEPTION_MEMORY_ACCESS,
  40. EXCEPTION_CUSTOM,
  41. } exception_t;
  42. typedef struct
  43. {
  44. exception_t number;
  45. registers_t state;
  46. dword_t parameters[4];
  47. } exception_info_t;
  48. sysret_t syscall_get_exception_info(exception_info_t *info);
  49. sysret_t syscall_raise_exception(handle_t thread, const exception_info_t *info);
  50. sysret_t syscall_save_exception_handler(exception_handler_t *old_handler);
  51. sysret_t syscall_restore_exception_handler(const exception_handler_t *old_handler);
  52. #endif