vvar.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * vvar.h: Shared vDSO/kernel variable declarations
  3. * Copyright (c) 2011 Andy Lutomirski
  4. * Subject to the GNU General Public License, version 2
  5. *
  6. * A handful of variables are accessible (read-only) from userspace
  7. * code in the vsyscall page and the vdso. They are declared here.
  8. * Some other file must define them with DEFINE_VVAR.
  9. *
  10. * In normal kernel code, they are used like any other variable.
  11. * In user code, they are accessed through the VVAR macro.
  12. *
  13. * Each of these variables lives in the vsyscall page, and each
  14. * one needs a unique offset within the little piece of the page
  15. * reserved for vvars. Specify that offset in DECLARE_VVAR.
  16. * (There are 896 bytes available. If you mess up, the linker will
  17. * catch it.)
  18. */
  19. /* Offset of vars within vsyscall page */
  20. #define VSYSCALL_VARS_OFFSET (3072 + 128)
  21. #if defined(__VVAR_KERNEL_LDS)
  22. /* The kernel linker script defines its own magic to put vvars in the
  23. * right place.
  24. */
  25. #define DECLARE_VVAR(offset, type, name) \
  26. EMIT_VVAR(name, VSYSCALL_VARS_OFFSET + offset)
  27. #else
  28. #define DECLARE_VVAR(offset, type, name) \
  29. static type const * const vvaraddr_ ## name = \
  30. (void *)(VSYSCALL_START + VSYSCALL_VARS_OFFSET + (offset));
  31. #define DEFINE_VVAR(type, name) \
  32. type __vvar_ ## name \
  33. __attribute__((section(".vsyscall_var_" #name), aligned(16)))
  34. #define VVAR(name) (*vvaraddr_ ## name)
  35. #endif
  36. /* DECLARE_VVAR(offset, type, name) */
  37. DECLARE_VVAR(0, volatile unsigned long, jiffies)
  38. DECLARE_VVAR(8, int, vgetcpu_mode)
  39. DECLARE_VVAR(128, struct vsyscall_gtod_data, vsyscall_gtod_data)
  40. #undef DECLARE_VVAR
  41. #undef VSYSCALL_VARS_OFFSET