exec.c 2.1 KB

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