mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Daniel Wilkerson <daniel.wilkerson@gmail.com>
To: musl@lists.openwall.com
Cc: Mark Winterrowd <markwinterrowd4@gmail.com>
Subject: request for help with aux
Date: Mon, 27 Jun 2016 13:07:59 -0700	[thread overview]
Message-ID: <CALzRTRnENpgnCRdJBfOb2CwAD-h6EE_mxgSXPi0abnWuNZsbaQ@mail.gmail.com> (raw)

The musl crt0 code seems to expect that when the process starts that
the stack pointer points to a data page having the following four data
structures immediately contiguous: argc, argv, env, aux.

I'm writing a loader for musl-riscv and I need to know how to
initialize this data.  The only one I wonder about is the aux array.
It seems that aux is a collection of name/value pairs which are used
as follows in musl-riscv/src/env/__libc_start_main.c:

    void __init_libc(char **envp, char *pn)
    {
            size_t i, *auxv, aux[AUX_CNT] = { 0 };
            __environ = envp;
            for (i=0; envp[i]; i++);
            libc.auxv = auxv = (void *)(envp+i+1);
            for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i\
+1];
            __hwcap = aux[AT_HWCAP];
            __sysinfo = aux[AT_SYSINFO];
            libc.page_size = aux[AT_PAGESZ];

            if (pn) {
                    __progname = __progname_full = pn;
                    for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
            }

            __init_tls(aux);
            __init_ssp((void *)aux[AT_RANDOM]);

            if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
                    && !aux[AT_SECURE]) return;

            struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
    #ifdef SYS_poll
            __syscall(SYS_poll, pfd, 3, 0);
    #else
            __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8);
    #endif
            for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
                    if (__sys_open("/dev/null", O_RDWR)<0)
                            a_crash();
            libc.secure = 1;
    }

This seems to initalize aux to be all zeros, so it seems that in
theory all of the aux values could be optional:

        size_t i, *auxv, aux[AUX_CNT] = { 0 };

What I'm wondering is where to find the semantics of all of the aux
names; I could hunt through all of the code, but any high-level
suggestions you could provide could help a lot.  As a bonus, which
ones might not have sensible defaults and are actually non-optional,
if any.

Daniel


             reply	other threads:[~2016-06-27 20:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-27 20:07 Daniel Wilkerson [this message]
2016-06-27 21:00 ` Bobby Bingham
2016-06-27 21:33   ` Daniel Wilkerson
2016-06-27 21:49     ` Nathan McSween
2016-06-27 21:58 ` Rich Felker
2016-06-28  0:22 ` Patrick Oppenlander

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=CALzRTRnENpgnCRdJBfOb2CwAD-h6EE_mxgSXPi0abnWuNZsbaQ@mail.gmail.com \
    --to=daniel.wilkerson@gmail.com \
    --cc=markwinterrowd4@gmail.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).