vfork.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (C) 2013 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <tls.h>
  15. /*
  16. Save the PID value, save 0x80000000 if PID was 0.
  17. Registers a2 and a3 are available; ar should return the PID and as threadptr
  18. */
  19. #define SAVE_PID(pid,tp,ar,as) \
  20. rur tp, threadptr; \
  21. movi ar, TLS_PRE_TCB_SIZE; \
  22. sub tp, tp, ar; \
  23. l32i pid, tp, PID; \
  24. neg ar, pid; \
  25. movi as, 0x80000000; \
  26. moveqz ar, as, ar; \
  27. s32i ar, tp, PID; \
  28. /*
  29. Restore the PID value, restore to 0 if saved value was 0x80000000
  30. Return value from the syscall is in a2.
  31. */
  32. #define RESTORE_PID(pid,tp,res) \
  33. beqz res, 1f; \
  34. s32i pid, tp, PID; \
  35. 1:
  36. /*
  37. Special version for call12, where we don't have enough registers
  38. available to preserve the original PID.
  39. */
  40. #define RESTORE_PID12(ar, as, at) \
  41. rur as, threadptr; \
  42. movi ar, TLS_PRE_TCB_SIZE; \
  43. sub as, as, ar; \
  44. l32i ar, as, PID; \
  45. movi at, 0x80000000; \
  46. sub at, at, ar; \
  47. neg ar, ar; \
  48. moveqz ar, at, at; \
  49. s32i ar, as, PID;
  50. #include <libc/sysdeps/linux/xtensa/vfork.S>