Basics Flashcards

1
Q

Name a central operating system abstraction

A

Process/Thread
File
Virtual Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where or when does the process consume additional system resources? Give two examples.

A

The process abstraction introduces a runtime overhead on context switches, that is by saving and restoring the register state. Each process/thread also requires its own stack, which increases the memory footprint of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why can system calls in an operating system like Linux conceptually not be replaced by procedure calls?

A

An important task of a system call is to change the privilege level of the CPU when entering the kernel. This can’t be done with a procedure call and would force the OS to give up the separation between user and kernel mode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give a reason besides simplicity why applications usually do not invoke system calls themselves but use language or system libraries instead.

A

Compatibility/Portability.
If the system call interface is not stable, updating the OS would require developers to also update their applications and potentially keep and maintain different versions. But even with a stable interface, invoking a system call is highly architecture specific. Language and system libraries help to abstract away from such details, making applications more portable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What other CPU mechanism besides the trap instruction could technically be used to synchronously enter the kernel from user mode?

A

CPU exceptions
software interrupts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name and explain two basic techniques for an operating system to wait for the completion of an input/output operation.

A

1) Programmed I/O, Polling: The CPU busy waits for the completion of the I/O operation by repeatedly querying a status register of the device.
2) Interrupts: The device raises a previously determined interrupt line or crafts a message for an interrupt controller. The CPU then jumps to a configured interrupt
service routine upon receiving the interrupt, thereby signaling the completion of the I/O operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain what is meant by cooperative multitasking. Which system call plays a special role in this context?

A

With cooperative multitasking, the OS doesn’t forcefully preempt processes or threads to perform a context switch. Instead, tasks are expected to voluntarily release the CPU, that is cooperate with the other processes. Releasing the CPU is usually done by invoking the yield() syscall.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Where or when does the file abstraction consume additional system resources? Give two examples

A

Translating file offsets to physical sector offsets slows down sector accesses. Respective data structures for address translation must be created, maintained, and stored on the storage device.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Where or when does the virtual memory abstraction consume additional system resources? Give two examples

A

It comes with additional costs for address translation (TLB misses, page faults). Switching between virtual address space is also a costly operation, especially when TLBs have to be flushed. Keeping management structures such as page tables consumes processor time and memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe a situation in which the process/thread abstraction saves system resources.

A

If the current process waits for I/O, switching to another process in the meantime can increase the overall system utilization; it saves CPU time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe a situation in which the file abstraction saves system resources.

A

The additional indirection provided by files allows unallocated areas to transparently return zero-sectors, saving the space on the storage device.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe a situation in which the virtual memory abstraction saves system resources.

A

The possibility to safely share identical data between processes, thus eliminating the need to hold multiple copies in memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Name one example of a mechanism as well as a policy of an operating system

A

Mechanisms: Dispatcher/threads, swap files
Policies: Scheduler, page replacement policy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which advantage does the separation between mechanism and policy provide?

A

More flexibility: Replacing the policy doesn’t require rewriting the mechanism.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain the difference between concurrency and parallelism.

A

Concurrency: The OS implements context switching between tasks on a single CPU
Parallelism: Multiple tasks run on multiple CPUs at the same time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In which situations do concurrency and parallelism each increase the performance of the system

A

Concurrency allows other tasks to run while one task waits for I/O – the overlap between CPU and I/O improves performance
Parallelism increases performance
whenever multiple tasks are runnable at the same time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Java is commonly viewed as an easier programming language than C. Explain one reason why it is, however, more difficult to write an operating system kernel in Java
compared to C.

A

> Java uses memory management based on garbage collection – the garbage collector itself adds to the work required to program a kernel and cannot be written in Java alone
Java does not allow access to arbitrary memory, although the OS frequently needs such access to arbitrary addresses to access device registers or to perform memory management

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

limited direct execution.

A

User-space code is allowed to perform most operations directly on the CPU without OS intervention, and only those operations which affect the safety or stability of the system are reserved for the OS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Microkernel operating systems implement device drivers and OS components as separate processes in user space instead of placing them in the shared kernel space. Name one advantage and one disadvantage of this architecture.

A

+Bugs in drivers have less impact on the safety/stability of the whole system. For example, accesses to invalid pointers don’t have the potential to crash the OS kernel.

