home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / sysdeps / i386 / setjmp / sigsetjmp.c < prev   
Encoding:
C/C++ Source or Header  |  1993-11-02  |  1.7 KB  |  56 lines

  1. /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <stddef.h>
  21. #include <setjmp.h>
  22. #include <signal.h>
  23.  
  24. /* Store the calling environment in ENV, also saving the
  25.    signal mask if SAVEMASK is nonzero.  Return 0.  */
  26. int
  27. DEFUN(sigsetjmp, (env, savemask), sigjmp_buf env AND int savemask)
  28. {
  29.   if (savemask)
  30.     env[0].__savemask = sigprocmask(SIG_BLOCK, (sigset_t *) NULL,
  31.                     &env[0].__sigmask) == 0;
  32.   else
  33.     env[0].__savemask = 0;
  34.  
  35. #define REGS \
  36.   REG (bx);\
  37.   REG (si);\
  38.   REG (di)
  39.  
  40.   /* Save the general registers.  */
  41. #define REG(xx) asm volatile ("movl %%e" #xx ",%0" : \
  42.     "=m" ((long int) ((env[0].__jmpbuf)[0].__##xx)) : )
  43.   REGS;
  44.  
  45.   /* Save the return PC.  */
  46.   (env[0].__jmpbuf)[0].__pc = (PTR) ((PTR *) &env)[-1];
  47.  
  48.   /* Save caller's FP, not our own.  */
  49.   (env[0].__jmpbuf)[0].__bp = (PTR) ((PTR *) &env)[-2];
  50.  
  51.   /* Save caller's SP, not our own.  */
  52.   (env[0].__jmpbuf)[0].__sp = (PTR) &env;
  53.  
  54.   return 0;
  55. }
  56.