Linux Kenel Development(2nd Edition)--reading digest

Questions:
1. What is the two spaces?
kenel space and user space
2. What is the two contexts?
interupt context and process context
3. What is process?
The process is one of the fundamental abstractions in Unix operating systems. A process is a program (object code stored on some media) in execution. Processes are, however, more than just the executing program code (often called the text section in Unix). They also include a set of resources such as open files and pending signals, internal kernel data, processor state, an address space, one or more threads of execution, and a data section containing global variables. Processes, in effect, are the living result of running program code.
4. What are the fundamental abstractions in Unix?
process and file
5. What are the two virtulizations in modern operating system?
On modern operating systems, processes provide two virtualizations: a virtualized processor and virtual memory. The virtual processor gives the process the illusion that it alone monopolizes the system, despite possibly sharing the processor among dozens of other processes. Chapter 4, "Process Scheduling," discusses this virtualization. Virtual memory lets the process allocate and manage memory as if it alone owned all the memory in the system. Virtual memory is covered in Chapter 11, "Memory Management." Interestingly, note that threads share the virtual memory abstraction while each receives its own virtualized processor.
6.  用户进程调用中的system call 属于什么进程?
user-space applications must somehow signal the kernel that they want to execute a system call and have the system switch to kernel mode, where the system call can be executed in kernel-space by the kernel on behalf of the application.
As discussed in Chapter 3, "Process Management," the kernel is in process context during the execution of a system call. The current pointer points to the current task, which is the process that issued the syscall.
When the system call returns, control continues in system_call(), which ultimately switches to user-space and continues the execution of the user process.
7. Bottom Halves属于什么context?
When executing an interrupt handler or bottom half, the kernel is in interrupt context. Recall that process context is the mode of operation the kernel is in while it is executing on behalf of a process, for example, executing a system call or running a kernel thread. In process context, the current macro points to the associated task.
Furthermore, because a process is coupled to the kernel in process context, process context can sleep or otherwise invoke the scheduler.
Interrupt context, on the other hand, is not associated with a process. The current macro is not relevant (although it points to the interrupted process).
in_interrupt():
It returns nonzero if the kernel is in interrupt context. This includes either executing an interrupt handler or a bottom half handler.
8. What is the entry points to kernel?
system call, exception, trap
9. Why user-space application can not simply make a function call to a method existing in kernel-space?
Because the kernel exists in a protected memory space. If applications could directly read and write to the kernel's address space, system security and stability would go out the window.
10. What is the mechanism to make a system call?
The mechanism to signal the kernel is a software interrupt: Incur an exception and then the system will switch to kernel mode and execute the exception handler. The exception handler, in this case, is actually the system call handler. The defined software interrupt on x86 is the int $0x80 instruction. It triggers a switch to kernel mode and the execution of exception vector 128, which is the system call handler. The system call handler is the aptly named function system_call(). It is architecture dependent and typically implemented in assembly in entry.S [6]. Recently, x86 processors added a feature known as sysenter. This feature provides a faster, more specialized way of trapping into a kernel to execute a system call than using the int interrupt instruction.
Support for this feature was quickly added to the kernel. Regardless of how the system call handler is invoked, however, the important notion is that somehow user-space causes an exception or trap to enter the kernel.
11. How denote a correct system call?
Simply entering kernel-space alone is not sufficient because there are multiple system calls, all of which enter the kernel in the same manner. Thus, the system call number must be passed into the kernel. On x86, the syscall number is fed to the kernel via the eax register. Before causing the trap into the kernel, user-space sticks in eax the number corresponding to the desired system call. The system call handler then reads the value from eax. Other architectures do something similar.
The specified system call is invoked:
call *sys_call_table(,%eax,4)
12. What is protected memory space?

A portion of the logical address space is set aside for protected address spaces (sometimes called user address spaces or ring 3). This protected address space is a portion of the logical address space that has carefully controlled interaction with the server operating system. All protected address spaces use virtual memory. For general information about virtual memory, see Virtual Memory.

A key benefit of protected address spaces is that you can use them to take advantage of virtual memory or to run untried or troublesome applications. Because modules loaded into a protected address space can't corrupt the operating system or cause server abends, the protected address space provides a safe place to run applications.

The operating system address space (ring 0) is sometimes called the OS address space or the kernel address space. The operating system itself cannot run in a protected address space.

The memory protection marshalling layer, in conjunction with the memory protection subsystem, prevents modules in a protected address space from having direct access to anything outside the address space.

