db_exception.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 OSCAR lab, Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * db_exception.c
  17. *
  18. * This file contains APIs to set up handlers of exceptions issued by the
  19. * host, and the methods to pass the exceptions to the upcalls.
  20. */
  21. #include "pal_defs.h"
  22. #include "pal.h"
  23. #include "pal_internal.h"
  24. #include "pal_error.h"
  25. #include "api.h"
  26. #include "linux_list.h"
  27. PAL_BOL
  28. DkSetExceptionHandler (void (*handler) (PAL_PTR, PAL_NUM, PAL_CONTEXT *),
  29. PAL_NUM event, PAL_FLG flags)
  30. {
  31. ENTER_PAL_CALL(DkSetExceptionHandler);
  32. if (!handler || event <= 0 || event > PAL_EVENT_NUM_BOUND) {
  33. _DkRaiseFailure(PAL_ERROR_INVAL);
  34. LEAVE_PAL_CALL_RETURN(PAL_FALSE);
  35. }
  36. int ret = _DkExceptionHandlers[event](event, handler, flags);
  37. if (ret < 0) {
  38. _DkRaiseFailure(-ret);
  39. LEAVE_PAL_CALL_RETURN(PAL_FALSE);
  40. }
  41. LEAVE_PAL_CALL_RETURN(PAL_TRUE);
  42. }
  43. void DkExceptionReturn (PAL_PTR event)
  44. {
  45. _DkExceptionReturn(event);
  46. }
  47. #ifndef NO_HANDLE_COMPATIBILITY
  48. unsigned long _DkHandleCompatibilityException (unsigned long syscallno,
  49. unsigned long args[6])
  50. {
  51. printf("compatibility support: detected an unintercepted system call\n");
  52. if (!pal_state.syscall_sym_addr)
  53. _DkProcessExit(-1);
  54. unsigned long ret;
  55. asm volatile ("movq %6, %%r10\r\n"
  56. "movq %7, %%r8\r\n"
  57. "movq %8, %%r9\r\n"
  58. "callq *%1\r\n"
  59. "movq %%rax, %0\r\n"
  60. : "=a" (ret)
  61. : "r"(pal_state.syscall_sym_addr),
  62. "a" (syscallno),
  63. "D" (args[0]),
  64. "S" (args[1]),
  65. "d" (args[2]),
  66. "r" (args[3]),
  67. "r" (args[4]),
  68. "r" (args[5])
  69. : "memory", "r10", "r8", "r9");
  70. return ret;
  71. }
  72. #endif