From: Alex Caudill <alex.caudill@gmail.com>
To: musl@lists.openwall.com
Subject: PATCH: dl_iterate_phdr()
Date: Thu, 11 Oct 2012 09:29:28 -0500 [thread overview]
Message-ID: <CAFXnQt4wBoJE4eZzVHChwpEbrzS7fm9U8VL1M02Opem7vn1fMw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 329 bytes --]
Hi!
With a little help on IRC I hacked together a basic version of
dl_iterate_phdr(), which I dropped into src/ldso/dynlink.c in my tree.
This introduces a new include file: <link.h>
Line #9 of dl_iterate_phdr.c throws a warning that I'm not sure how to silence.
I've attached both, and a test program. No copyright.
Thanks!
[-- Attachment #2: dl_iterate_phdr.c --]
[-- Type: text/x-csrc, Size: 632 bytes --]
int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
{
struct dso *current;
Ehdr *ehdr;
struct dl_phdr_info info;
int ret = 0;
for(current = head; current; current = current->next) {
ehdr = (Ehdr *)current->map;
info.dlpi_addr = (ehdr->e_type == ET_EXEC) ? 0 : current->map;
info.dlpi_name = current->shortname;
info.dlpi_phdr = (Phdr *)(current->map + ehdr->e_phoff);
info.dlpi_phnum = ehdr->e_phnum;
ret = (callback)(&info, sizeof (info), data);
if (ret != 0)
break;
}
return ret;
}
[-- Attachment #3: link.h --]
[-- Type: text/x-chdr, Size: 480 bytes --]
#ifndef LINK_H
#define LINK_H
#include <elf.h>
#define __NEED_size_t
#include <bits/alltypes.h>
#ifdef _LP64
#define ElfW(type) Elf64_ ## type
#else
#define ElfW(type) Elf32_ ## type
#endif
struct dl_phdr_info {
ElfW(Addr) dlpi_addr;
const char *dlpi_name;
const ElfW(Phdr) *dlpi_phdr;
ElfW(Half) dlpi_phnum;
};
int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *);
#endif
[-- Attachment #4: dltest.c --]
[-- Type: text/x-csrc, Size: 528 bytes --]
#define _GNU_SOURCE
#include <link.h>
#include <stdlib.h>
#include <stdio.h>
static int
callback(struct dl_phdr_info *info, size_t size, void *data)
{
int j;
printf("name=%s (%d segments)\n", info->dlpi_name,
info->dlpi_phnum);
for (j = 0; j < info->dlpi_phnum; j++)
printf("\t\t header %2d: address=%10p\n", j,
(void *) (info->dlpi_addr + info->dlpi_phdr[j].p_vaddr));
return 0;
}
int
main(int argc, char *argv[])
{
dl_iterate_phdr(callback, NULL);
exit(EXIT_SUCCESS);
}
next reply other threads:[~2012-10-11 14:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-11 14:29 Alex Caudill [this message]
2012-10-11 23:42 ` Rich Felker
2012-10-12 0:00 ` Rich Felker
2012-10-12 13:28 ` Alex Caudill
2012-10-12 15:43 ` Rich Felker
2012-10-13 1:04 ` Alex Caudill
2012-10-13 1:24 ` Alex Caudill
2012-10-13 1:31 ` Rich Felker
2012-10-15 3:30 ` Rich Felker
2012-10-15 4:47 ` Alex Caudill
2012-10-15 12:41 ` Rich Felker
2012-10-18 20:45 ` Rich Felker
2012-10-31 18:35 ` Alex Caudill
2012-11-01 1:33 ` Rich Felker
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=CAFXnQt4wBoJE4eZzVHChwpEbrzS7fm9U8VL1M02Opem7vn1fMw@mail.gmail.com \
--to=alex.caudill@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).