KEDEF(2)

NAME
kedef - SVID Kernel Extension definitions

DESCRIPTION
The SVID Kernel Extension provides three mechanisms for inter-process communication (IPC): messages, semaphores and shared-memory. This section defines some of the data structures employed.

IPC Permissions
All of the IPC mechanisms use a common structure type, ipc_perm, to pass information used in determining permission to perform an IPC operation.

The ipc_perm structure is defined by the header file <sys/ipc.h> and includes the following members:

    ushort	cuid;	/* creator's user id */
    ushort	cgid;	/* creator's group id */
    ushort	uid;	/* owner's user id */
    ushort	gid;	/* owner's group id */
    ushort	mode;	/* access permissions */

The following symbolic constants are also defined by the <sys/ipc.h> header file:

    IPC_CREAT	/* create entry if key does not exist */
    IPC_EXCL	/* fail if key exists */
    IPC_NOWAIT	/* error if request must wait */
    IPC_RMID	/* remove identifier */
    IPC_SET		/* set options */
    IPC_STAT	/* get options */
    IPC_PRIVATE	/* private key */

Message Queue Identifier
A message queue identifier msqid is a unique positive integer created by a call to the msgget(2) routine. Each msqid has a message queue and a data structure associated with it. The data structure is referred to as msqid_ds and contains the following members:

    struct	ipc_perm msg_perm;	/* operation permissions */
    ushort	msg_qnum;	/* number of messages on q */
    ushort	msg_qbytes;	/* max number of bytes on q */
    ushort	msg_lspid;	/* pid of last msgsnd operation */
    ushort	msg_lrpid;	/* pid of last msgrcv operation */
    time_t	msg_stime;	/* last msgsnd time */
    time_t	msg_rtime;	/* last msgrcv time */
    time_t	msg_ctime;	/* last change time */
    		/* Times in seconds since */
    		/* 00:00:00 GMT, 1st January 1970 */

msg_perm
    is an ipc_perm structure (see above) that specifies the message operation permission.

msg_qnum
    is the number of messages currently on the queue.

msg_qbytes
    is the maximum number of bytes allowed on the queue.

msg_lspid
    is the process id of the last process that performed a msgsnd operation.

msg_lrpid
    is the process id of the last process that performed a msgrcv operation.

msg_stime
    is the time of the last msgsnd operation.

msg_rtime
    is the time of the last msgrcv operation.

msg_ctime
    is the time of the last msgctl(2) operation that changed a member of the above structure.

Message Operation Permissions
In the msgop(2) and msgctl(2) system call descriptions, the permission required for an operation is given as a bit pattern in msg_perm.mode, where the type of permission needed is interpreted as follows:

    00400
        Read by user
    00200
        Write by user
    00040
        Read by group
    00020
        Write by group
    00004
        Read by others
    00002
        Write by others

Read and Write permissions on a msqid are granted to a process if one or more of the following are true:

    The effective user ID of the process is super-user.

    The effective user ID of the process matches msg_perm.cuid or msg_perm.uid in the data structure associated with msqid and the appropriate bit of the ``user'' portion (0600) of msg_perm.mode is set.

    The effective user ID of the process does not match msg_perm.cuid or msg_perm.uid and the effective group ID of the process matches msg_perm.cgid or msg_perm.gid and the appropriate bit of the ``group'' portion (0060) of msg_perm.mode is set.

    The effective user ID of the process does not match msg_perm.cuid or msg_perm.uid and the effective group ID of the process does not match msg_perm.cgid or msg_perm.gid and the appropriate bit of the ``other'' portion (0006) of msg_perm.mode is set.

Otherwise, the corresponding permissions are denied.

Semaphore Identifier
A semaphore identifier semid is a unique positive integer created by a semget(2) system call. Each semid has a set of semaphores and a data structure associated with it. The data structure is semid_ds and contains the following members:

    struct	ipc_perm sem_perm;	/* operation permissions */
    ushort	sem_nsems;	/* count of semaphores in set */
    time_t	sem_otime;	/* last operation time */
    time_t	sem_ctime;	/* last change time */
    		/* Times measured in seconds since */
    		/* 00:00:00 GMT, 1st January 1970 */

sem_perm
    is an ipc_perm structure that specifies the semaphore operation permission (see above).

sem_nsems
    has a value equal to the number of semaphores in the set. Each semaphore in the set is referenced by a positive integer referred to as a sem_num. The value of sem_num runs sequentially from 0 to the value of sem_nsems-1

sem_otime
    is the time of the last semop(2) operation.