-The architecture causes increased overhead compared to traditional OS. As the system is partitioned with finer granularity, more system calls and IPC operations are required to communicate between drivers and the kernel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Garbage collection

A

Garbage collection is an automatic memory management technique used in programming languages and environments where memory allocation and deallocation are done by the language runtime rather than by the programmer. The goal of garbage collection is to identify and free memory that is no longer being used by the program, in order to prevent memory leaks and improve program performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Removing the separation into user and kernel mode can make sense in specialized environments such as on embedded devices or where only a single fixed application is run on the operating system. Name and explain one advantage and one disadvantage of running the application and operating system together in kernel mode.

A

+ A potentially faster execution as expensive system calls can be replaced with cheap function calls.

  • Bugs in the application can easily corrupt OS data structures and thereby reduce reliability and stability.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the role of the system call dispatcher?

A

The syscall dispatcher performs the lookup in the system call table and jumps to the handler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Multi-processor systems are usually capable of delivering interrupts to an arbitrary processor. Give two reasons why the choice of the target processor may affect system performance.

A

> If the interrupt is delivered to a busy processor instead of an idle one, the running process is unnecessarily interrupted and delayed.

> Each processor has its own cache. How efficiently the interrupt can be handled depends on the data in the cache. Processors which have recently accessed the data required to process the interrupt will perform significantly better than processors with a “cold” cache.

> If one processor processes all interrupts, the chance is high that interrupts are not handled immediately by the OS, which increases the response time to the user input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

The .bss segment of an ELF file is enlarged. How does this affect the file size and the consumption of virtual and physical memory? Assume demand paging.

A

> File size doesn’t change. Because being all zeroes, the .bss
segment is not actually stored on the disk.

> Virtual memory increases according to the change in the segment size because the segment has to be represented in virtual memory to allow access.

> Physical memory may increase, depending on if the newly reserved space is actually accessed. Also depends on other paging decisions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Why does it make sense to use an operating system even if only one application is to be executed on a system?

A

> Avoid engineering efforts to support necessary devices and perform basic OS tasks such as handling I/O, scheduling and dispatching threads, or memory management.

> Application is not restricted to run only on the particular system due to the OS abstractions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

In a system call, parameters can be passed via the stack or registers. Explain an additional measure that must be taken when passing parameters by stack to ensure the security of the system.

A

The parameters need to be copied from the user-mode stack of the thread to its kernel-mode stack of the thread to its kernel mode stack before verification so that they can’t be manipulated by other user-mode threads that are running concurrently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Without taking security into account, name one advantage and one disadvantage of passing parameters via registers.

A

+saves memory accesses
-limited number of parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

A try/catch block handles two exceptions: ArithmeticException and IllegalArgumentException. Which of the exceptions might have originally been raised by the CPU? Give an example of such a situation.

A

ArithmeticException, for example, due to a division by zero.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

To synchronize a critical section in the kernel, a spinlock is used. What additional action may be necessary to ensure correct synchronization and when is it necessary?

A

It might be necessary to also disable interrupts if the critical section accesses a state that may also be touched by interrupt handlers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Describe the terms interrupt vector and interrupt service routine.

A

Interrupt Vector: Either directly the entry address of an interrupt handler or the index into an array of such addresses, called the interrupt vector table.

Interrupt Service Routine: An ISR is a piece of system code that handles an interrupt. It is often part of a device driver and may be reading or writing device registers and device memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Explain an advantage and a disadvantage of static versus dynamic linking of libraries

A

+no external dependencies as libraries are linked to a single executable
+link time optimization (LTO) is possible as libraries are available at the link time of executable
+potentially smaller memory footprint because only required functionality is included
+smaller load time because no dependency resolution and dynamic linking

-higher physical memory consumption due to missing sharing opportunities
-larger executable distribution and storage size
-higher security risks, as all executables that share a vulnerable library have to be relinked and updated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Name a segment of an ELF file that can be shared between processes and another segment that cannot be shared. Give reasons why each segment can be shared or cannot be shared

A

Generally, ELF segments can be shared if they are read-only and thus do not receive process private data. Accordingly, .text and .rodata can be shared, whereas .data and .bss cannot be shared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Name two ways of passing the parameters of a system call to the kernel. Which of these ways would you prefer? Explain your answer.

A

Parameters can be passed either on registers or on the stack. Passing them in registers is preferable because registers can be accessed faster than memory, which may improve system call performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

How does the operating system know that a non-privileged process has tried to execute a privileged instruction?

A

The CPU generates an exception in that case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What do the following abbreviations stand for?
TCB
IPC

A

TCB: Thread Control Block
IPC: Interprocess Communication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Give two pairs of hardware resources and corresponding operating system abstraction.

A

Hardware Resource OB Abstraction
CPU time Process/Thread
RAM/Memory Virtual address space
Disk File

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Describe textually for which properties the parameters should be
checked before file access.

s s i z e _ t read ( int fd , void ∗buf , s i z e _ t count) ;

A

fd is a valid file descriptor and allows read access
buf and buf + count are in user-mode memory

38
Q

Why should interrupt service routines (ISRs) be as short as possible?

A

While the ISR runs, the respective interrupt is mostly masked. Thus, if ISR takes too long, further signals from the device might get lost.

39
Q

In a hypothetical operating system, interrupt service routines are not executed on a dedicated stack. Explain briefly why this endangers the security and stability of the system.

A

An adversary could exploit the moment when an ISR runs on a user-mode stack, leaking sensitive information

40
Q

Give two aspects in which interrupts differ from exceptions.

A

Interrupts are asynchronous, exceptions are synchronous
Interrupts notify the OS of external events, exceptions signal specific error conditions

41
Q

What do the following abbreviations stand for?
PCB
IPI
ASID
GOT

A

PCB: Process Control Block
IPI: Inter-Processor Interrupt
ASID: Address Space Identifier
GOT: Global Offset Table

42
Q

A process invokes the kernel by a system call. Name two ways of passing the parameters to the kernel.

A

> Parameters can be passed in registers
Parameters can be pushed on the stack by a program and popped off by the kernel.
When there are more parameters than registers, parameters can be stored in a block memory and the address of the block can be passed as a parameter in a register.

43
Q

Why does a system call not necessarily require a context switch?

A

Since the kernel is mapped into the address space of all processes, system calls that don’t block can be executed without changing the address spaces.

44
Q

Besides potential performance advantages, give a reason why at least a part of interrupt service routines is typically written in assembly language.

A

High-level languages usually don’t allow the kind of low-level access to CPU hardware that is required to interrupt service routines. For example, an ISR may be required to (de-)activate the interrupt servicing of a particular device or directly access certain registers.

45
Q

Name one exception triggered by the processor for which the process is usually continued after exception handling and one for which the process is usually terminated.

A

The process is usually resumed after a page fault.
The process is usually terminated after a division by zero or an invalid opcode.

46
Q

Name five segments typically present in the user address space.

A

.data, .rodata, .bss, .text, stack, heap

47
Q

Name one of these segments whose memory is usually shared between multiple processes.

A

.text, .rodata

48
Q

Give a reason for one of the segments why it cannot be shared.

A

For example, the heap can’t be shared because then allocations and modifications from one process would be visible in other processes, breaking the isolation.

49
Q

Name four operations the operating system offers for working with files.

A

create()
write()
read()
reposition() or seek()
delete()
open()
close()

50
Q

Which two ways can the kernel use to access device registers?

A

port-mapped I/O
memory-mapped I/O

51
Q

Why do very large memory allocations from applications usually succeed even if the system does not have sufficient memory?

A

The virtual address space is larger than physical memory. When the program uses more of its address space than can be backed by physical memory, the OS moves some of the pages to a swap file or partition to make space for additional
data.

52
Q

Explain the term context switch.

A

During a context switch, the OS switches from one process/thread to another by saving the CPU state (register state, address space, . . . ) of the previous
process and restoring the CPU state of the next process

53
Q

Memory accesses often show temporal and/or spatial locality. Explain the meaning of both.

A

Temporal locality: If the same memory address is accessed repeatedly, the accesses are likely to happen shortly after each other.

Spatial locality: The addresses accessed by consecutive memory accesses are likely close to each other.

54
Q

Why do hard disk drives provide higher performance if the hard disk accesses feature a high degree of locality?

A

Hard disk drives need to position their read/write arm to the accessed sector. If sectors are close together, the seek distance and therefore the seek latency is kept low.

