Open System Services System Calls Reference Manual (G06.25+, H06.03+)
System Functions (s and S) shmat(2)
NAME
shmat - Attaches a shared memory segment to the address space of the calling process
LIBRARY
G-series native OSS processes: /G/system/sysnn/zossksrl
H-series OSS processes: /G/system/zdllnnn/zosskdll
SYNOPSIS
#include <sys/shm.h>
void *shmat(
int shmid,
const void *shmaddr,
int shmflag);
PARAMETERS
shmid Specifies the identifier for the shared memory segment. The identifier is usually
returned by a previous call to the shmget() function.
shmaddr Specifies the virtual address at which the process wants to attach the shared
memory segment. The process can also specify 0 (zero) to have the system
select an appropriate address.
shmflag Specifies the following attach flags:
SHM_RND If the shmaddr parameter is not a null pointer, the system rounds
off the address, if necessary.
SHM_RDONLY
The current release of OSS does not support read-only access. If
the calling process has read permission, the system attaches the
segment for both reading and writing.
DESCRIPTION
The shmat() function attaches the shared memory segment identified by the shmid parameter to
the virtual address space of the calling process. For the shmaddr parameter, the process can
specify an explicit address, or it can specify a null pointer to have the system select the address.
If an explicit address is used and (shmflag & SHM_RND) is not zero, the system attempts to
attach the segment at the address given by (shmaddr -((ptrdiff_t)shmaddr % SHMLBA)). The
character % is the C-language modulus (remainder) operator.
If an explicit address is used and (shmflag & SHM_RND) is 0 (zero), the system attempts to
attach the segment at the address given by shmaddr.
The current release of OSS does not support read-only access. The segment is attached for read-
ing and writing if (shmflag & SHM_RDONLY) is not zero and the calling process has read per-
mission. If (shmflag & SHM_RDONLY) is 0 (zero) and the calling process has read and write
permission, the segment is attached for reading and writing.
Memory can be shared only within the same processor.
Shared memory uses operating system flat segments (permanently mapped shareable data seg-
ments). Refer to the Guardian Programmer’s Guide for more information about flat segments.
Address Range
An application that is using the shared memory functions shmat() and shmdt() to manage a
range of virtual addresses should use only these functions to manipulate the range.
The valid range of addresses for the shmaddr parameter can change from one release to the next.
Programs should not contain hard-coded addresses.
527186-003 Hewlett-Packard Company 7−45