You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by sidinsd <si...@ga.com> on 2011/08/12 15:31:48 UTC

Emulation of /dev/zero on Windows

APR is supposed to let you do UNIX things on Windows. Does it support
/dev/zero? In other words if I do an apr_file_open("/dev/zero", ...) will I
then get zeros when I read from that file, like I do on UNIX?
-- 
View this message in context: http://old.nabble.com/Emulation-of--dev-zero-on-Windows-tp32250236p32250236.html
Sent from the APR Dev (Apache Portable Runtime) mailing list archive at Nabble.com.


Re: Emulation of /dev/zero on Windows

Posted by "William A. Rowe Jr." <wr...@rowe-clan.net>.
On 8/12/2011 11:19 AM, sidinsd wrote:
> 
> I just read the doc for "MapViewOfFile" and I quote it below;
> 
> If a file mapping object is backed by the paging file (CreateFileMapping is
> called with the hFile parameter set to INVALID_HANDLE_VALUE), the paging
> file must be large enough to hold the entire mapping. If it is not,
> MapViewOfFile fails. The initial contents of the pages in a file mapping
> object backed by the paging file are 0 (zero). 

Precisely.  But the pages returned are from the unallocated memory, never
allocated memory!  Think of this as a cross-process calloc() where you
haven't named a specific backing store.  This is true on unix as well.

APR offers no means to access memory allocated by other processes, if that
is what you are trying to accomplish.

Re: Emulation of /dev/zero on Windows

Posted by sidinsd <si...@ga.com>.
I just read the doc for "MapViewOfFile" and I quote it below;

If a file mapping object is backed by the paging file (CreateFileMapping is
called with the hFile parameter set to INVALID_HANDLE_VALUE), the paging
file must be large enough to hold the entire mapping. If it is not,
MapViewOfFile fails. The initial contents of the pages in a file mapping
object backed by the paging file are 0 (zero). 

So, it seems like in order for APR to support MAP_ANON they would have to
use the Windows APIs as specified above, but I don't think they do. Is there
any thought of APR supporting the MAP_ANON feature of mmap?


sidinsd wrote:
> 
> Thank you for the reply, but I am not as technically knowledgeable as you,
> so I really do not know what the words "previously cross-process,
> unallocated swap-backed heap" mean. I was under the impression that the
> MAP_ANON feature of mmap is just like opening an mmap with an fd that
> points to /dev/zero. So, in other words, any memory that you reference
> using the pointer that mmap returns to you will be initialized to zeros.
> Is that true of the pointer returned by apr_mmap_create under Windows?
> From what I could see, APR uses the Windows APIs CreateFileMapping and
> MapViewOfFile to emulate the mmap function and I don't believe those APIs
> support the zeroing of the memory they obtain, but I'm not really sure of
> that, which is why I am asking the question.
> 
> William A. Rowe Jr. wrote:
>> 
>> On 8/12/2011 9:23 AM, sidinsd wrote:
>>> 
>>> Since APR does not support /dev/zero, but it does support Memory Mapping
>>> of
>>> files (see apr_mmap_create, etc.) how does it support the MAP_ANONYMOUS
>>> feature of the mmap function?
>> 
>> It returns previously cross-process, unallocated swap-backed heap.
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Emulation-of--dev-zero-on-Windows-tp32250236p32251635.html
Sent from the APR Dev (Apache Portable Runtime) mailing list archive at Nabble.com.


Re: Emulation of /dev/zero on Windows

Posted by sidinsd <si...@ga.com>.
Thank you for the reply, but I am not as technically knowledgeable as you, so
I really do not know what the words "previously cross-process, unallocated
swap-backed heap" mean. I was under the impression that the MAP_ANON feature
of mmap is just like opening an mmap with an fd that points to /dev/zero.
So, in other words, any memory that you reference using the pointer that
mmap returns to you will be initialized to zeros. Is that true of the
pointer returned by apr_mmap_create under Windows? From what I could see,
APR uses the Windows APIs CreateFileMapping and MapViewOfFile to emulate the
mmap function and I don't believe those APIs support the zeroing of the
memory they obtain, but I'm not really sure of that, which is why I am
asking the question.

William A. Rowe Jr. wrote:
> 
> On 8/12/2011 9:23 AM, sidinsd wrote:
>> 
>> Since APR does not support /dev/zero, but it does support Memory Mapping
>> of
>> files (see apr_mmap_create, etc.) how does it support the MAP_ANONYMOUS
>> feature of the mmap function?
> 
> It returns previously cross-process, unallocated swap-backed heap.
> 
> 