In particular, the memory protection marshalling layer serves as the interface between the protected address spaces and the server operating system. These layers prevent NLM programs in protected spaces from making calls or passing parameters to the operating system that would corrupt or fault the core operating system. Likewise, programs using memory outside the boundary cannot allocate areas of memory inside the boundary.

You can load modules into a protected address space, unload modules from a space, delete a space, or kill a space. See Using Protected Address Spaces and Loading Protected Address Spaces.

http://www.novell.com/documentation/nw65/index.html?age=/documentation/nw65/smem_enu/data/hm7eiu26.html

The above result is from Novell system, but it seems different form Linux protected address space.

13. Does kernel thread map to process address space?

Kernel threads do not have an address space and mm is NULL. Therefore, when a kernel thread is scheduled, the kernel notices that mm is NULL and keeps the previous process's address space loaded.

14. User space中的system call在什么address space中?
08048000-08049000 r-xp 00000000 00:09 677602     Linux_System_Analysis_And_Advanced_Programming_Tech/ch20/hello
08049000-0804a000 rw-p 00000000 00:09 677602
Linux_System_Analysis_And_Advanced_Programming_Tech/ch20/hello
40000000-40016000 r-xp 00000000 03:01 544068     /lib/ld-2.2.4.so
40016000-40017000 rw-p 00015000 03:01 544068     /lib/ld-2.2.4.so
40032000-40033000 rw-p 00000000 00:00 0
40033000-40040000 r-xp 00000000 03:01 480079     /lib/i686/libpthread-0.9.so
40040000-40048000 rw-p 0000c000 03:01 480079     /lib/i686/libpthread-0.9.so
40048000-4017a000 r-xp 00000000 03:01 480075     /lib/i686/libc-2.2.4.so
4017a000-4017f000 rw-p 00131000 03:01 480075     /lib/i686/libc-2.2.4.so
4017f000-40183000 rw-p 00000000 00:00 0
bfffe000-c0000000 rwxp fffff000 00:00 0
Each process runs in its private address space. A process running in User Mode refers to private stack, data, and code areas. When running in Kernel Mode, the process addresses the kernel data and code area and makes use of another stack.
System call should be in kernel address space not map to any process address space.
15. How kernel access Process Address Space?
System call service routines quite often need to read or write data contained in the process's address space. Linux includes a set of macros that make this access easier. We'll describe two of them, called get_user( ) and put_user( ). The first can be used to read 1, 2, or 4 consecutive bytes from an address, while the second can be used to write data of those sizes into an address.
16. What is the kernel mode and user mode?
As already mentioned, a CPU can run either in User Mode or in Kernel Mode. Actually, some CPUs can have more than two execution states. For instance, the Intel 80x86 microprocessors have four different execution states. But all standard Unix kernels make use of only Kernel Mode and User Mode.
When a program is executed in User Mode, it cannot directly access the kernel data structures or the kernel programs. When an application executes in Kernel Mode, however, these restrictions no longer apply. Each CPU model provides special instructions to switch from User Mode to Kernel Mode and vice versa. A program executes most of the time in User Mode and switches to Kernel Mode only when requesting a service provided by the kernel. When the kernel has satisfied the program's request, it puts the program back in User Mode.
The kernel itself is not a process but a process manager. The process/kernel model assumes that processes that require a kernel service make use of specific programming constructs called system calls. Each system call sets up the group of parameters that identifies the process request and then executes the hardware-dependent CPU instruction to switch from User Mode to Kernel Mode.
Besides user processes, Unix systems include a few privileged processes called kernel threads with the following characteristics:
• They run in Kernel Mode in the kernel address space.
• They do not interact with users, and thus do not require terminal devices.
• They are usually created during system startup and remain alive until the system is shut down.
17. How invoke kernel routine?
• A process invokes a system call.
• The CPU executing the process signals an exception, which is some unusual condition such as an invalid instruction. The kernel handles the exception on behalf of the process that caused it.
• A peripheral device issues an interrupt signal to the CPU to notify it of an event such as a request for attention, a status change, or the completion of an I/O operation. Each interrupt signal is dealt by a kernel program called an interrupt handler. Since peripheral devices operate asynchronously with respect to the CPU, interrupts occur at unpredictable times.
• A kernel thread is executed; since it runs in Kernel Mode, the corresponding program must be considered part of the kernel, albeit encapsulated in a process.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值