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.

struct struct file address_ space

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

struct struct file address_ space

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

Once again, a combination of kern_ipc_perm and shmid_kernel held in the entries array of the smd_ids global variable is used to facilitate management of the access permissions to the IPC object. A dummy file linked with the corresponding instance of shmid_kernel via shm_file is created for each shared memory object. The kernel uses the pointer smh_file->f_mapping to access the address space object (struct address_space) used to create anonymous mappings as described in Chapter 4. The page tables of the processes involved are set up so that each process is able to access the areas linked with the region.

Continue reading here: Signals

Was this article helpful?

0 0