Re: [boost] [bug report]boost-sandbox.interprocess::mapped_region.hpp

Hi, another problems in the same file. A) problem of align because mmap() requires: 1. offset should be a multiple of page size 2. the address start must be a multiple of page size. we have to align the offset and start to page size. for code snip begin from line 444, ===================================== if(address){ address = static_cast<const char*>(address) - m_extra_offset; } ===================================== you make a wrong alignment for address. for example construct a mapped_region object with offset=1 and address=0x3f000002. m_extra_offset is 1, and calculated address is 0x3f000001 which is not page size aligned. another member variable have to imported to record the offset of address and m_base. B) problem of m_size under windows in some case, the m_size is zero (0) under windows. code snipp begin at line 327 (mapped_region::flush) ===================================== if(numbytes == 0) { numbytes = m_size - offset; } ===================================== if m_size is 0, numbytes is a negative. for the problem A, I do suggest m_base/m_offset is the real value not adjusted value. then we just adjust this value in get_size()/get_address()/get_offset() like this: get_size() { if(m_size == 0) return m_size; return m_size - m_extra_offset; } get_address() { return static_cast<char* >(m_base) + m_extra_offset; } get_offset() { return m_offset + m_extra_offset; } Best Regards, Wilbur Lang

Wilbur Lang wrote:
Hi,
another problems in the same file.
A) problem of align because mmap() requires: 1. offset should be a multiple of page size 2. the address start must be a multiple of page size. we have to align the offset and start to page size.
for code snip begin from line 444, ===================================== if(address){ address = static_cast<const char*>(address) - m_extra_offset; } =====================================
you make a wrong alignment for address.
for example construct a mapped_region object with offset=1 and address=0x3f000002. m_extra_offset is 1, and calculated address is 0x3f000001 which is not page size aligned. another member variable have to imported to record the offset of address and m_base.
The result is that the user specifies both wrong address and offset (both should be page_size aligned) and the call fails. I don't see why Interprocess should try to support that. The user wants to map offset 1 in address 0x3f000002 and that will always fail. This is equivalent to what the code tries: map offset 0 to 0x3f000001. And this will fail according to POSIX (and Interprocess), so I don't see any problem. What Interprocess can do at the top of the function is to check both parameters to see if they are properly aligned and throw an error if any of them is not correctly aligned. But I think current code will do the same (throw an error).
B) problem of m_size under windows in some case, the m_size is zero (0) under windows.
code snipp begin at line 327 (mapped_region::flush) ===================================== if(numbytes == 0) { numbytes = m_size - offset; } ===================================== if m_size is 0, numbytes is a negative.
Ok. Thanks. Regards, Ion
participants (2)
-
Ion Gaztañaga
-
Wilbur Lang