Course contentsShow
← Computer Science
Lesson 1381 of 2,87231. Memory ManagementFree lesson

Segmentation with Protection and Sharing

Exploring how segmentation naturally supports memory protection through bounds checking and enables code/data sharing between processes.

Segmentation with Protection and Sharing

What you'll learn: How segmentation naturally enables both memory protection and safe sharing of code and data between processes.

Why Segmentation Excels at Protection

Segmentation divides memory into logical units (code, stack, heap, data), and each segment has its own base, limit, and permissions. When the MMU translates a logical address, it automatically checks:

  1. Bounds checking: Is the offset within the segment's limit? If not, trap to the OS (segmentation fault).
  2. Permission bits: Does the access match the segment's allowed operations (read, write, execute)?

For example, a code segment might be marked read-execute only—any write attempt triggers a protection fault. A stack segment allows read-write but not execute, preventing certain exploits.

Sharing Made Simple

Because segments represent logical units, multiple processes can safely share segments by pointing their segment table entries to the same physical memory.

Common sharing scenarios:

  • Code sharing: Multiple processes running the same program can share a single read-only code segment (saves memory).
  • Shared libraries: Standard library code segments can be shared across all processes using them.
  • Data sharing: Cooperating processes can share a data segment for inter-process communication.

Each process still has its own segment table, so they maintain separate stacks and private data while sharing common code.

The Analogy

Think of an office building where different departments (segments) have locked doors with key-card access. The security system (MMU) checks both that you're entering a valid room number (bounds) and that your key-card has the right permissions (read/write/execute). Multiple departments can share the conference room (shared segment) while keeping their private offices separate.

Key Takeaway: Segmentation's logical division of memory naturally supports fine-grained protection through bounds and permission checking, while enabling efficient sharing of code and data segments between processes.