[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
    Arjan van de Ven wrote:
    > On Fri, 2005-10-21 at 16:37 +0100, Alex Bligh - linux-kernel wrote:
    >>--On 21 October 2005 17:22 +0200 Arjan van de Ven <>
    >>>Ok I meant in the "while adhering to the standard" :)
    >>More precisely, as per the man page:
    >>>POSIX.1b says that mprotect can be used only on regions of memory
    >>>obtained from mmap(2).
    >>But what is interesting (if anything) is this:
    >>> EINVAL addr is not a valid pointer, or not a multiple of
    >>> PAGESIZE.
    >>So if he calls mprotect with memory allocated by malloc (which should
    >>fail), why doesn't he get EINVAL? He says it returns 0 (meaning it
    >>succeeded). Which it shouldn't (unless he is stupendously lucky in
    >>malloc's allocation, in which case it should work).
    > it succeeds all right; it just does other things than you expect
    > perhaps ;)
    > your alignment code had a bug, so it would align potentially to the
    > wrong piece of memory

    Actually, it should give a SIGSEGV for the first byte allocated,
    although I agree that it might not work for any other byte allocated in
    the case where malloc returns a pointer just at the end of a page.

    I just tested the sample code and in fact I do get a SIGSEGV.

    What kernel version / architecture are you testing this on?

    Paulo Marques
    Software Development Department - Grupo PIE, S.A.
    Phone: +351 252 290600, Fax: +351 252 290601

    The rule is perfect: in all matters of opinion our
    adversaries are insane.
    Mark Twain
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-10-21 18:01    [W:0.021 / U:4.440 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site