Unix Programming - mmap() ---- Invalid argument(EINVAL) error ..?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > September 2005 > mmap() ---- Invalid argument(EINVAL) error ..?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author mmap() ---- Invalid argument(EINVAL) error ..?
Vinu

2005-09-20, 7:49 am

Hi
I am using mmap() like this my intension is to allocate (mSize)memory
with no memory protection and without file descriptor like this:

pBase =(Ptr) mmap(0, mSize,PROT_NONE,MAP_ANONYMOUS,0,0);

but I am getting an error Invalid argument(EINVAL). Can anybody give
the correct way of doing this? I am using gcc in SOLARIS environment.

Thanks,
Vinu

Casper H.S. Dik

2005-09-20, 7:49 am

"Vinu" <vinuwarrier@yahoo.com> writes:

>Hi
> I am using mmap() like this my intension is to allocate (mSize)memory
>with no memory protection and without file descriptor like this:


> pBase =(Ptr) mmap(0, mSize,PROT_NONE,MAP_ANONYMOUS,0,0);


>but I am getting an error Invalid argument(EINVAL). Can anybody give
>the correct way of doing this? I am using gcc in SOLARIS environment.



The file descriptor needs to be -1 when you want anonymous memory
from the paging system.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Vinu

2005-09-20, 7:49 am

I used it in this way also

pBase =(Ptr) mmap(0, mSize,PROT_NONE,MAP_ANONYMOUS,-1,0); still the
result(error) is same Invalid argument(EINVAL).

Casper H.S. Dik

2005-09-20, 7:49 am

"Vinu" <vinuwarrier@yahoo.com> writes:

>I used it in this way also


>pBase =(Ptr) mmap(0, mSize,PROT_NONE,MAP_ANONYMOUS,-1,0); still the
>result(error) is same Invalid argument(EINVAL).



What's "mSize"? Oh, you need to specify exactly one of
MAP_SHARED or MAP_PRIVATE.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Vinu

2005-09-20, 7:49 am

Hi,

mSize is the size which I want to allocate
When I used it like this

pBase =(Ptr) mmap(0, mSize,PROT_NONE,MAP_PRIVATE,-1,0); the error is

EBADF(Bad file number)

Thanks,
Vinu

Paul Pluzhnikov

2005-09-20, 6:05 pm

"Vinu" <vinuwarrier@yahoo.com> writes:

Please use cross-posting instead of multi-posting.

> mSize is the size which I want to allocate


Casper knows *that*. What he asks is what is the *value* of mSize?

> When I used it like this
>
> pBase =(Ptr) mmap(0, mSize,PROT_NONE,MAP_PRIVATE,-1,0); the error is
>
> EBADF(Bad file number)


That's right. If you want to use -1 as the fd, you *must* have
MAP_ANONYMOUS in the flags.

Try this:

pBase = (Ptr)mmap(0, mSize, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com