shim_sleep.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 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 Lesser 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 Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * shim_sleep.c
  17. *
  18. * Implementation of system call "pause" and "nanosleep".
  19. */
  20. #include <shim_internal.h>
  21. #include <shim_utils.h>
  22. #include <shim_table.h>
  23. #include <shim_handle.h>
  24. #include <shim_vma.h>
  25. #include <pal.h>
  26. #include <pal_error.h>
  27. #include <errno.h>
  28. #define SHIM_DEFAULT_SLEEP 1000
  29. int shim_do_pause (void)
  30. {
  31. while (1) {
  32. unsigned long ret = DkThreadDelayExecution(SHIM_DEFAULT_SLEEP);
  33. if (!ret)
  34. break;
  35. }
  36. return 0;
  37. }
  38. int shim_do_nanosleep (const struct __kernel_timespec * rqtp,
  39. struct __kernel_timespec * rmtp)
  40. {
  41. if (!rqtp)
  42. return -EFAULT;
  43. unsigned long time = rqtp->tv_sec * 1000000L + rqtp->tv_nsec / 1000;
  44. unsigned long ret = DkThreadDelayExecution(time);
  45. if (ret < time) {
  46. if (rmtp) {
  47. unsigned long remtime = time - ret;
  48. rmtp->tv_sec = remtime / 1000000L;
  49. rmtp->tv_nsec = (remtime - rmtp->tv_sec * 1000) * 1000;
  50. }
  51. return -EINTR;
  52. }
  53. return 0;
  54. }