swapcontext.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright (C) 2001-2017 Free Software Foundation, Inc.
  2. Contributed by Jakub Jelinek <jakub@redhat.com>.
  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 <ucontext.h>
  15. extern int __getcontext (ucontext_t *ucp);
  16. extern int __setcontext (const ucontext_t *ucp, int restoremask);
  17. int
  18. __swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
  19. {
  20. extern void __swapcontext_ret (void);
  21. /* Save the current machine context to oucp. */
  22. __getcontext (oucp);
  23. /* Modify oucp to skip the __setcontext call on reactivation. */
  24. oucp->uc_mcontext.mc_gregs[MC_PC] = (long) __swapcontext_ret;
  25. oucp->uc_mcontext.mc_gregs[MC_NPC] = ((long) __swapcontext_ret) + 4;
  26. /* Restore the machine context in ucp. */
  27. __setcontext (ucp, 1);
  28. return 0;
  29. }
  30. __asm__ (" \n\
  31. .text \n\
  32. .type __swapcontext_ret, #function \n\
  33. __swapcontext_ret: \n\
  34. return %i7 + 8 \n\
  35. clr %o0 \n\
  36. .size __swapcontext_ret, .-__swapcontext_ret \n\
  37. ");
  38. weak_alias (__swapcontext, swapcontext)