This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Undefined behaviour code used in sysdeps/unix/sysv/linux/x86_64/makecontext.c


https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86_64/makecontext.c;h=0d0802bf431326f7fcfe03d49df0c8ee7f4fdaab;hb=HEAD#l71

  51 void
  52 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
  53 {
  54   extern void __start_context (void) attribute_hidden;
  55   greg_t *sp;
  56   unsigned int idx_uc_link;
  57   va_list ap;
  58   int i;
  59
  60   /* Generate room on stack for parameter if needed and uc_link.  */
  61   sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp
  62                    + ucp->uc_stack.ss_size);
  63   sp -= (argc > 6 ? argc - 6 : 0) + 1;
  64   /* Align stack and make space for trampoline address.  */
  65   sp = (greg_t *) ((((uintptr_t) sp) & -16L) - 8);
  66
  67   idx_uc_link = (argc > 6 ? argc - 6 : 0) + 1;
  68
  69   /* Setup context ucp.  */
  70   /* Address to jump to.  */

  71   ucp->uc_mcontext.gregs[REG_RIP] = (uintptr_t) func;

As far as I know cast a function pointer to ordinary integer type or
void*/char* is undefined behaviour in C specification.

Or this is a gcc extension? (use uintptr_t cast on a function pointer to
get the start address of the function code). If it's true, where I could
found the detailed specification?

Thanks a lot :)

Remus


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]