exec.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/stddef.h"
  6. #include "linux/fs.h"
  7. #include "linux/smp_lock.h"
  8. #include "linux/ptrace.h"
  9. #include "linux/sched.h"
  10. #include "asm/current.h"
  11. #include "asm/processor.h"
  12. #include "asm/uaccess.h"
  13. #include "mem_user.h"
  14. #include "skas.h"
  15. #include "os.h"
  16. void flush_thread(void)
  17. {
  18. void *data = NULL;
  19. unsigned long end = proc_mm ? task_size : CONFIG_STUB_START;
  20. int ret;
  21. arch_flush_thread(&current->thread.arch);
  22. ret = unmap(&current->mm->context.skas.id, 0, end, 1, &data);
  23. if (ret) {
  24. printk(KERN_ERR "flush_thread - clearing address space failed, "
  25. "err = %d\n", ret);
  26. force_sig(SIGKILL, current);
  27. }
  28. __switch_mm(&current->mm->context.skas.id);
  29. }
  30. void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
  31. {
  32. set_fs(USER_DS);
  33. PT_REGS_IP(regs) = eip;
  34. PT_REGS_SP(regs) = esp;
  35. }
  36. #ifdef CONFIG_TTY_LOG
  37. extern void log_exec(char **argv, void *tty);
  38. #endif
  39. static long execve1(char *file, char __user * __user *argv,
  40. char __user *__user *env)
  41. {
  42. long error;
  43. #ifdef CONFIG_TTY_LOG
  44. struct tty_struct *tty;
  45. mutex_lock(&tty_mutex);
  46. tty = get_current_tty();
  47. if (tty)
  48. log_exec(argv, tty);
  49. mutex_unlock(&tty_mutex);
  50. #endif
  51. error = do_execve(file, argv, env, &current->thread.regs);
  52. if (error == 0) {
  53. task_lock(current);
  54. current->ptrace &= ~PT_DTRACE;
  55. #ifdef SUBARCH_EXECVE1
  56. SUBARCH_EXECVE1(&current->thread.regs.regs);
  57. #endif
  58. task_unlock(current);
  59. }
  60. return error;
  61. }
  62. long um_execve(char *file, char __user *__user *argv, char __user *__user *env)
  63. {
  64. long err;
  65. err = execve1(file, argv, env);
  66. if (!err)
  67. do_longjmp(current->thread.exec_buf, 1);
  68. return err;
  69. }
  70. long sys_execve(char __user *file, char __user *__user *argv,
  71. char __user *__user *env)
  72. {
  73. long error;
  74. char *filename;
  75. lock_kernel();
  76. filename = getname(file);
  77. error = PTR_ERR(filename);
  78. if (IS_ERR(filename)) goto out;
  79. error = execve1(filename, argv, env);
  80. putname(filename);
  81. out:
  82. unlock_kernel();
  83. return error;
  84. }