Course: CPSC/ECE 3220 Fall 2024 Lecture Notes
Content follows OSPP Chapter 2 – Part A, adapted by Mark Smotherman from Tom Anderson’s slides on the OSPP website.
Definition: The kernel is the lowest level of software running on a system.
Its primary purpose is to implement protection against unauthorized access.
The kernel is trusted fully and has access to all hardware resources.
Important to restrict the privileges of untrusted code for security reasons.
Its access to hardware should be limited.
It should not modify the kernel or other crucial applications.
The challenge is executing code but restricting its privileges to mitigate risks from bugs or malicious intent.
Examples of such code include:
A script running in a web browser.
A program downloaded from the Internet.
A program still in development or not fully tested.
Source File on Disk: Initial programming code written by the developer.
Executable File on Disk: Produced after compiling and linking the source code, containing machine instructions with a specified entry point and initialized data.
Memory Image: Developed after the program is loaded into memory, consisting of stacks, heaps, and uninitialized data areas to support execution.
Process includes:
Source Code: Written in languages like C/C++.
Machine Instructions: Processed and executed according to system requirements.
Data: Used during execution, which includes instructions for the heap and stack.
Steps recognized during compilation include:
Preprocessing - Involves header files and macro expansions.
Compilation - The core code is converted into a machine-readable format.
Assembling - Assembly code is transformed into machine code.
Linking - The assembler resolves definitions, leading to an executable format.
An executable file comprises several sections:
.text section - Contains binary machine code.
.data section - Contains initialized data (read-write).
.rodata section - Holds initialized read-only data.
.bss section - Represents uninitialized data or static variables.
Process Concept: Seen as the OS abstraction for executing programs with limited privileges.
Dual-mode Operation: Differentiates between user mode (limited privileges) and kernel mode (full privileges).
Safe Control Transfer: Method governing the transition from user mode to kernel mode and vice versa.
Definition: A process is an instance of a program executing with limited rights.
Thread: Execution sequence within a process, where multiple threads can exist per process.
Address Space: Defines the valid range of addresses a process can access.
Allocated Resources: Includes physical memory, files, and network connections accessible to the process.
Capabilities: Permissions the process holds to make system calls and access objects.
Concept: Execute program instructions in a controlled environment (simulator) checking for permission before execution to enhance security.
To enhance speed, ideally, unprivileged code should run directly on the CPU.
Kernel Mode: Full access to hardware, allowing any memory read/write, I/O device access, and disk operations.
User Mode: Access restricted to permissions granted by the kernel.
Mode Bit: Indicates the current mode of operation, stored in the processor status register.
Instructions exclusive to the kernel:
Modify mode bits in the processor status register.
Control memory accesses for user programs.
Facilitate commands for I/O devices.
Allow transitions into kernel code.
Instructions allowed in both user and kernel modes:
Basic arithmetic operations and control commands (e.g., load, store, branch).
Fundamental for both OS and applications.
In User Mode: Only non-privileged instructions should execute.
Kernel Mode: Both privileged and non-privileged instructions may execute without restrictions.
Attempting to execute privileged instructions in user mode results in stopping the application and notifying the OS.
This is typically an error, but some instructions may be used intentionally to invoke the OS.
Given a simplistic example: Why should a "Hello world" program not write directly to the screen memory, requiring kernel involvement?
Physical Memory Management: Mechanisms ensure the physical address generated is checked against limits to prevent unauthorized access.
Implement virtual addressing utilizing bounds and base registers for memory management.
Challenges faced with memory management techniques:
Sharing memory between processes while avoiding fragmentation.
Solutions include paging and segmentation.
Code snippet provided to demonstrate how the OS operates with virtual addresses, utilizing static variables.
Demonstrates running processes in parallel, with expected output showcasing shared results.
Concept: Randomizes placement of text, data, heap, and stack in a process's address space to enhance security against buffer overflow attacks.