db_exception.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 event, PAL_NUM arg,
  29. PAL_CONTEXT * context),
  30. PAL_NUM event, PAL_FLG flags)
  31. {
  32. if (!handler || event <= 0 || event > PAL_EVENT_NUM_BOUND) {
  33. notify_failure(PAL_ERROR_INVAL);
  34. return PAL_FALSE;
  35. }
  36. int ret = _DkExceptionHandlers[event](event, handler, flags);
  37. if (ret < 0) {
  38. notify_failure(-ret);
  39. return PAL_FALSE;
  40. }
  41. return PAL_TRUE;
  42. }
  43. void DkExceptionReturn (PAL_PTR event)
  44. {
  45. _DkExceptionReturn(event);
  46. }