On Tuesday, October 12, 2010 22:06:29 CAI Qian wrote:
> ----- "Mike Frysinger" wrote:
> > On Tuesday, October 12, 2010 10:07:16 CAI Qian wrote:
> > > + x = mmap("/dev/zero", SIZE+SIZE-4096, PROT_READ|PROT_WRITE,
> > > + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
> >
> > uhh, have you even checked this test ? this mmap() makes absolutely
> > no sense on so many levels.
>
> Can you elaborate?
so you havent actually looked at the syscalls made by the application and the
memory maps created nor used mmap() in detail before ? well, let's start with
the mmap() man page:
void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);
"addr" doesnt sound like "file name" to me, and the description agrees:
If addr is not NULL, then the kernel takes it as a hint about where to
place the mapping; on Linux, the mapping will be created at a nearby
page
boundary. The address of the new mapping is returned as the result of
the call.
so basically you told the kernel to create a mapping in/near your .rodata
section (since that is the address of the constant string "/dev/zero"). the
contents of that pointer (which is not of type "char *") have absolutely no
meaning to the kernel.
then there are the flags you're using:
MAP_ANONYMOUS
The mapping is not backed by any file; its contents are
initialized
to zero. The fd and offset arguments are ignored; however, some
implementations require fd to be -1 if MAP_ANONYMOUS (or
MAP_ANON)
is specified, and portable applications should ensure this.
so not only are you not getting a mapping from /dev/zero, you're just
allocating a random piece of memory that the kernel has guaranteed will be
zeroed out for you. so any attempts to verify the contents are zero *because
the data came from /dev/zero* fail.
finally, there's the fd which you're passing as "-1":
The contents of a file mapping (as opposed to an anonymous mapping; see
MAP_ANONYMOUS below), are initialized using length bytes starting at
offset "offset" in the file (or other object) referred to by the file
descriptor "fd".
"-1" is not a valid fd, so there's no way it could possibly be from /dev/zero.
so we're back where we started: this test makes no sense as written and you
apparently havent verified it "works" beyond "is the exit status 0 when it
finished".
> > why are you using _exit() ?
>
> It is used to terminate a child.
i meant why arent you using exit() ? why do you need _exit() semantics ?
-mike
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb
_______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
