简体   繁体   中英

Where is glibc's code for setjmp?

I was interested in what exactly setjmp does at least in x86_64 linux, so I searched through glibc 's source code, but I cannot really find where the register saving is done. Could you explain what is going on here?

setjmp.h

extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROWNL;
#define setjmp(env)     _setjmp (env)

bsd-_setjmp.c

int
_setjmp (jmp_buf env)
{
  return __sigsetjmp (env, 0);
}

libc_hidden_def (_setjmp)

setjmp.c

int
__libc_sigsetjmp (jmp_buf env, int savemask)
{
  __sigjmp_save (env, savemask);
  __set_errno (ENOSYS);
  return 0;
}

weak_alias (__libc_sigsetjmp, __sigsetjmp)
stub_warning (__sigsetjmp)

sigjmp.c

int
__sigjmp_save (sigjmp_buf env, int savemask)
{
  env[0].__mask_was_saved = (savemask &&
                             __sigprocmask (SIG_BLOCK, (sigset_t *) NULL,
                                            &env[0].__saved_mask) == 0);
  return 0;
}

setjmp is a macro which calls _setjmp . For the x86_64 architecture, it's defined in ../sysdeps/x86_64/bsd-_setjmp.S . _setjmp will then call __sigsetjmp , defined in ../sysdeps/x86_64/setjmp.S ; this function is strictly platform dependent and needs to be implemented in assembly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM