sys_score.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * arch/score/kernel/syscall.c
  3. *
  4. * Score Processor version.
  5. *
  6. * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
  7. * Chen Liqin <liqin.chen@sunplusct.com>
  8. * Lennox Wu <lennox.wu@sunplusct.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, see the file COPYING, or write
  22. * to the Free Software Foundation, Inc.,
  23. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25. #include <linux/file.h>
  26. #include <linux/fs.h>
  27. #include <linux/mm.h>
  28. #include <linux/mman.h>
  29. #include <linux/module.h>
  30. #include <linux/slab.h>
  31. #include <linux/unistd.h>
  32. #include <linux/syscalls.h>
  33. #include <asm/syscalls.h>
  34. asmlinkage long
  35. sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
  36. unsigned long flags, unsigned long fd, unsigned long pgoff)
  37. {
  38. return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
  39. }
  40. asmlinkage long
  41. sys_mmap(unsigned long addr, unsigned long len, unsigned long prot,
  42. unsigned long flags, unsigned long fd, off_t offset)
  43. {
  44. if (unlikely(offset & ~PAGE_MASK))
  45. return -EINVAL;
  46. return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  47. }
  48. asmlinkage long
  49. score_fork(struct pt_regs *regs)
  50. {
  51. return do_fork(SIGCHLD, regs->regs[0], regs, 0, NULL, NULL);
  52. }
  53. /*
  54. * Clone a task - this clones the calling program thread.
  55. * This is called indirectly via a small wrapper
  56. */
  57. asmlinkage long
  58. score_clone(struct pt_regs *regs)
  59. {
  60. unsigned long clone_flags;
  61. unsigned long newsp;
  62. int __user *parent_tidptr, *child_tidptr;
  63. clone_flags = regs->regs[4];
  64. newsp = regs->regs[5];
  65. if (!newsp)
  66. newsp = regs->regs[0];
  67. parent_tidptr = (int __user *)regs->regs[6];
  68. child_tidptr = (int __user *)regs->regs[8];
  69. return do_fork(clone_flags, newsp, regs, 0,
  70. parent_tidptr, child_tidptr);
  71. }
  72. asmlinkage long
  73. score_vfork(struct pt_regs *regs)
  74. {
  75. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
  76. regs->regs[0], regs, 0, NULL, NULL);
  77. }
  78. /*
  79. * sys_execve() executes a new program.
  80. * This is called indirectly via a small wrapper
  81. */
  82. asmlinkage long
  83. score_execve(struct pt_regs *regs)
  84. {
  85. int error;
  86. char *filename;
  87. filename = getname((char __user*)regs->regs[4]);
  88. error = PTR_ERR(filename);
  89. if (IS_ERR(filename))
  90. return error;
  91. error = do_execve(filename,
  92. (const char __user *const __user *)regs->regs[5],
  93. (const char __user *const __user *)regs->regs[6],
  94. regs);
  95. putname(filename);
  96. return error;
  97. }
  98. /*
  99. * Do a system call from kernel instead of calling sys_execve so we
  100. * end up with proper pt_regs.
  101. */
  102. int kernel_execve(const char *filename,
  103. const char *const argv[],
  104. const char *const envp[])
  105. {
  106. register unsigned long __r4 asm("r4") = (unsigned long) filename;
  107. register unsigned long __r5 asm("r5") = (unsigned long) argv;
  108. register unsigned long __r6 asm("r6") = (unsigned long) envp;
  109. register unsigned long __r7 asm("r7");
  110. __asm__ __volatile__ (" \n"
  111. "ldi r27, %5 \n"
  112. "syscall \n"
  113. "mv %0, r4 \n"
  114. "mv %1, r7 \n"
  115. : "=&r" (__r4), "=r" (__r7)
  116. : "r" (__r4), "r" (__r5), "r" (__r6), "i" (__NR_execve)
  117. : "r8", "r9", "r10", "r11", "r22", "r23", "r24", "r25",
  118. "r26", "r27", "memory");
  119. if (__r7 == 0)
  120. return __r4;
  121. return -__r4;
  122. }