This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: mmap() on 64K aligned address fails


Samuel Thibault wrote:
[snip]
>>No, in windows there is a requirement that mmap uses memory aligned to 64k (the
>>infamous granularity).
> 
> Then the result of pagesize() is not sufficiently big: POSIX says that
> mmap() can return EINVAL if « the address [...] is not a multiple of
> the page size, or is considered invalid by the implementation ». Well,
> we could consider non-16-pages-alignment as `considered invalid', but I
> guess this expression was meant as `not in a mmap()-able area'.

mmap() is returning an error code, probably EINVAL I just ddisn't care to look
what was it because there shouldn't be an error.

[snip]
> 16 pages
> are still not enough: if malloc() returns 0x0001 for instance, you'll
> round up that to 16*pagesize, which is out the allocated area. 17 pages
> are necessary.

Yes, that would produce an error... not the one you are saying but the "aligned"
result will fall at the end with less than a pagesize available for mmap.

> BTW, I don't understand why using so complicated code:
> p += (align - ((long) p & (align-1))) & (align-1)
> Isn't
> p = ((long) p + (align-1)) & (align-1)
> both faster (tested) and more readable ?

I didn't write the original code, it is from gcc-4.0.2 and it's used all over
the place to make libraries (libstdc, libgcj, perhaps others) and tools.  There
are other mmap() tests that fail (mmap from /dev/zero, mmap with MAP_ANON) I'm
just starting to look around to see what is the problem, and perhaps send a
patch to the gcc maintainers so we can have a fully functional set of libraries.

Regards.
-- 
René Berber


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]