sem_ctime
    is the time of the last semctl(2) operation that changed a member of the above structure.

A semaphore is a data structure that contains the following members:

    ushort	semval;	/* semaphore value */
    short	sempid;	/* pid of last operation  */
    ushort	semncnt;	/* number awaiting semval > cval */
    ushort	semzcnt;	/* number awaiting semval = 0 */

semval
    is a non-negative integer.

sempid
    is equal to the process ID of the last process that performed a semaphore operation on this semaphore.

semncnt
    is a count of the number of processes that are currently suspended awaiting this semaphore's semval to become greater than its current value.

semzcnt
    is a count of the number of processes that are currently suspended awaiting this semaphore's semval to become zero.

Semaphore Operation Permissions
In the semop(2) and semctl(2) system call descriptions, the permission required for an operation is given as a bit pattern in sem_perm.mode where the type of permission needed interpreted as follows:

    00400
        Read by user
    00200
        Alter by user
    00040
        Read by group
    00020
        Alter by group
    00004
        Readby others
    00002
        Alter by others

The Read and Alter permissions on a semid are granted to a process if one or more of the following are true:

    The effective user ID of the process is super-user.

    The effective user ID of the process matches sem_perm.cuid or sem_perm.uid in the data structure associated with semid and the appropriate bit of the ``user'' portion (0600) of sem_perm.mode is set.

    The effective user ID of the process does not match sem_perm.cuid or sem_perm.uid and the effective group ID of the process matches sem_perm.cgid or sem_perm.gid and the appropriate bit of the ``group'' portion (0060) of sem_perm.mode is set.

    The effective user ID of the process does not match sem_perm.cuid or sem_perm.uid and the effective group ID of the process does not match sem_perm.cgid or sem_perm.gid and the appropriate bit of the ``other'' portion (0006) of sem_perm.mode is set.

Otherwise, the corresponding permissions are denied.

Shared Memory Identifier
A shared memory identifier shmid is a unique positive integer created by a shmget(2) system call. Each shmid has a segment of memory (referred to as a shared memory segment) and a data structure associated with it.

The data structure is referred to as shmid_ds and contains the following members:

    struct	ipc_perm shm_perm;	/* operation permissions */
    int	shm_segsz;	/* size of segment */
    ushort	shm_cpid;	/* creator pid */
    ushort	shm_lpid;	/* pid of last operation */
    short	shm_nattch;	/* number of current attaches */
    time_t	shm_atime;	/* last attach time */
    time_t	shm_dtime;	/* last detach time */
    time_t	shm_ctime;	/* last change time */
    		/* Times measured in seconds since */
    		/* 00:00:00 GMT, 1st January 1970 */

shm_perm
    is an ipc_perm structure that specifies the shared memory operation permission (see above).

shm_segsz
    specifies the size of the shared memory segment.

shm_cpid
    is the process id of the process that created the shared memory identifier.

shm_lpid
    is the process id of the last process that performed a shmop(2) operation.

shm_nattch
    is the number of processes that currently have this segment attached.

shm_atime
    is the time of the last shmat operation.

shm_dtime
    is the time of the last shmdt operation.

shm_ctime
    is the time of the last shmctl(2) operation that changed one of the members of the above structure.

Shared Memory Operation Permissions
In the shmop(2) and shmctl(2) system call descriptions, the permission required for an operation is given as a bit pattern in shm_perm.mode where the type of permission needed interpreted as follows:

    00400
        Read by user
    00200
        Write by user
    00040
        Read by group
    00020
        Write by group
    00004
        Read by others
    00002
        Write by others

Read and Write permissions on a shmid are granted to a process if one or more of the following are true:

    The effective user ID of the process is super-user.

    The effective user ID of the process matches shm_perm.cuid or shm_perm.uid in the data structure associated with shmid and the appropriate bit of the ``user'' portion (0600) of shm_perm.mode is set.

    The effective user ID of the process does not match shm_perm.cuid or shm_perm.uid and the effective group ID of the process matches shm_perm.cgid or shm_perm.gid and the appropriate bit of the ``group'' portion (0060) of shm_perm.mode is set.

    The effective user ID of the process does not match shm_perm.cuid or shm_perm.uid and the effective group ID of the process does not match shm_perm.cgid or shm_perm.gid and the appropriate bit of the ``other'' portion (0006) of shm_perm.mode is set.

Otherwise, the corresponding permissions are denied.

SEE ALSO
Chapters 8-11 of the System V Interface Definition, Issue 2, Volume 1.