pt-vfork.S 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <sysdep.h>
  17. #define _ERRNO_H 1
  18. #include <bits/errno.h>
  19. #include <bits/kernel-features.h>
  20. #include <tcb-offsets.h>
  21. /* Save the PID value. */
  22. #define SAVE_PID \
  23. movl %gs:PID, %edx; \
  24. movl %edx, %eax; \
  25. negl %eax; \
  26. movl %eax, %gs:PID
  27. /* Restore the old PID value in the parent. */
  28. #define RESTORE_PID \
  29. testl %eax, %eax; \
  30. je 1f; \
  31. movl %edx, %gs:PID; \
  32. 1:
  33. /* Clone the calling process, but without copying the whole address space.
  34. The calling process is suspended until the new process exits or is
  35. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  36. and the process ID of the new process to the old process. */
  37. ENTRY (__vfork)
  38. /* Pop the return PC value into ECX. */
  39. popl %ecx
  40. SAVE_PID
  41. /* Stuff the syscall number in EAX and enter into the kernel. */
  42. movl $SYS_ify (vfork), %eax
  43. int $0x80
  44. RESTORE_PID
  45. /* Jump to the return PC. Don't jump directly since this
  46. disturbs the branch target cache. Instead push the return
  47. address back on the stack. */
  48. pushl %ecx
  49. cmpl $-4095, %eax
  50. jae SYSCALL_ERROR_LABEL /* Branch forward if it failed. */
  51. L(pseudo_end):
  52. ret
  53. PSEUDO_END (__vfork)
  54. weak_alias (__vfork, vfork)