55
Q

Assuming purely cooperative scheduling, is it possible that after the processing of an
interrupt a different process is executed than before the arrival of the interrupt?

A

No, as the described situation is essential preemption (involuntary context
switch), which is not supported by purely cooperative scheduling. Note that interrupt handlers never directly terminate programs, as the program could be in the middle of a critical section in the kernel. Instead, the interrupt handler can
deliver a signal to the process which then “commits suicide”.

56
Q

Why is the distinction between privileged and non-privileged instructions necessary?

A

Some instructions can be used to circumvent the protection mechanisms of the OS, e.g., to read other processes’ memory or to starve other processes by disabling interrupts. These instructions must not be usable from user space.

57
Q

Operations such as reading the system clock can be implemented both as nonprivileged instructions and as system calls. Which advantage do non-privileged instructions have?

A

System calls add overhead due to the required trap instruction and the resulting user-kernel transition, whereas direct execution of the instruction is considerably faster.

58
Q

Explain briefly, using one example each, where an operating system performs multiplexing in time and space.

A

With multiplexing, a resource can be shared by multiple processes.
Time Computation: time is the primary resource provided by a CPU. The OS multiplexes CPU time with context switches, where the state of the CPU (i.e., the contents of registers) is swapped with a saved state in memory.
Space Memory: it is multiplexed by the OS by using virtual memory and dedicated address spaces, thus allowing each process to work with the full range of virtual addresses.

59
Q

How does multiprogramming improve the system utilization during I/O operations?

A

When a process initiates an I/O operation, it is often necessary to block it until the operation has finished. When having only a single program running concurrently, the CPU is thus forced into an idle phase, which wastes precious computation time. By having multiple programs running concurrently, the operating system can perform a context switch to another process and continue execution. This way, the CPU and I/O devices can be utilized at the same time, improving the overall system load.

60
Q

Visually depict the usual layout of a virtual address space.

A

Kernel
Stack
->
<-
Heap
Data
Text

61
Q

A system call has more arguments than there are CPU registers. Give, in the right order, two important steps the operating system has to take to protect itself from malicious callers when handling the parameters.

A

(a) Copy arguments to kernel memory (e.g., the kernel stack).
(b) Check the arguments using the copy.

62
Q

What must apply to buffer addresses (e.g., a destination buffer when reading a file) which were passed to system calls?

A

Buffer addresses must be in user space. Otherwise, the caller could lead the kernel into overwriting arbitrary memory or leaking sensitive information.

63
Q

Explain the difference between a program and a process.

A

A program is a specification that is used to construct a process. It contains the code to be loaded and the address space layout.
A process is an activity of executing
a program.

64
Q

Give an example for a policy and a corresponding mechanism.

A

> Scheduling algorithm and dispatcher
Moving memory pages to disk and the page replacement algorithm

65
Q

Which advantage does dividing OS functionality into policy and mechanism provide?

A

> The mechanism can be reused even if a different policy is required (e.g., because of changing workloads).
The hardware-independent policy can be reused if the hardware (and therefore the hardware-dependent mechanism) changes.

66
Q

Why does a modern system contain different types of memory (e.g., cache, RAM, SSD, hard disk)?

A

Because faster memory such as cache is expensive and therefore only available in small quantities, modern systems need to be able to store large amounts of data and need to provide high memory performance.

67
Q

Which limitations does user mode have in comparison to kernel mode?

A

User mode code can’t access memory marked to be only accessible to kernel mode and can’t execute privileged instructions.

68
Q

Is it possible to implement protection between processes on a system that does not
differentiate between user and kernel mode?

A

No, because modifying address spaces need to be privileged. If processes could make arbitrary changes to address spaces, they could modify their address space to access other processes’ memory.

69
Q

Why do interactive systems usually use preemptive scheduling?

A

Interactive systems use preemptive scheduling to prevent CPU-intensive processes from monopolizing the CPU and increasing the response time of other processes

70
Q

The int instruction of x86 processors causes the processor to change to kernel mode and to immediately continue execution in the OS. Into which of the three categories for kernel entries (system call/trap instruction, interrupt, exception) does this process fall?

A

The instruction causes a synchronous and voluntary entry into the kernel. It is therefore a trap instruction, used for system calls. It is not an interrupt, as interrupts do not originate from the code itself.

71
Q

Why does the OS have to switch from the application’s stack to a separate kernel stack when handling an interrupt?

A

> Because the application’s stack might be too small or not valid at all, so access to the stack might fail and might crash the system.
Because other threads from the same application could, when running on other cores of an SMP system, examine and change sensitive data which is placed on the stack by the OS during interrupt handling

72
Q

Outline the most important steps during interrupt handling by the CPU and the operating system.

A
  1. Lookup: The CPU performs a lookup in the interrupt vector to identify the service routine
  2. Entry: The CPU calls the service routine. The routine is expected to save the current CPU context.
  3. Execution: The service routine in the OS handles the interrupt. This may include communicating with devices (e.g., reading device memory).
  4. Exit: The CPU returns from the service routine. The routine is expected to restore the previous CPU context.
73
Q

Give two privileged CPU operations on x86 and explain why each of them needs to be
privileged. You do not need to provide the assembler mnemonics. Inverse operations do not count.

A

> Deactivate interrupts (CLI): Timer triggers via an interrupt. If the user could disable interrupts, she could interfere with scheduling.
Set CR3 register: The CR3 register controls which address space is currently active. Allowing the user to modify the address space breaks the memory
isolation.

74
Q

Do CPU exceptions occur synchronously with the program flow?

A

Yes

75
Q

Consider an OS in which processes and the kernel each possess a dedicated, full address space. When executing the trap instruction, the system automatically switches to the kernel’s address space and to the respective kernel stack. A system call requires more arguments than there are CPU registers available. Explain how the parameters could be passed in this system.

A

Since there are not enough registers, at least some parameters have to be passed via the stack. However, the stack is only accessible in the process’s address space. To access the arguments in the kernel we, therefore, have to:
1. Save the user stack pointer in a selected register
2. Map the user stack into the kernel address space
3. Copy the arguments from the user stack to the kernel stack using the saved (adjusted) user stack pointer

76
Q

Give an advantage and a disadvantage of a dedicated kernel address space on 32-bit systems. How do you rate this design on 64-bit systems

A

+Having dedicated address spaces instead of sharing a single virtual address space between the process and the kernel provide more space for both parties.
-Jumping between user and kernel mode includes a full address space switch, which is expensive. It also makes parameter passing more complex.

77
Q

Give four sections that are usually represented in ELF files. Shortly explain each section’s purpose.

A

RW Data: Pre-initialized data, which can be modified during execution.
RO Data: Pre-initialized data, which is read-only and should not be modified.
The OS marks these pages as read-only in the page tables.
BSS: Not initialized writable data area. The section will be all zeros at startup.
The section does not take up any space in the ELF file.

78
Q

Give an address space area that is not represented in an ELF file.

A

Stack or heap

79
Q

Give two general purposes of abstractions in an operating system. For each one, provide an example abstraction and the corresponding hardware resource.

A

> Simply interface to the hardware by hiding implementation details
Example: Files → Disk Storage

> Multiplex hardware to multiple processes
Example: Processes/Threads → CPU

80
Q

Discuss the pros and cons of interrupts over polling. In which situation is polling the better choice?

A

With polling, the CPU constantly has to probe device registers for detecting events such as I/O completions. As long as no events occur, this method wastes CPU time. While reducing the polling frequency (i.e., performing other work in between checks) preserves some CPU time, it also increases latency. With interrupts, the CPU does not have to poll device registers, but instead, it actively receives a signal as soon as its attention is required.
However, interrupts are computationally expensive as they imply a context switch. They are thus not particularly well suited for scenarios, where the CPU is predominantly processing events anyways and interrupts introduce unnecessary overhead.

81
Q

Give a usage example for an operating system without separation in user and kernel mode.

A

In small embedded systems a separation in user and kernel mode is often not necessary, because the system executes only a single application. This application will probably also perform frequent hardware accesses and one might not want to pay the overhead of privilege boundary crossings on a less potent hardware platform

82
Q

Outline the most important steps by an application and the operating system for a system call

A
  1. Place parameters (incl. system call number!) in registers and/or on stack
  2. Execute trap instruction
  3. Switch to kernel-mode stack and copy parameters from user stack to kernel stack
  4. Look up and execute selected system service routine
  5. Place result in register or on (user) stack and switch back to user stack
  6. Return to user mode
