clone.S 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Pat Beirne <patb@corelcomputer.com>
  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. /* clone() is even more special than fork() as it mucks with stacks
  17. and invokes a function in the right context after its all over. */
  18. #define _ERRNO_H
  19. #include <features.h>
  20. #include <bits/errno.h>
  21. #include <sys/syscall.h>
  22. #ifdef __NR_clone
  23. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  24. .text
  25. .global clone
  26. .type clone,%function
  27. .align 2
  28. clone:
  29. @ sanity check args
  30. cmp r0, #0
  31. cmpne r1, #0
  32. moveq r0, #-EINVAL
  33. beq __error
  34. @ insert the args onto the new stack
  35. sub r1, r1, #8
  36. str r3, [r1, #4]
  37. @ save the function pointer as the 0th element
  38. str r0, [r1]
  39. @ do the system call
  40. @ get flags
  41. mov r0, r2
  42. @ new sp is already in r1
  43. DO_CALL (clone)
  44. movs a1, a1
  45. blt __error
  46. #if defined(__USE_BX__)
  47. bxne lr
  48. #else
  49. movne pc, lr
  50. #endif
  51. @ pick the function arg and call address off the stack and execute
  52. ldr r0, [sp, #4]
  53. mov lr, pc
  54. ldr pc, [sp]
  55. @ and we are done, passing the return value through r0
  56. b HIDDEN_JUMPTARGET(_exit)
  57. __error:
  58. b __syscall_error
  59. .size clone,.-clone
  60. #endif