lkml.org 
[lkml]   [2012]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [PATCH -mm v2] coredump: extend core dump note section to contain file names of mapped files
    On Tue, Sep 18, 2012 at 6:58 PM, Roland McGrath <roland@hack.frob.com> wrote:
    > The code needs to be macroized a bit so that compat_binfmt_elf.c will
    > produce a version that encodes 32-bit values correctly so as to be
    > compatible with the output of a native 32-bit kernel.

    Just did it...

    > It's doubtful that rolling your own single loop actually performs better
    > than just calling strlen and memcpy.

    I didn't do it for speed, rather for simplicity.

    > Since you're just counting to estimate the size of a temporary buffer,
    > you could skip the initial loop and just estimate based on mm->map_count.
    > Then collect the count in the main loop and write the first word of the
    > buffer last.

    The format is:

    long count -- how many files are mapped
    long page_size -- units for file_ofs
    array of [COUNT] elements of
    long start
    long end
    long file_ofs
    followed by COUNT filenames in ASCII: "FILE1" NUL "FILE2" NUL...

    In order to fill in file names, we need to know exact number of array elements,
    since file names immediately follow that array. IOW:

    + for (vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
    + if (it is a file-backed vma)
    + count++;
    + }
    +
    + size = count * 64;
    + word_count = 2 + 3 * count; <=====
    ...
    + name = (void*)&start_end_ofs[word_count]; <=====

    The marked statements are crucial. We can't use estimated count,
    we need exact one here in order for 'name' pointer to be correct.

    Otherwise (if we would use count = mm->map_count),
    we'd need to memmove block of file names at the end.
    And we might end up allocating significant amounts of memory
    we don't need if there are tons of anon mappings.
    IMO this is worse than the counting loop.

    Anyway, I will shortly send a patch which implements your logic.
    --
    vda


    \
     
     \ /
      Last update: 2012-09-19 20:01    [W:3.617 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site