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 ..?
|
|
|
| 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:57 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.
| |
|
| 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:57 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.
| |
|
| 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, 7:02 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.
|
|
|
|
|