execve.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <errno.h>
  16. #include <unistd.h>
  17. #include <sysdep.h>
  18. #include <alloca.h>
  19. #include <sys/syscall.h>
  20. #include <bp-checks.h>
  21. extern int __syscall_execve (const char *__unbounded file,
  22. char *__unbounded const *__unbounded argv,
  23. char *__unbounded const *__unbounded envp);
  24. extern void __pthread_kill_other_threads_np (void);
  25. weak_extern (__pthread_kill_other_threads_np)
  26. int
  27. __execve (file, argv, envp)
  28. const char *file;
  29. char *const argv[];
  30. char *const envp[];
  31. {
  32. /* If this is a threaded application kill all other threads. */
  33. if (__pthread_kill_other_threads_np)
  34. __pthread_kill_other_threads_np ();
  35. #if __BOUNDED_POINTERS__
  36. {
  37. char *const *v;
  38. int i;
  39. char *__unbounded *__unbounded ubp_argv;
  40. char *__unbounded *__unbounded ubp_envp;
  41. char *__unbounded *__unbounded ubp_v;
  42. for (v = argv; *v; v++)
  43. ;
  44. i = v - argv + 1;
  45. ubp_argv = (char *__unbounded *__unbounded) alloca (sizeof (*ubp_argv) * i);
  46. for (v = argv, ubp_v = ubp_argv; --i; v++, ubp_v++)
  47. *ubp_v = CHECK_STRING (*v);
  48. *ubp_v = 0;
  49. for (v = envp; *v; v++)
  50. ;
  51. i = v - envp + 1;
  52. ubp_envp = (char *__unbounded *__unbounded) alloca (sizeof (*ubp_envp) * i);
  53. for (v = envp, ubp_v = ubp_envp; --i; v++, ubp_v++)
  54. *ubp_v = CHECK_STRING (*v);
  55. *ubp_v = 0;
  56. return INLINE_SYSCALL (execve, 3, CHECK_STRING (file), ubp_argv, ubp_envp);
  57. }
  58. #else
  59. return INLINE_SYSCALL (execve, 3, file, argv, envp);
  60. #endif
  61. }
  62. weak_alias (__execve, execve)