need help about get errno [ENXIO] for mmap


 
Thread Tools Search this Thread
Top Forums Programming need help about get errno [ENXIO] for mmap
# 1  
Old 10-25-2011
need help about get errno [ENXIO] for mmap

from mmap manpage I get it's errors discription:
[ENXIO] The addresses specified by the range [off, off + len) are invalid
for filedes.

How could I trigger a ENXIO ? anyone can input the code?

Lei
# 2  
Old 10-25-2011
Assuming: mmap() call with MAP_FIXED. Probably for a character special file. You did not specify.

ENXIO: Now you are trying to reference something outside the bounds of the memory you mapped.... the device does not support what you are asking it to do. You can also get ENXIO when the device does not exist any longer.

Ex: you can mmap() a character special device but you cannot expect the driver to keep everything displayed on the device in memory.

Since you did not post your code - this is a guess on my part. Post code and we will help you. We need the mmap call, and the line(s) of code that generated ENXIO.
# 3  
Old 10-26-2011
Quote:
Originally Posted by jim mcnamara
Assuming: mmap() call with MAP_FIXED. Probably for a character special file. You did not specify.

ENXIO: Now you are trying to reference something outside the bounds of the memory you mapped.... the device does not support what you are asking it to do. You can also get ENXIO when the device does not exist any longer.

Ex: you can mmap() a character special device but you cannot expect the driver to keep everything displayed on the device in memory.

Since you did not post your code - this is a guess on my part. Post code and we will help you. We need the mmap call, and the line(s) of code that generated ENXIO.

thanks for the replay

[lyang0@pek-lpgbuild7 mmap]$ cat 18-1_test.c
Code:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

int main(void)

{
  int fd = -1;
  void *pa = NULL;
  void *addr = NULL;
  addr=0x10000;
  printf("addr is %p\n",addr);
  size_t len = 0;
  int prot = PROT_READ;
  int flag;
  off_t off = 0;
  long page_size = sysconf(_SC_PAGE_SIZE);
  len = 2 * page_size;
  off= (off_t)addr-page_size;

    if((fd = open("/bin/ls",O_RDONLY,0 )) < 0){
        printf("File open failed\n");
    }

  flag = MAP_SHARED;
  pa = mmap (addr, len, prot, flag, fd, off);
  printf("err is %d\n",errno);
  printf("len is %d\n",len);
  printf("off is %d\n",off);
  printf("add is %d\n",addr);
  close(fd);
}

the results is
[lyang0@pek-lpgbuild7 mmap]$ ./test
addr is 0x10000
err is 0
len is 8192
off is 61440
add is 65536


from the mmap discription:

[ENXIO] The addresses specified by the range [off, off + len) are invalid for filedes.

add is in [off, off + len), but I don't got ENXIO
# 4  
Old 10-26-2011
/bin/ls is a regular file, the ENXIO error usually arises on devices like tty's which are character sepcial files. Normally len should be the result of a stat() call, struct stat st_size for /bin/ls in this case, because you are reading a regular file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

mmap

I want to know whether this is possile or ever been tried out. I want to obtain a chuck of memory using mmap() I do it so : n = mmap(0, 8000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); And hold on to that memory, when a process requests for memory, some memory is... (2 Replies)
Discussion started by: xerox
2 Replies

2. UNIX for Advanced & Expert Users

Regarding MMAP, MLOCK etc..

Hi I want to lock or prevent a portion of memory which I allocated. So I tried MLOCK, MPROTECT and some like this. But all these functions works only on page border. Can I know why that so. Is that possible to protect a portion of memory which is in middle of the page. Example. int A; ... (1 Reply)
Discussion started by: jionnet
1 Replies

3. Programming

mmap

hai, How do we map 'n' number of files into memory by using mmap system call?? Thanks in advance...... (5 Replies)
Discussion started by: andrew.paul
5 Replies

4. Homework & Coursework Questions

mmap

Descriptions: Develop a program that uses mmap() to map a file to memory space. Prepare such a file by yourself and do the follows. <LI class=MsoNormal>Display the content of the file after mapping; <LI class=MsoNormal>Output how many digits included in the file; <LI class=MsoNormal>Replace... (1 Reply)
Discussion started by: gokult
1 Replies

5. Programming

mmap()

how to use mmap() to map a file to memory space. Do you have any simple program???? Because I have to implement lot of concepts into it. (5 Replies)
Discussion started by: gokult
5 Replies

6. UNIX for Dummies Questions & Answers

mmap()

how to use mmap() to map a file to memory space. Do you have any simple program???? Because I have to implement lot of concepts into it. (3 Replies)
Discussion started by: gokult
3 Replies

7. Solaris

mmap() on 64 bit m/c

Dear Experts, i have a problem related to mmap(), when i run my program on sun for 64 bit which is throwing SIGBUS when it encounters mmap() function, what is the reason how to resolve this one, because it is working for 32 bit. with regards, vidya. (2 Replies)
Discussion started by: vin_pll
2 Replies

8. UNIX for Advanced & Expert Users

mmap and select

I'm using select() to monitor multiple file descriptors (inet sockets) in application. But this application must also collaborate with other applications on the same host via shared memory (mmap'ed file) due to performance reasons. How can I become notification that mmaped memory is changed or... (1 Reply)
Discussion started by: Hitori
1 Replies

9. HP-UX

mmap failed

We recently have been seeing the following type of error on our development server. Being somewhat new to HP-UX I was hoping to get some insight. Here is what I have found. I have been doing some research. /usr/lib/dld.sl: Call to mmap() failed - TEXT /u07/mdev/lib/libCLEND.sl... (2 Replies)
Discussion started by: scotbuff
2 Replies

10. Filesystems, Disks and Memory

mmap

Hello. I'm writing some random access i/o software on Solaris 8 using mmap64 to memory map large files (my test file is ~25 GB). The abbreviated code fragment is: fd = open(cbuf,O_RDONLY|O_LARGEFILE); struct stat statbuf; fstat(fd,&statbuf); off_t len =... (0 Replies)
Discussion started by: gusm
0 Replies
Login or Register to Ask a Question