db_exception.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. store_frame(SetExceptionHandler);
  32. if (!handler || event <= 0 || event > PAL_EVENT_NUM_BOUND)
  33. leave_frame(PAL_FALSE, PAL_ERROR_INVAL);
  34. int ret = _DkExceptionHandlers[event](event, handler, flags);
  35. if (ret < 0)
  36. leave_frame(PAL_FALSE, -ret);
  37. leave_frame(PAL_TRUE, 0);
  38. }
  39. void DkExceptionReturn (PAL_PTR event)
  40. {
  41. _DkExceptionReturn(event);
  42. }
  43. unsigned long _DkHandleCompatibilityException (unsigned long syscallno,
  44. unsigned long args[6])
  45. {
  46. printf("compatibility support: detected an unintercepted system call\n");
  47. if (!pal_state.syscall_sym_addr)
  48. _DkProcessExit(-1);
  49. unsigned long ret;
  50. asm volatile ("movq %6, %%r10\r\n"
  51. "movq %7, %%r8\r\n"
  52. "movq %8, %%r9\r\n"
  53. "callq *%1\r\n"
  54. "movq %%rax, %0\r\n"
  55. : "=a" (ret)
  56. : "r"(pal_state.syscall_sym_addr),
  57. "a" (syscallno),
  58. "D" (args[0]),
  59. "S" (args[1]),
  60. "d" (args[2]),
  61. "r" (args[3]),
  62. "r" (args[4]),
  63. "r" (args[5])
  64. : "memory", "r10", "r8", "r9");
  65. return ret;
  66. }