mmap possible?!

bridged with qdn.public.porting
Post Reply
Martin Halle

mmap possible?!

Post by Martin Halle » Tue Feb 18, 2003 9:19 am

Dear NG,

I am trying to "play around" with memory maps on QNX 6.2. I tried to compile
the sample-code below (as mmapdemo.c). The compiler doesn't state a warning.
Also the program runs perfectly on Linux systems.

However, starting the application on QNX gives as output:
mmap: Not supported.

My question is: Am I doing something wrong, or is this feature really not
supported by the QNX? But why isn't this stated in the libc-documentation?

With regards,

Martin Halle.

--- Here is the code...

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>

int main(int argc, char *argv[])
{
int fd, offset;
char *data;
struct stat sbuf;

if (argc != 2) {
fprintf(stderr, "usage: mmapdemo offset\n");
exit(1);
}

if ((fd = open("mmapdemo.c", O_RDONLY)) == -1) {
perror("open");
exit(1);
}

if (stat("mmapdemo.c", &sbuf) == -1) {
perror("stat");
exit(1);
}

offset = atoi(argv[1]);
if (offset < 0 || offset > sbuf.st_size-1) {
fprintf(stderr, "mmapdemo: offset must be in the range 0-%d\n",
sbuf.st_size-1);
exit(1);
}

if ((data = mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED, fd,
0)) == (caddr_t)(-1)) {
perror("mmap");
exit(1);
}

printf("byte at offset %d is '%c'\n", offset, data[offset]);

return 0;
}

Guest

Re: mmap possible?!

Post by Guest » Tue Feb 18, 2003 12:40 pm

martin.halle@gmx.net sed in <b2st0v$hln$1@inn.qnx.com>:
if ((fd = open("mmapdemo.c", O_RDONLY)) == -1) {
if ((data = mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED, fd,
0)) == (caddr_t)(-1)) {
Current QNX can't map a plain file. Q.E.D


The reason is understandable, given the realtime requirements.
I don't expect it will support mapping plainfile anytime soon.
--
kabe

David Gibbs

Re: mmap possible?!

Post by David Gibbs » Tue Feb 18, 2003 1:49 pm

Martin Halle <martin.halle@gmx.net> wrote:
Dear NG,

I am trying to "play around" with memory maps on QNX 6.2. I tried to compile
the sample-code below (as mmapdemo.c). The compiler doesn't state a warning.
Also the program runs perfectly on Linux systems.
This may or may not work depending on whether the underlieing resource
manager supports mmap().

With the "normal" QNX4 filesystem, I think this will work if you add
MAP_NOSYNCFILE to the mmap() call.

(But, the mmap access and other (open/read/write) access will not neccessarily
be kept in sync with each other.)

-David
--
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Bill Caroselli

Re: mmap possible?!

Post by Bill Caroselli » Tue Feb 18, 2003 6:24 pm

David Gibbs <dagibbs@qnx.com> wrote:
Martin Halle <martin.halle@gmx.net> wrote:
Dear NG,

I am trying to "play around" with memory maps on QNX 6.2. I tried to compile
the sample-code below (as mmapdemo.c). The compiler doesn't state a warning.
Also the program runs perfectly on Linux systems.

This may or may not work depending on whether the underlieing resource
manager supports mmap().

With the "normal" QNX4 filesystem, I think this will work if you add
MAP_NOSYNCFILE to the mmap() call.

(But, the mmap access and other (open/read/write) access will not neccessarily
be kept in sync with each other.)
Just curious.

If/when this *is* working, does it imply that the entire file is kept in
RAM? Or is there some funny stuff going on with memory faults and then
reading new chunks of the file into RAM?

Martin Halle

Re: mmap possible?!

Post by Martin Halle » Wed Feb 19, 2003 8:58 am

Dear David (and others),
With the "normal" QNX4 filesystem, I think this will work if
you add MAP_NOSYNCFILE to the mmap() call.
This indeed works.
(But, the mmap access and other (open/read/write) access will
not neccessarily be kept in sync with each other.)
....but I'm not sure yet, if this might be a no-go criteria.
However - thanks for your reply.

With regrards,

Martin Halle.

Guest

Re: mmap possible?!

Post by Guest » Wed Feb 19, 2003 10:13 pm

dagibbs@qnx.com sed in <b2tdl3$6m5$1@nntp.qnx.com>:
With the "normal" QNX4 filesystem, I think this will work if you add
MAP_NOSYNCFILE to the mmap() call.
Woops. I was trying on 6.1; yes 6.2 seems to support mapping plainfile
but you still need (nonportable) MAP_NOSYNCFILE.

On further digging, Igor's patch on
<http://www.faqchest.com/prgm/apach-l/ap ... 03098.html>
says add MAP_ELF for workaround;
testing MAP_PRIVATE|MAP_NOSYNCFILE|MAP_ELF on 6.1 seems to work too.


Is there any issues on future platforms by these flags?
--
kabe

Post Reply

Return to “qdn.public.porting”