public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Undefined behaviour code used in sysdeps/unix/sysv/linux/x86_64/makecontext.c
@ 2018-05-21  4:32 Remus Clearwater
  2018-05-21 11:39 ` Godmar Back
  2018-05-22 11:21 ` Florian Weimer
  0 siblings, 2 replies; 7+ messages in thread
From: Remus Clearwater @ 2018-05-21  4:32 UTC (permalink / raw)
  To: libc-help

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-05-22 11:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-21  4:32 Undefined behaviour code used in sysdeps/unix/sysv/linux/x86_64/makecontext.c Remus Clearwater
2018-05-21 11:39 ` Godmar Back
     [not found]   ` <CAMjELStuFqCE3iVUR-ju3nZqG89dzfPET9kTWniz+kGPOm12ug@mail.gmail.com>
2018-05-21 13:09     ` Fwd: " Remus Clearwater
2018-05-21 13:18       ` Remus Clearwater
2018-05-21 14:27         ` Godmar Back
2018-05-22  6:47           ` Remus Clearwater
2018-05-22 11:21 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).