clone.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. see <http://www.gnu.org/licenses/>. */
  13. /* clone() is even more special than fork() as it mucks with stacks
  14. and invokes a function in the right context after its all over. */
  15. #include <sys/syscall.h>
  16. #warning "This file contains a hardcoded constant for SYS_clone"
  17. .section .rodata
  18. .align 2
  19. .LC0: .long 120 /* SYS_clone */
  20. .align 4
  21. .text
  22. .type clone,@function
  23. .globl clone;
  24. clone:
  25. .word 0x0040
  26. /* subl2 $8, %sp */
  27. movl 4(%ap), %r1
  28. movl 8(%ap), %r0
  29. mcoml $21, %r6
  30. /* Sanity check args. */
  31. tstl %r1
  32. jeql CLONE_ERROR_LABEL
  33. tstl %r0
  34. jeql CLONE_ERROR_LABEL
  35. /* Need to setup the child stack the same as the parent. */
  36. subl2 $24, %r0
  37. movl 16(%ap), 20(%r0)
  38. movl %r1, 16(%r0)
  39. movl %r0, %r1
  40. addl2 $16, %r1
  41. movl %r1, 12(%r0)
  42. /* Do the system call. */
  43. pushl %ap
  44. pushl %r0
  45. pushl 12(%ap)
  46. pushl $0x2
  47. movl %sp, %ap
  48. chmk .LC0 /* %r0 .LC0 -4(%fp) -8(%fp) */
  49. addl2 $12, %sp
  50. movl (%sp)+, %ap
  51. movl %r0, %r6
  52. jneq CLONE_ERROR_LABEL
  53. movl $0, %fp
  54. pushl 4(%ap)
  55. movl (%r1), %r0
  56. calls $1, (%r0)
  57. pushl %r0
  58. calls $1, HIDDEN_JUMPTARGET(_exit)
  59. CLONE_ERROR_LABEL:
  60. cmpl %r6, $-126 /* -ENOKEY?!?! Fuck, this must be wrong! FIXME */
  61. jlequ CLONE_RETURN_LABEL
  62. calls $0, __errno_location
  63. mnegl %r6, (%r0)
  64. mcoml $0, %r6
  65. movl %r6, %r0
  66. ret
  67. CLONE_RETURN_LABEL:
  68. ret
  69. .size clone,.-clone