mailing list of musl libc
 help / color / mirror / code / Atom feed
* request for help with aux
@ 2016-06-27 20:07 Daniel Wilkerson
  2016-06-27 21:00 ` Bobby Bingham
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Daniel Wilkerson @ 2016-06-27 20:07 UTC (permalink / raw)
  To: musl; +Cc: Mark Winterrowd

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


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

end of thread, other threads:[~2016-06-28  0:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-27 20:07 request for help with aux Daniel Wilkerson
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

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).