lkml.org 
[lkml]   [2005]   [Oct]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: Understanding Linux addr space, malloc, and heap
    From
    Date
    On Fri, 2005-10-21 at 11:11 -0400, Vincent W. Freeh wrote:
    > Arjan van de Ven wrote:
    > > On Fri, 2005-10-21 at 09:45 -0400, Vincent W. Freeh wrote:
    > >
    > >>Thanks for your quick response. It basically confirmed that I observed
    > >>what I thought I did. However, I am no closer to solving my problem. I
    > >>cannot mprotect data that I malloc beyond the first 65 pages.
    > >
    > >
    > > you can't mprotect malloc() memory period ..
    >
    > Actually, I can and do. Simple program at end.
    >
    > >
    > >> Why is
    > >>that? Can that be fixed? Second, why does mprotect silently fail? I
    > >>could live with it failing--but I cannot deal with a call the "works"
    > >>but doesn't work.
    > >
    > >
    > > need more info :)
    > >
    >
    > I call mprotect and it return 0--meaning it succeeded. But the
    > permissions on the page remain rw. So it fails to change the
    > permissions, but doesn't give any indication of this.
    >
    > Thanks,
    > vince.
    >
    > ------------------
    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <sys/mman.h>
    > #include <unistd.h>
    >
    > int main(int argc, char *argv[])
    > {
    > void *p;
    > int pgsize = getpagesize();
    >
    > p = malloc(1024);
    > mprotect((void*)((unsigned)p & ~(pgsize-1)), 1024, PROT_NONE);
    > printf("\t*p = %d\n", *(int *)p);
    > return 0;
    > }

    This program is completely screwed. Read the mprotect man page in
    particular the examples section has an example of how to do your program
    correctly.

    Best regards,

    Anton
    --
    Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
    Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
    Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
    WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-10-21 17:22    [W:0.024 / U:0.612 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site