syscall.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Author: Hanlu Li <[email protected]>
  4. * Huacai Chen <[email protected]>
  5. *
  6. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  7. */
  8. #include <linux/capability.h>
  9. #include <linux/entry-common.h>
  10. #include <linux/errno.h>
  11. #include <linux/linkage.h>
  12. #include <linux/syscalls.h>
  13. #include <linux/unistd.h>
  14. #include <asm/asm.h>
  15. #include <asm/signal.h>
  16. #include <asm/switch_to.h>
  17. #include <asm-generic/syscalls.h>
  18. #undef __SYSCALL
  19. #define __SYSCALL(nr, call) [nr] = (call),
  20. SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, unsigned long,
  21. prot, unsigned long, flags, unsigned long, fd, off_t, offset)
  22. {
  23. if (offset & ~PAGE_MASK)
  24. return -EINVAL;
  25. return ksys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  26. }
  27. void *sys_call_table[__NR_syscalls] = {
  28. [0 ... __NR_syscalls - 1] = sys_ni_syscall,
  29. #include <asm/unistd.h>
  30. };
  31. typedef long (*sys_call_fn)(unsigned long, unsigned long,
  32. unsigned long, unsigned long, unsigned long, unsigned long);
  33. void noinstr do_syscall(struct pt_regs *regs)
  34. {
  35. unsigned long nr;
  36. sys_call_fn syscall_fn;
  37. nr = regs->regs[11];
  38. /* Set for syscall restarting */
  39. if (nr < NR_syscalls)
  40. regs->regs[0] = nr + 1;
  41. regs->csr_era += 4;
  42. regs->orig_a0 = regs->regs[4];
  43. regs->regs[4] = -ENOSYS;
  44. nr = syscall_enter_from_user_mode(regs, nr);
  45. if (nr < NR_syscalls) {
  46. syscall_fn = sys_call_table[nr];
  47. regs->regs[4] = syscall_fn(regs->orig_a0, regs->regs[5], regs->regs[6],
  48. regs->regs[7], regs->regs[8], regs->regs[9]);
  49. }
  50. syscall_exit_to_user_mode(regs);
  51. }