[Gambas-bugtracker] Bug #2534: Libc mmap() call always returns -1
bugtracker at gambaswiki.org
bugtracker at gambaswiki.org
Sat Apr 30 22:23:12 CEST 2022
http://gambaswiki.org/bugtracker/edit?object=BUG.2534&from=L21haW4-
Comment #8 by Brian G:
Here is a summary of what I am using that seems to work well.
using pointers
Extern mmap(MapPoint As Pointer, MapLength As Integer, prot As Integer, flags As Integer, fd As Integer, offset As Integer) As Pointer In "libc:6"
Extern munmap(MapPoint As Pointer, MapLength As Integer) As Integer In "libc:6"
Extern shm_open(name As String, oflag As Integer, mode As Integer) As Integer In "librt:1"
Extern shm_unlink(name As String) As Integer In "librt:1"
Extern ftruncate(FileHandle As Integer, length As Integer) As Integer In "libc:6"
Static Private MemoryStorage As Pointer = Null ' actual storage address
Static Public NamedMemHandle As Integer = -1 ' Handle of the named memory area
NamedMemHandle = shm_open(MemName, O_CREAT Or O_RDWR Or O_EXCL, &O666) ' return an error if its already there
If NamedMemHandle = -1 Then
NamedMemHandle = shm_open(MemName, O_RDWR, &O666)
If NamedMemHandle = -1 Then
Error.Raise("Unable to open Named Shared Memory" & MemName & " " & Str(System.error) & " " & String@(strerror(System.error)))
Return False
Endif
else
If ftruncate(NamedMemHandle, MemSize + SharedMemoryControlHeader) = -1 Then
Error "Unable to create the storage area for variables" & MemName & " " & Str(System.error) & " " & String@(strerror(System.error))
rClose(NamedMemCollectionHandle)
rClose(NamedMemHandle)
shm_unlink(MemName)
shm_unlink(ColName)
Error.Raise("Unable to create the storage area for variables" & MemName & " " & Str(System.error) & " " & String@(strerror(System.error)))
Endif
Endif
'my interface supports named and unnammed memory
If NamedMemHandle = -1 Then
MemoryStorage = mmap(Null, BlockSize, (PROT_READ Or PROT_WRITE), (MAP_SHARED Or MAP_ANONYMOUS), NamedMemHandle, 0) 'Or MAP_ANONYMOUS
Else
MemoryStorage = mmap(Null, BlockSize, (PROT_READ Or PROT_WRITE), MAP_SHARED, NamedMemHandle, 0) 'Or MAP_ANONYMOUS
Endif
Hope this helps!
More information about the Bugtracker
mailing list