ShM. Shared Memory - JulTob/Ada GitHub Wiki

16.20 Shared Memory

Shared Memory Flags IPC_CREAT Create new shared memory block IPC_EXCL plus read, write and execute bits.

IPC_PRIVATE indicates no key is supplied.

function shmget( key : key_t; bytes : integer; shmflag : integer ) return integer; pragma import( C, shmget ); Key is an id you supply to identify the memory (or IPC_PRIVATE for no key). bytes is the minimum amount of memory that you need. shmflag indicates options for this call. Returns -1 on error, or an id for the memory. Example: shmid := shmget( mykey, 4096, IPC_CREAT+IPC_EXCL+8#0660#);

function shmat( result : out system.address; shmid : integer; shmaddr : system.address; shmflag : integer ) return system.address; pragma import( C, shmat ); Shared memory attach. Makes shared memory accessible by returning a pointer to it. shmid is the id returned by shmget. if shmaddr isn't zero, the kernel will the address you give instead of chosing one itself. shmflags are additional options. Returns the address of the shared memory, or an address of -1 for an error. Example: shmat( ShmCPtr, myID, To_Address( null ), 0 ); ShmPtr := To_Address( ShmCPtr );

SHM_RDONLY - this memory is read-only (that is, as if it was constant ). SHM_RND - allows your shmaddr to be truncated to a virtual memory page boundary.

function shmdt( shmaddr : system.address ) return integer; pragma import( C, shmdt ); Shared memory detach. Removes the association of the shared memory to the pointer. Returns 0 if the memory was detached, -1 for failure. Example: Result := shmdt( To_Address( ShmPtr ) );

function shmctl( shmid : integer; cmd : integer; info : system.address) return integer; pragma import( C, shmctl ); Performs miscellaneous shared memory functions, including deallocating shared memory allocated with shmget. Returns 0 if the function was successful, or -1 for a failure. Example: Result := shmctl( myID, IPC_RMID, To_Address( null) );

IPC_RMID - deallocate shared memory