clone.S 2.1 KB

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