[Gambas-bugtracker] Bug #2534: Libc mmap() call always returns -1

bugtracker at gambaswiki.org bugtracker at gambaswiki.org
Fri Apr 29 02:39:40 CEST 2022


http://gambaswiki.org/bugtracker/edit?object=BUG.2534&from=L21haW4-

Comment #3 by Gary SPRANG:

Benoit, thanks for the quick reply.  You are correct, I was looking for the -1 return value, so I could have the app stop if mmap() didn't work.
Brian, I will study the examples you pointed me to.  What I need is a method for Gambas to connect to an existing shared memory segment.
I ran an Strace on my code, I got this - 
openat(AT_FDCWD, "/dev/shm/SHM_SEG", O_RDWR|O_NOFOLLOW|O_CLOEXEC) = 14

mmap(NULL, 1048576, PROT_READ|PROT_WRITE, 0x4 /* MAP_??? */, 14, 0) = -1 EINVAL (Invalid argument)

The possible values for the flags are: 
MAP_SHARED = 4
MAP_PRIVATE = 2
MAP_FIXED = 1

Also, I discovered a boo-boo: permissions are usually shown in hex.  So I made a couple of changes to my Gambas code - 
new implementation:
  shm_fd = myshm_open(shm_id, &2, &600) ' 2=read/write  mode = perms
  If shm_fd == -1 Then
      Message.Info("shm_open() failed!", " OK ")
      Quit
  Endif
 ' map shared Memory To process address space
shm_addr = mymap(0, shm_size, protection, visibility, shm_fd, 0)' flags was 4 (MAP_SHARED)
mmap_err = shm_addr ' convert the pointer to an integer
If mmap_err < 1 Then
  Message.Info("mmap() failed!", " OK ")
  Quit
Endif

  shmaddr2 = shm_addr
And now it works, most of the time.  But I will study the examples.  Thanks!




More information about the Bugtracker mailing list