public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Remus Clearwater <remus.clearwater@gmail.com>
To: libc-help@sourceware.org
Subject: Undefined behaviour code used in sysdeps/unix/sysv/linux/x86_64/makecontext.c
Date: Mon, 21 May 2018 04:32:00 -0000	[thread overview]
Message-ID: <CAMjELSscx-WZdBTrhhi_jzunQb+cU9_4d3-XBeN17RW1x8XyWg@mail.gmail.com> (raw)

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

             reply	other threads:[~2018-05-21  4:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-21  4:32 Remus Clearwater [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMjELSscx-WZdBTrhhi_jzunQb+cU9_4d3-XBeN17RW1x8XyWg@mail.gmail.com \
    --to=remus.clearwater@gmail.com \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).