syscall_64.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* System call table for x86-64. */
  3. #include <linux/linkage.h>
  4. #include <linux/sys.h>
  5. #include <linux/cache.h>
  6. #include <linux/moduleparam.h>
  7. #undef MODULE_PARAM_PREFIX
  8. #define MODULE_PARAM_PREFIX "syscall."
  9. #include <asm/asm-offsets.h>
  10. #include <asm/syscall.h>
  11. /* this is a lie, but it does not hurt as sys_ni_syscall just returns -EINVAL */
  12. extern asmlinkage long sys_ni_syscall(const struct pt_regs *);
  13. #define __SYSCALL_64(nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *);
  14. #include <asm/syscalls_64.h>
  15. #undef __SYSCALL_64
  16. #define __SYSCALL_64(nr, sym, qual) [nr] = sym,
  17. asmlinkage const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {
  18. /*
  19. * Smells like a compiler bug -- it doesn't work
  20. * when the & below is removed.
  21. */
  22. [0 ... __NR_syscall_max] = &sys_ni_syscall,
  23. #include <asm/syscalls_64.h>
  24. };
  25. #ifdef CONFIG_X86_X32_ABI
  26. /* Maybe enable x32 syscalls */
  27. #if defined(CONFIG_X86_X32_DISABLED)
  28. DEFINE_STATIC_KEY_FALSE(x32_enabled_skey);
  29. #else
  30. DEFINE_STATIC_KEY_TRUE(x32_enabled_skey);
  31. #endif
  32. static int __init x32_param_set(const char *val, const struct kernel_param *p)
  33. {
  34. bool enabled;
  35. int ret;
  36. ret = kstrtobool(val, &enabled);
  37. if (ret)
  38. return ret;
  39. if (IS_ENABLED(CONFIG_X86_X32_DISABLED)) {
  40. if (enabled) {
  41. static_key_enable(&x32_enabled_skey.key);
  42. pr_info("Enabled x32 syscalls\n");
  43. }
  44. } else {
  45. if (!enabled) {
  46. static_key_disable(&x32_enabled_skey.key);
  47. pr_info("Disabled x32 syscalls\n");
  48. }
  49. }
  50. return 0;
  51. }
  52. static int x32_param_get(char *buffer, const struct kernel_param *p)
  53. {
  54. return sprintf(buffer, "%c\n",
  55. static_key_enabled(&x32_enabled_skey) ? 'Y' : 'N');
  56. }
  57. static const struct kernel_param_ops x32_param_ops = {
  58. .set = x32_param_set,
  59. .get = x32_param_get,
  60. };
  61. arch_param_cb(x32, &x32_param_ops, NULL, 0444);
  62. #endif