httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Korb <>
Subject Re: apr mmap/ & shm/ problem.
Date Wed, 29 Jun 2005 22:41:14 GMT
Michael Vergoz wrote:
 > Hi Bruce,
 > Yes
Thank you!

 > because you must align the page to the biggest you can.

??  The problem is is that no matter how you align the thing,
if the last byte of the file is the last byte of a page,
then the next byte is unmapped.  Consequently, when "strlen(3C)"
tries to determine if the next byte after the last valid byte
is NUL or not, it faults on a bad memory reference.  There
are several solutions:

Punt mmap and just read the file into an allocated buffer.

mmap the file then figure out if the last byte is the last
byte of a page.  If so, then mmap anonymous memory into
the fixed address following the last page of the text file.
I do this, but it is a real pain.  I hate it.  :-)  Most
often, I just allocate and read the file 'cuz it is easier.

 > Have a look at :
 > Into function apr_mem_pager() :
 > if you need 0x2001 (Size).
 > <snip>
 > 	ret = size; // ret = 0x2001
 > 	if((ret%_apr_mem_page_size) != 0) { // 0x0001
 > 		ret -= (ret%_apr_mem_page_size); // ret -= 0x0001 = 0x2000
 > 		ret += _apr_mem_page_size*map->pager; // ret += 0x1000*PAGER
 > 	}
 > </snip>

Right.  If "size" is 0x2000 exactly, the byte following the
mapping will be unmapped and "strlen(3C)" will fault.
That's the problem.

 > You may have a look at apr_mem_remap(). It will allow you to ask for a
 > unaligned address. Then the engine will auto update the address alignment
 > with a predefined pager (defined by the pager argument in apr_mem_map()).

OK.  So, if I check the file size and it is a multiple of a page size,
then I should ask for non-aligned mapping, otherwise an aligned mapping?
Better than messing around with anonymous pages on my own, but still.....

Thanks.  Regards, Bruce

View raw message