um_vdso.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2011 Richard Weinberger <[email protected]>
  4. *
  5. * This vDSO turns all calls into a syscall so that UML can trap them.
  6. */
  7. /* Disable profiling for userspace code */
  8. #define DISABLE_BRANCH_PROFILING
  9. #include <linux/time.h>
  10. #include <linux/getcpu.h>
  11. #include <asm/unistd.h>
  12. int __vdso_clock_gettime(clockid_t clock, struct __kernel_old_timespec *ts)
  13. {
  14. long ret;
  15. asm("syscall"
  16. : "=a" (ret)
  17. : "0" (__NR_clock_gettime), "D" (clock), "S" (ts)
  18. : "rcx", "r11", "memory");
  19. return ret;
  20. }
  21. int clock_gettime(clockid_t, struct __kernel_old_timespec *)
  22. __attribute__((weak, alias("__vdso_clock_gettime")));
  23. int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
  24. {
  25. long ret;
  26. asm("syscall"
  27. : "=a" (ret)
  28. : "0" (__NR_gettimeofday), "D" (tv), "S" (tz)
  29. : "rcx", "r11", "memory");
  30. return ret;
  31. }
  32. int gettimeofday(struct __kernel_old_timeval *, struct timezone *)
  33. __attribute__((weak, alias("__vdso_gettimeofday")));
  34. __kernel_old_time_t __vdso_time(__kernel_old_time_t *t)
  35. {
  36. long secs;
  37. asm volatile("syscall"
  38. : "=a" (secs)
  39. : "0" (__NR_time), "D" (t) : "cc", "r11", "cx", "memory");
  40. return secs;
  41. }
  42. __kernel_old_time_t time(__kernel_old_time_t *t) __attribute__((weak, alias("__vdso_time")));
  43. long
  44. __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
  45. {
  46. /*
  47. * UML does not support SMP, we can cheat here. :)
  48. */
  49. if (cpu)
  50. *cpu = 0;
  51. if (node)
  52. *node = 0;
  53. return 0;
  54. }
  55. long getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
  56. __attribute__((weak, alias("__vdso_getcpu")));