[Mono-dev] Howto Marshal IntPtr to Elf32_Phdr[] ?

Quandary quandary82 at hailmail.net
Sun Mar 27 11:43:34 EDT 2011

Hi everyone,

I have a problem with dl_iterate_phdr.
(man 3 dl_iterate_phdr)

You find the (till now unanswered) question on stackoverflow, I'm not
inclined to retype everything here again, so below the link:

In a nutshell, the problem is the struct dl_phdr_info you see below.

It seems I need to Marshal
public System.IntPtr dlpi_phdr;
public Elf32_Phdr[] dlpi_phdr;

Or maybe I did translate it to managed code the wrong way.
Can anybody have a look at it ?

All necessary code/structs to get the sample running you find on the
stackoverflow link.

Here's the C struct:

| struct dl_phdr_info {
           ElfW(Addr)        dlpi_addr;  /* Base address of object */
           const char       *dlpi_name;  /* (Null-terminated) name of
                                            object */
           const ElfW(Phdr) *dlpi_phdr;  /* Pointer to array of
                                            ELF program headers
                                            for this object */
           ElfW(Half)        dlpi_phnum; /* # of items in dlpi_phdr */

Here's my C# translation of the above struct:

|  public struct dl_phdr_info 
        public System.UInt32 dlpi_addr; /* Base address of object */
        // TODO: String, MarshalAs Pointer
        public System.IntPtr dlpi_name;  /* (Null-terminated) name of object*/

        /* Pointer to array of ELF program headers for this object */
        public System.IntPtr dlpi_phdr; // Hackish, cannot read it, but then at least the rest works

        // This way it throws an exception at runtime.
        //public Elf32_Phdr[] dlpi_phdr;

        public System.UInt16  dlpi_phnum; /* # of items in 'dlpi_phdr' */

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110327/0bbbd8b2/attachment-0001.html 

More information about the Mono-devel-list mailing list