exec.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "as-layout.h"
  14. #include "mem_user.h"
  15. #include "skas.h"
  16. #include "os.h"
  17. void flush_thread(void)
  18. {
  19. void *data = NULL;
  20. unsigned long end = proc_mm ? task_size : STUB_START;
  21. int ret;
  22. arch_flush_thread(&current->thread.arch);
  23. ret = unmap(&current->mm->context.id, 0, end, 1, &data);
  24. if (ret) {
  25. printk(KERN_ERR "flush_thread - clearing address space failed, "
  26. "err = %d\n", ret);
  27. force_sig(SIGKILL, current);
  28. }
  29. __switch_mm(&current->mm->context.id);
  30. }
  31. void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
  32. {
  33. set_fs(USER_DS);
  34. PT_REGS_IP(regs) = eip;
  35. PT_REGS_SP(regs) = esp;
  36. }
  37. #ifdef CONFIG_TTY_LOG
  38. extern void log_exec(char **argv, void *tty);
  39. #endif
  40. static long execve1(char *file, char __user * __user *argv,
  41. char __user *__user *env)
  42. {
  43. long error;
  44. #ifdef CONFIG_TTY_LOG
  45. struct tty_struct *tty;
  46. mutex_lock(&tty_mutex);
  47. tty = get_current_tty();
  48. if (tty)
  49. log_exec(argv, tty);
  50. mutex_unlock(&tty_mutex);
  51. #endif
  52. error = do_execve(file, argv, env, &current->thread.regs);
  53. if (error == 0) {
  54. task_lock(current);
  55. current->ptrace &= ~PT_DTRACE;
  56. #ifdef SUBARCH_EXECVE1
  57. SUBARCH_EXECVE1(&current->thread.regs.regs);
  58. #endif
  59. task_unlock(current);
  60. }
  61. return error;
  62. }
  63. long um_execve(char *file, char __user *__user *argv, char __user *__user *env)
  64. {
  65. long err;
  66. err = execve1(file, argv, env);
  67. if (!err)
  68. UML_LONGJMP(current->thread.exec_buf, 1);
  69. return err;
  70. }
  71. long sys_execve(char __user *file, char __user *__user *argv,
  72. char __user *__user *env)
  73. {
  74. long error;
  75. char *filename;
  76. lock_kernel();
  77. filename = getname(file);
  78. error = PTR_ERR(filename);
  79. if (IS_ERR(filename)) goto out;
  80. error = execve1(filename, argv, env);
  81. putname(filename);
  82. out:
  83. unlock_kernel();
  84. return error;
  85. }