clone.S 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Library General Public License as
  4. published by the Free Software Foundation; either version 2 of the
  5. License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public
  11. License along with the GNU C Library; see the file COPYING.LIB. If not,
  12. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  13. Boston, MA 02111-1307, USA. */
  14. /* clone() is even more special than fork() as it mucks with stacks
  15. and invokes a function in the right context after its all over. */
  16. #include <sys/syscall.h>
  17. #warning "This file contains a hardcoded constant for SYS_clone"
  18. .section .rodata
  19. .align 2
  20. .LC0: .long 120 /* SYS_clone */
  21. .align 4
  22. .text
  23. .type clone,@function
  24. .globl clone;
  25. clone:
  26. .word 0x0040
  27. /* subl2 $8, %sp */
  28. movl 4(%ap), %r1
  29. movl 8(%ap), %r0
  30. mcoml $21, %r6
  31. /* Sanity check args. */
  32. tstl %r1
  33. jeql CLONE_ERROR_LABEL
  34. tstl %r0
  35. jeql CLONE_ERROR_LABEL
  36. /* Need to setup the child stack the same as the parent. */
  37. subl2 $24, %r0
  38. movl 16(%ap), 20(%r0)
  39. movl %r1, 16(%r0)
  40. movl %r0, %r1
  41. addl2 $16, %r1
  42. movl %r1, 12(%r0)
  43. /* Do the system call. */
  44. pushl %ap
  45. pushl %r0
  46. pushl 12(%ap)
  47. pushl $0x2
  48. movl %sp, %ap
  49. chmk .LC0 /* %r0 .LC0 -4(%fp) -8(%fp) */
  50. addl2 $12, %sp
  51. movl (%sp)+, %ap
  52. movl %r0, %r6
  53. jneq CLONE_ERROR_LABEL
  54. movl $0, %fp
  55. pushl 4(%ap)
  56. movl (%r1), %r0
  57. calls $1, (%r0)
  58. pushl %r0
  59. calls $1, HIDDEN_JUMPTARGET(_exit)
  60. CLONE_ERROR_LABEL:
  61. cmpl %r6, $-126 /* -ENOKEY?!?! Fuck, this must be wrong! FIXME */
  62. jlequ CLONE_RETURN_LABEL
  63. calls $0, __errno_location
  64. mnegl %r6, (%r0)
  65. mcoml $0, %r6
  66. movl %r6, %r0
  67. ret
  68. CLONE_RETURN_LABEL:
  69. ret
  70. .size clone,.-clone