Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 5: Locking and Interprocess Communication


q_messages
q_receivers
q_senders

struct msg_receiver

struct task_struct
ipcs_idr struct msg_msg

struct msg_queue

struct
kern_ipc_perm

ID to pointer mapping

struct
ipc_ids

Figure 5-6: Data structures for System V message queues.

5.3.4 Shared Memory


From the user and kernel perspective,shared memory— the third and final SysV concept for interprocess
communication — uses similar structures for its implementation to the first two mechanisms described
above. Its essential aspects do not differ from those of semaphores and message queues.

❑ Applications request an IPC object that can be accessed via a common magic number and a
kernel-internal identifier via the current namespace.
❑ Access to memory can be restricted by means of a system of privileges.
❑ System calls are used to allocate memory that is associated with the IPC object and that can be
accessed by all processes with the appropriate authorization.

Kernel-side implementation also adopts very similar concepts to those described above. I will therefore
make do with a brief description of the data structures shown in Figure 5-7.

shm_file

shmid_kernel struct
address_
space

struct
file

ipcs_idr

ID to pointer mapping

struct
ipc_ids kern_ipc_perm

Figure 5-7: Data structures for System V shared memory.

Once again, a combination ofkern_ipc_permandshmid_kernelheld in theentriesarray of thesmd_ids
global variable is used to facilitate management of the access permissions to the IPC object. A dummy
Free download pdf