user3810155
user3810155

Reputation:

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;
}

Upvotes: 6

Views: 1679

Answers (1)

edmz
edmz

Reputation: 8494

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.

Upvotes: 5

Related Questions