pt-vfork.S 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Andreas Schwab <schwab@gnu.org>.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #define _ERRNO_H 1
  17. #include <bits/errno.h>
  18. #include <bits/kernel-features.h>
  19. #include <tcb-offsets.h>
  20. /* Save the PID value. */
  21. #define SAVE_PID \
  22. movl %gs:PID, %edx; \
  23. movl %edx, %eax; \
  24. negl %eax; \
  25. movl %eax, %gs:PID
  26. /* Restore the old PID value in the parent. */
  27. #define RESTORE_PID \
  28. testl %eax, %eax; \
  29. je 1f; \
  30. movl %edx, %gs:PID; \
  31. 1:
  32. /* Clone the calling process, but without copying the whole address space.
  33. The calling process is suspended until the new process exits or is
  34. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  35. and the process ID of the new process to the old process. */
  36. ENTRY (__vfork)
  37. /* Pop the return PC value into ECX. */
  38. popl %ecx
  39. SAVE_PID
  40. /* Stuff the syscall number in EAX and enter into the kernel. */
  41. movl $SYS_ify (vfork), %eax
  42. int $0x80
  43. RESTORE_PID
  44. /* Jump to the return PC. Don't jump directly since this
  45. disturbs the branch target cache. Instead push the return
  46. address back on the stack. */
  47. pushl %ecx
  48. cmpl $-4095, %eax
  49. jae SYSCALL_ERROR_LABEL /* Branch forward if it failed. */
  50. L(pseudo_end):
  51. ret
  52. PSEUDO_END (__vfork)
  53. weak_alias (__vfork, vfork)