83
Q

Explain why the stack cannot replace the heap

A

Although the stack can provide memory for variables and data structures just like the heap, the lifetime of data on the stack is inherently bound to the CPU’s execution context. If the CPU leaves a function, which stored data on the stack, the data
can no longer be safely accessed and should be considered dead. The heap, on the other side, decouples lifetime and execution context

84
Q

Name the two basic functions of an operating system.

A

An OS must provide abstractions from the hardware and protection from other applications.

85
Q

Explain the difference between an interrupt and an exception.

A

An Interrupt is generally caused outside the currently executing program. Technically, the program could thus go on without handling the interrupt.
An exception is caused by an instruction in the currently executing program and
prevents the program from continuing until the exception is handled.

86
Q

Explain the term multiprogramming.

A

Multiprogramming refers to multiple programs being loaded in memory at the same time, with the OS switching between them as necessary. If, for example, a program blocks for I/O, the OS can switch to a different one to keep the CPU busy.

87
Q

I/O instructions, which are used for accessing hardware devices, are typically privileged (i.e., these instructions can only be executed in kernel mode). Give a reason why these instructions are privileged. Also, give a reason why it may be beneficial to allow user mode direct access to some devices.

A

I/O instructions should be privileged to guarantee process isolation. For example, if user space code had direct access to a DMA-enabled device, that code could use DMA to access the memory of other processes. Making device access privileged
allows the kernel to validate DMA requests.
Entering the kernel on each I/O request induces application overhead. Therefore, it may be beneficial to allow user space code direct device access if performance is critical for the operation of the device. (1 P) Examples of such devices are GPUs or certain high-performance network hardware. However, these devices must implement appropriate protection mechanisms themselves to allow user space direct access without breaking isolation.

88
Q

Give and explain an advantage and a disadvantage of the separation into user- and kernel-mode in modern operating systems.

A

+The separation into user- and kernel-mode dramatically increases the stability of the system, because malfunctioning processes cannot inadvertently tamper with kernel code and data structures and thereby crash the system.
+The boundary increases the security of the system because only proper protection of the kernel allows an operating system to perform trustworthy security checks (e.g., authentication and authorization). Private information such
as login credentials are not leaked.
-The system can also enforce fairness by preventing processes from hogging the CPU or otherwise misusing resources.
-Crossing the boundary comes at a cost, because the architectural state needs to be saved and restored, and the CPU must switch to a different privilege level. System calls are therefore noticeably slower than calls into a library.

89
Q

Explain how system calls are technically implemented.

A

> Switch to kernel mode: The CPU usually provides a special (non-privileged) trap instruction, which performs a switch to kernel mode and jumps to a previously configured kernel code location (the system call dispatcher). The address is set up by the OS during system initialization.

> System service selection: When a program performs a system call, it requests a particular system service. To express which service it needs, the program provides the system call number in a predefined location or register. The number is usually used as an index into a function table.

> Parameter passing: A limited number of parameters can be passed via CPU registers. More parameters or data types such as strings must be passed via the user stack.

> Application Program Interface (API): Since the calling convention of the system call interface as well as the system call numbers are OS and
potentially even version specific, the system call interface is usually accessed through system libraries. This allows the OS to be updated without having to change applications. The system libraries often also implement additional functionality that eases application development.

90
Q

Explain why timely and fast processing of interrupts by the operating system is important.

A

If the OS does not promptly react to interrupts, the overall system performance becomes sluggish. This is because the lag between the occurrence of an event (e.g., a key press by the user) and the system’s reaction is high – resulting for example in high input latency or cracking sound. Interrupts might also get lost, or more precisely, device buffers may exhaust and further input (such as network packets or key presses) gets lost, because
during the processing of a particular interrupt, the interrupt is masked and will not be delivered.

91
Q

During the processing of an I/O operation, an unexpected exception occurs in a kernel driver, which does not handle the exception. The kernel could cancel the I/O operation and return an error. Why might it be better to stop the system, for example by blue screen or kernel panic?

A

After an unexpected error, the system is in an unknown condition as the error could have effects that are not directly visible but ultimately lead to erratic system behavior such as data corruption or loss. The reliability of the system should therefore be considered compromised and an early stop might prevent additional damage.