ヨーグルト
ヨーグルト

Reputation: 21

What happens to the process after the system call?

Is the kernel code loaded in the code segment context in the main memory space which is assigned to the process that made the system call?
Then does the process of making a system call now send kernel code to the processor's pipeline?

Upvotes: 0

Views: 43

Answers (1)

Brendan
Brendan

Reputation: 37262

Is the kernel code loaded in the code segment context in the main memory space which is assigned to the process that made the system call?

Typically (at least for modern operating systems) each program or process has a virtual address space, and a process' virtual address space is split into 2 large areas - one called "user space" that is different for each process, and one called "kernel space" that is the same for all processes and requires special permission to access.

These larger areas are split up into many smaller areas. E.g. "user space" might be one area for the program's code, one for the program's "initialized from the executable file" data, one for the program's "not initialized from the executable file, initialized to zeros" data; then another group of areas (for code and data) for each shared library; then more zones for things like heap, memory mapped files, etc.

In a similar way, "kernel space" may be split into many smaller areas - one for kernel's code, one for kernel's data, a group of areas for each dynamically loaded "kernel module", some special purpose areas, etc. This all depends heavily on which OS or which kernel it is (and in some cases "kernel space" might just be a minimal stub that switches to another virtual address space for security reasons).

When you call a function in a shared library, the "call" instruction tells the CPU to execute code in a completely different area (in user space) of the virtual address space.

When you call a kernel system call, the instruction used to do that tells the CPU to execute code in a completely different area (in kernel space) of the virtual address space. The main difference is that a special instruction is used (instead of a normal "call" instruction) so that the CPU also changes the privilege level at the same time, so that CPU allows the called kernel code to access (restricted) "kernel space".

Of course the details of the special instruction that does "call with privilege level change" is CPU and possibly OS/kernel specific (and is paired with a special "return with privilege level change" instruction); and there's plenty of little technical details (e.g. switching stacks) that are part of privilege level changes.

Upvotes: 1

Related Questions