sys.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * linux/arch/unicore32/kernel/sys.c
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/slab.h>
  16. #include <linux/mm.h>
  17. #include <linux/sem.h>
  18. #include <linux/msg.h>
  19. #include <linux/shm.h>
  20. #include <linux/stat.h>
  21. #include <linux/syscalls.h>
  22. #include <linux/mman.h>
  23. #include <linux/fs.h>
  24. #include <linux/file.h>
  25. #include <linux/ipc.h>
  26. #include <linux/uaccess.h>
  27. #include <asm/syscalls.h>
  28. #include <asm/cacheflush.h>
  29. /* Clone a task - this clones the calling program thread.
  30. * This is called indirectly via a small wrapper
  31. */
  32. asmlinkage long __sys_clone(unsigned long clone_flags, unsigned long newsp,
  33. void __user *parent_tid, void __user *child_tid,
  34. struct pt_regs *regs)
  35. {
  36. if (!newsp)
  37. newsp = regs->UCreg_sp;
  38. return do_fork(clone_flags, newsp, regs, 0,
  39. parent_tid, child_tid);
  40. }
  41. /* sys_execve() executes a new program.
  42. * This is called indirectly via a small wrapper
  43. */
  44. asmlinkage long __sys_execve(const char __user *filename,
  45. const char __user *const __user *argv,
  46. const char __user *const __user *envp,
  47. struct pt_regs *regs)
  48. {
  49. int error;
  50. char *fn;
  51. fn = getname(filename);
  52. error = PTR_ERR(fn);
  53. if (IS_ERR(fn))
  54. goto out;
  55. error = do_execve(fn, argv, envp, regs);
  56. putname(fn);
  57. out:
  58. return error;
  59. }
  60. int kernel_execve(const char *filename,
  61. const char *const argv[],
  62. const char *const envp[])
  63. {
  64. struct pt_regs regs;
  65. int ret;
  66. memset(&regs, 0, sizeof(struct pt_regs));
  67. ret = do_execve(filename,
  68. (const char __user *const __user *)argv,
  69. (const char __user *const __user *)envp, &regs);
  70. if (ret < 0)
  71. goto out;
  72. /*
  73. * Save argc to the register structure for userspace.
  74. */
  75. regs.UCreg_00 = ret;
  76. /*
  77. * We were successful. We won't be returning to our caller, but
  78. * instead to user space by manipulating the kernel stack.
  79. */
  80. asm("add r0, %0, %1\n\t"
  81. "mov r1, %2\n\t"
  82. "mov r2, %3\n\t"
  83. "mov r22, #0\n\t" /* not a syscall */
  84. "mov r23, %0\n\t" /* thread structure */
  85. "b.l memmove\n\t" /* copy regs to top of stack */
  86. "mov sp, r0\n\t" /* reposition stack pointer */
  87. "b ret_to_user"
  88. :
  89. : "r" (current_thread_info()),
  90. "Ir" (THREAD_START_SP - sizeof(regs)),
  91. "r" (&regs),
  92. "Ir" (sizeof(regs))
  93. : "r0", "r1", "r2", "r3", "ip", "lr", "memory");
  94. out:
  95. return ret;
  96. }
  97. EXPORT_SYMBOL(kernel_execve);
  98. /* Note: used by the compat code even in 64-bit Linux. */
  99. SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
  100. unsigned long, prot, unsigned long, flags,
  101. unsigned long, fd, unsigned long, off_4k)
  102. {
  103. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  104. off_4k);
  105. }
  106. /* Provide the actual syscall number to call mapping. */
  107. #undef __SYSCALL
  108. #define __SYSCALL(nr, call) [nr] = (call),
  109. /* Note that we don't include <linux/unistd.h> but <asm/unistd.h> */
  110. void *sys_call_table[__NR_syscalls] = {
  111. [0 ... __NR_syscalls-1] = sys_ni_syscall,
  112. #include <asm/unistd.h>
  113. };