On Fri, Feb 12, 2010 at 10:48:00AM +0300, Vadim Zhukov wrote:
> On 12 February 2010 P3. 03:31:22 Jordi Beltran Creix wrote:
> > Wouldn't that return EINVAL unless the address is aligned to the page
> > boundary?
> 
> >From the man page:
> "The OpenBSD implementation of mprotect() does not require addr to be
> page-aligned". And code is agree, too.
> 
> But the problem is not with the address itself, it's all about how to
> treat 0 passed as "len" parameter. I didn't checked behavior of other
> *BSD, but their mprotect(2) pages do not say anything about treating 0
> in "len" parameter at all. Linux manual is most clear: "The function
> mprotect specifies the desired protection for the memory page(s)
> containing part or all of the interval [addr,addr+len-1]".

I'm confused about the "[addr,addr+len-1]", cause based on
above wording (from Linux manual per you), len = 0 produces
a strange range.

As you specified in your original post, SUS says:

        | The function mprotect() changes the access protections
        | to be that specified by prot for those whole pages
        | containing any part of the address space of the
        | process starting at address addr and continuing for
        | len bytes.

So if len = 0, then no pages are protected based on that
wording. Which, is what the OpenBSD man page says assuming
there was a typo and the word "no" is missing in the sentence:

        | If len is 0, then action will be taken on the page
        | that contains addr.

(should read)

        | If len is 0, then no action will be taken on the page
        | that contains addr.

--patrick

Reply via email to