mmap possible?!

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;
}

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

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.

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?

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.

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/apach-01/apach-0111/apach-011114/apach01111500_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