-- 
View this message in context: http://old.nabble.com/Emulation-of--dev-zero-on-Windows-tp32250236p32251583.html
Sent from the APR Dev (Apache Portable Runtime) mailing list archive at Nabble.com.


Re: Emulation of /dev/zero on Windows

Posted by "William A. Rowe Jr." <wr...@rowe-clan.net>.
On 8/12/2011 9:23 AM, sidinsd wrote:
> 
> Since APR does not support /dev/zero, but it does support Memory Mapping of
> files (see apr_mmap_create, etc.) how does it support the MAP_ANONYMOUS
> feature of the mmap function?

It returns previously cross-process, unallocated swap-backed heap.

Re: Emulation of /dev/zero on Windows

Posted by sidinsd <si...@ga.com>.
Thank you.

Jeff Trawick wrote:
> 
> On Fri, Aug 12, 2011 at 10:23 AM, sidinsd <si...@ga.com> wrote:
>>
>> OK, I'm sorry you seem to have take such offense to my message, I didn't
>> mean
>> it to be disparaging or argumentative in any way, I'm just trying to
>> obtain
>> information.
> 
> ditto, only I'm trying to help
> 
> 

-- 
View this message in context: http://old.nabble.com/Emulation-of--dev-zero-on-Windows-tp32250236p32250756.html
Sent from the APR Dev (Apache Portable Runtime) mailing list archive at Nabble.com.


Re: Emulation of /dev/zero on Windows

Posted by Jeff Trawick <tr...@gmail.com>.
On Fri, Aug 12, 2011 at 10:23 AM, sidinsd <si...@ga.com> wrote:
>
> OK, I'm sorry you seem to have take such offense to my message, I didn't mean
> it to be disparaging or argumentative in any way, I'm just trying to obtain
> information.

ditto, only I'm trying to help

Re: Emulation of /dev/zero on Windows

Posted by sidinsd <si...@ga.com>.
OK, I'm sorry you seem to have take such offense to my message, I didn't mean
it to be disparaging or argumentative in any way, I'm just trying to obtain
information.

Since APR does not support /dev/zero, but it does support Memory Mapping of
files (see apr_mmap_create, etc.) how does it support the MAP_ANONYMOUS
feature of the mmap function?


Jeff Trawick wrote:
> 
> On Fri, Aug 12, 2011 at 9:31 AM, sidinsd <si...@ga.com> wrote:
>>
>> APR is supposed to let you do UNIX things on Windows.
> 
> APR is designed to provide a reasonable feature set which works the
> same on all supported platforms.  It is not designed to let you do
> Unix things on Windows or vice versa.
> 
>>         Does it support
>> /dev/zero? In other words if I do an apr_file_open("/dev/zero", ...) will
>> I
>> then get zeros when I read from that file, like I do on UNIX?
> 
> no
> 
>> --
>> View this message in context:
>> http://old.nabble.com/Emulation-of--dev-zero-on-Windows-tp32250236p32250236.html
>> Sent from the APR Dev (Apache Portable Runtime) mailing list archive at
>> Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Born in Roswell... married an alien...
> 
> 

-- 
View this message in context: http://old.nabble.com/Emulation-of--dev-zero-on-Windows-tp32250236p32250714.html
Sent from the APR Dev (Apache Portable Runtime) mailing list archive at Nabble.com.


Re: Emulation of /dev/zero on Windows

Posted by Jeff Trawick <tr...@gmail.com>.
On Fri, Aug 12, 2011 at 9:31 AM, sidinsd <si...@ga.com> wrote:
>
> APR is supposed to let you do UNIX things on Windows.

APR is designed to provide a reasonable feature set which works the
same on all supported platforms.  It is not designed to let you do
Unix things on Windows or vice versa.

>         Does it support
> /dev/zero? In other words if I do an apr_file_open("/dev/zero", ...) will I
> then get zeros when I read from that file, like I do on UNIX?

no

> --
> View this message in context: http://old.nabble.com/Emulation-of--dev-zero-on-Windows-tp32250236p32250236.html
> Sent from the APR Dev (Apache Portable Runtime) mailing list archive at Nabble.com.
>
>



-- 
Born in Roswell... married an alien...