syscalls.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <linux/file.h>
  2. #include <linux/fs.h>
  3. #include <linux/module.h>
  4. #include <linux/mount.h>
  5. #include <linux/namei.h>
  6. #include <asm/uaccess.h>
  7. #include "spufs.h"
  8. /**
  9. * sys_spu_run - run code loaded into an SPU
  10. *
  11. * @unpc: next program counter for the SPU
  12. * @ustatus: status of the SPU
  13. *
  14. * This system call transfers the control of execution of a
  15. * user space thread to an SPU. It will return when the
  16. * SPU has finished executing or when it hits an error
  17. * condition and it will be interrupted if a signal needs
  18. * to be delivered to a handler in user space.
  19. *
  20. * The next program counter is set to the passed value
  21. * before the SPU starts fetching code and the user space
  22. * pointer gets updated with the new value when returning
  23. * from kernel space.
  24. *
  25. * The status value returned from spu_run reflects the
  26. * value of the spu_status register after the SPU has stopped.
  27. *
  28. */
  29. static long do_spu_run(struct file *filp,
  30. __u32 __user *unpc,
  31. __u32 __user *ustatus)
  32. {
  33. long ret;
  34. struct spufs_inode_info *i;
  35. u32 npc, status;
  36. ret = -EFAULT;
  37. if (get_user(npc, unpc))
  38. goto out;
  39. /* check if this file was created by spu_create */
  40. ret = -EINVAL;
  41. if (filp->f_op != &spufs_context_fops)
  42. goto out;
  43. i = SPUFS_I(filp->f_path.dentry->d_inode);
  44. ret = spufs_run_spu(i->i_ctx, &npc, &status);
  45. if (put_user(npc, unpc))
  46. ret = -EFAULT;
  47. if (ustatus && put_user(status, ustatus))
  48. ret = -EFAULT;
  49. out:
  50. return ret;
  51. }
  52. static long do_spu_create(const char __user *pathname, unsigned int flags,
  53. mode_t mode, struct file *neighbor)
  54. {
  55. char *tmp;
  56. int ret;
  57. tmp = getname(pathname);
  58. ret = PTR_ERR(tmp);
  59. if (!IS_ERR(tmp)) {
  60. struct nameidata nd;
  61. ret = path_lookup(tmp, LOOKUP_PARENT|
  62. LOOKUP_OPEN|LOOKUP_CREATE, &nd);
  63. if (!ret) {
  64. ret = spufs_create(&nd, flags, mode, neighbor);
  65. path_put(&nd.path);
  66. }
  67. putname(tmp);
  68. }
  69. return ret;
  70. }
  71. struct spufs_calls spufs_calls = {
  72. .create_thread = do_spu_create,
  73. .spu_run = do_spu_run,
  74. .coredump_extra_notes_size = spufs_coredump_extra_notes_size,
  75. .coredump_extra_notes_write = spufs_coredump_extra_notes_write,
  76. .notify_spus_active = do_notify_spus_active,
  77. .owner = THIS_MODULE,
  78. };