Skip to content

Commit 76785c2

Browse files
committed
fix typos: misc and syscall chapters
1 parent 64b0d27 commit 76785c2

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

Misc/how_kernel_compiled.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
129129
-e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
130130
```
131131

132-
As you can see, it executes the [uname](https://en.wikipedia.org/wiki/Uname) util that prints information about machine, operating system and architecture. As it gets the output of `uname`, it parses the ouput and assigns the result to the `SUBARCH` variable. Now that we have `SUBARCH`, we set the `SRCARCH` variable that provides the directory of the certain architecture and `hfr-arch` that provides the directory for the header files:
132+
As you can see, it executes the [uname](https://en.wikipedia.org/wiki/Uname) util that prints information about machine, operating system and architecture. As it gets the output of `uname`, it parses the output and assigns the result to the `SUBARCH` variable. Now that we have `SUBARCH`, we set the `SRCARCH` variable that provides the directory of the certain architecture and `hfr-arch` that provides the directory for the header files:
133133

134134
```Makefile
135135
ifeq ($(ARCH),i386)

SysCall/syscall-2.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ How does the Linux kernel handle a system call
77
The previous [part](http://0xax.gitbooks.io/linux-insides/content/SysCall/syscall-1.html) was the first part of the chapter that describes the [system call](https://en.wikipedia.org/wiki/System_call) concepts in the Linux kernel.
88
In the previous part we learned what a system call is in the Linux kernel, and in operating systems in general. This was introduced from a user-space perspective, and part of the [write](http://man7.org/linux/man-pages/man2/write.2.html) system call implementation was discussed. In this part we continue our look at system calls, starting with some theory before moving onto the Linux kernel code.
99

10-
An user application does not make the system call directly from our applications. We did not write the `Hello world!` program like:
10+
A user application does not make the system call directly from our applications. We did not write the `Hello world!` program like:
1111

1212
```C
1313
int main(int argc, char **argv)
@@ -135,16 +135,16 @@ wrmsrl(MSR_STAR, ((u64)__USER32_CS)<<48 | ((u64)__KERNEL_CS)<<32);
135135
wrmsrl(MSR_LSTAR, entry_SYSCALL_64);
136136
```
137137

138-
The first model specific register - `MSR_STAR` contains `63:48` bits of the user code segment. These bits will be loaded to the `CS` and `SS` segment registers for the `sysret` instruction which provides functionality to return from a system call to user code with the related privilege. Also the `MSR_STAR` contains `47:32` bits from the kernel code that will be used as the base selector for `CS` and `SS` segment registers when user space applications execute a system call. In the second line of code we fill the `MSR_LSTAR` register with the `entry_SYSCALL_64` symbol that represents system call entry. The `entry_SYSCALL_64` is defined in the [arch/x86/entry/entry_64.S](https://github.com/torvalds/linux/blob/master/arch/x86/entry/entry_64.S) assembly file and contains code related to the preparation peformed before a system call handler will be executed (I already wrote about these preparations, read above). We will not consider the `entry_SYSCALL_64` now, but will return to it later in this chapter.
138+
The first model specific register - `MSR_STAR` contains `63:48` bits of the user code segment. These bits will be loaded to the `CS` and `SS` segment registers for the `sysret` instruction which provides functionality to return from a system call to user code with the related privilege. Also the `MSR_STAR` contains `47:32` bits from the kernel code that will be used as the base selector for `CS` and `SS` segment registers when user space applications execute a system call. In the second line of code we fill the `MSR_LSTAR` register with the `entry_SYSCALL_64` symbol that represents system call entry. The `entry_SYSCALL_64` is defined in the [arch/x86/entry/entry_64.S](https://github.com/torvalds/linux/blob/master/arch/x86/entry/entry_64.S) assembly file and contains code related to the preparation performed before a system call handler will be executed (I already wrote about these preparations, read above). We will not consider the `entry_SYSCALL_64` now, but will return to it later in this chapter.
139139

140140
After we have set the entry point for system calls, we need to set the following model specific registers:
141141

142-
* `MSR_CSTAR` - target `rip` for the compability mode callers;
142+
* `MSR_CSTAR` - target `rip` for the compatibility mode callers;
143143
* `MSR_IA32_SYSENTER_CS` - target `cs` for the `sysenter` instruction;
144144
* `MSR_IA32_SYSENTER_ESP` - target `esp` for the `sysenter` instruction;
145145
* `MSR_IA32_SYSENTER_EIP` - target `eip` for the `sysenter` instruction.
146146

147-
The values of these model specific register depend on the `CONFIG_IA32_EMULATION` kernel configuration option. If this kernel configuration option is enabled, it allows legacy 32-bit programs to run under a 64-bit kernel. In the first case, if the `CONFIG_IA32_EMULATION` kernel configuration option is enabled, we fill these model specific registers with the entry point for the system calls the compability mode:
147+
The values of these model specific register depend on the `CONFIG_IA32_EMULATION` kernel configuration option. If this kernel configuration option is enabled, it allows legacy 32-bit programs to run under a 64-bit kernel. In the first case, if the `CONFIG_IA32_EMULATION` kernel configuration option is enabled, we fill these model specific registers with the entry point for the system calls the compatibility mode:
148148

149149
```C
150150
wrmsrl(MSR_CSTAR, entry_SYSCALL_compat);
@@ -191,7 +191,7 @@ wrmsrl(MSR_SYSCALL_MASK,
191191
X86_EFLAGS_IOPL|X86_EFLAGS_AC|X86_EFLAGS_NT);
192192
```
193193

194-
These flags will be cleared during syscall initialization. That's all, it is the end of the `syscall_init` function and it means that system call entry is ready to work. Now we can see what will occur when an user application executes the `syscall` instruction.
194+
These flags will be cleared during syscall initialization. That's all, it is the end of the `syscall_init` function and it means that system call entry is ready to work. Now we can see what will occur when a user application executes the `syscall` instruction.
195195

196196
Preparation before system call handler will be called
197197
--------------------------------------------------------------------------------
@@ -364,7 +364,7 @@ In the end we just call the `USERGS_SYSRET64` macro that expands to the call of
364364
sysretq;
365365
```
366366

367-
Now we know what occurs when an user application calls a system call. The full path of this process is as follows:
367+
Now we know what occurs when a user application calls a system call. The full path of this process is as follows:
368368

369369
* User application contains code that fills general purposer register with the values (system call number and arguments of this system call);
370370
* Processor switches from the user mode to kernel mode and starts execution of the system call entry - `entry_SYSCALL_64`;

SysCall/syscall-3.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ As we can see, at the beginning of the `map_vsyscall` function we get the physic
5555
ffffffff81881000 D __vsyscall_page
5656
```
5757
58-
in the `.data..page_aligned, aw` [section](https://en.wikipedia.org/wiki/Memory_segmentation) and contains call of the three folowing system calls:
58+
in the `.data..page_aligned, aw` [section](https://en.wikipedia.org/wiki/Memory_segmentation) and contains call of the three following system calls:
5959
6060
* `gettimeofday`;
6161
* `time`;
@@ -105,7 +105,7 @@ enum fixed_addresses {
105105
...
106106
```
107107

108-
It equal to the `511`. The second argument is the physical address of the the page that has to be mapped and the third argument is the flags of the page. Note that the flags of the `VSYSCALL_PAGE` depend on the `vsyscall_mode` variable. It will be `PAGE_KERNEL_VSYSCALL` if the `vsyscall_mode` variable is `NATIVE` and the `PAGE_KERNEL_VVAR` otherwise. Both macros (the `PAGE_KERNEL_VSYSCALL` and the `PAGE_KERNEL_VVAR`) will be expanded to the following flags:
108+
It equal to the `511`. The second argument is the physical address of the page that has to be mapped and the third argument is the flags of the page. Note that the flags of the `VSYSCALL_PAGE` depend on the `vsyscall_mode` variable. It will be `PAGE_KERNEL_VSYSCALL` if the `vsyscall_mode` variable is `NATIVE` and the `PAGE_KERNEL_VVAR` otherwise. Both macros (the `PAGE_KERNEL_VSYSCALL` and the `PAGE_KERNEL_VVAR`) will be expanded to the following flags:
109109

110110
```C
111111
#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
@@ -168,7 +168,7 @@ __vsyscall_page:
168168
ret
169169
```
170170

171-
And the start address of the `vsyscall` page is the `ffffffffff600000` everytime. So, the [glibc](https://en.wikipedia.org/wiki/GNU_C_Library) knows the addresses of the all virutal system call handlers. You can find definition of these addresses in the `glibc` source code:
171+
And the start address of the `vsyscall` page is the `ffffffffff600000` everytime. So, the [glibc](https://en.wikipedia.org/wiki/GNU_C_Library) knows the addresses of the all virtual system call handlers. You can find definition of these addresses in the `glibc` source code:
172172

173173
```C
174174
#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
@@ -180,7 +180,7 @@ All virtual system call requests will fall into the `__vsyscall_page` + `VSYSCAL
180180
181181
In the second case, if we pass `vsyscall=emulate` parameter to the kernel command line, an attempt to perform virtual system call handler will cause a [page fault](https://en.wikipedia.org/wiki/Page_fault) exception. Of course, remember, the `vsyscall` page has `__PAGE_KERNEL_VVAR` access rights that forbid execution. The `do_page_fault` function is the `#PF` or page fault handler. It tries to understand the reason of the last page fault. And one of the reason can be situation when virtual system call called and `vsyscall` mode is `emulate`. In this case `vsyscall` will be handled by the `emulate_vsyscall` function that defined in the [arch/x86/entry/vsyscall/vsyscall_64.c](https://github.com/torvalds/linux/blob/master/arch/x86/entry/vsyscall/vsyscall_64.c) source code file.
182182
183-
The `emulate_vsyscall` function gets the number of a virtual system call, checks it, prints error and sends [segementation fault](https://en.wikipedia.org/wiki/Segmentation_fault) single:
183+
The `emulate_vsyscall` function gets the number of a virtual system call, checks it, prints error and sends [segmentation fault](https://en.wikipedia.org/wiki/Segmentation_fault) single:
184184
185185
```C
186186
...
@@ -284,7 +284,7 @@ extern const struct vdso_image vdso_image_x32;
284284
#endif
285285
```
286286

287-
If our kernel is configured for the `x86` architecture or for the `x86_64` and compability mode, we will have ability to call a system call with the `int 0x80` interrupt, if compability mode is enabled, we will be able to call a system call with the native `syscall instruction` or `sysenter` instruction in other way:
287+
If our kernel is configured for the `x86` architecture or for the `x86_64` and compatibility mode, we will have ability to call a system call with the `int 0x80` interrupt, if compatibility mode is enabled, we will be able to call a system call with the native `syscall instruction` or `sysenter` instruction in other way:
288288

289289
```C
290290
#if defined CONFIG_X86_32 || defined CONFIG_COMPAT
@@ -395,7 +395,7 @@ Links
395395
* [BUILD_BUG_ON](http://0xax.gitbooks.io/linux-insides/content/Initialization/linux-initialization-1.html)
396396
* [Processor register](https://en.wikipedia.org/wiki/Processor_register)
397397
* [Page fault](https://en.wikipedia.org/wiki/Page_fault)
398-
* [segementation fault](https://en.wikipedia.org/wiki/Segmentation_fault)
398+
* [segmentation fault](https://en.wikipedia.org/wiki/Segmentation_fault)
399399
* [instruction pointer](https://en.wikipedia.org/wiki/Program_counter)
400400
* [stack pointer](https://en.wikipedia.org/wiki/Stack_register)
401401
* [uname](https://en.wikipedia.org/wiki/Uname)

SysCall/syscall-4.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This part will be last part in this chapter and as you can understand from the p
1616
how do we launch our programs?
1717
--------------------------------------------------------------------------------
1818

19-
There are many different ways to launch an application from an user perspective. For example we can run a program from the [shell](https://en.wikipedia.org/wiki/Unix_shell) or double-click on the application icon. It does not matter. The Linux kernel handles application launch regardless how we do launch this application.
19+
There are many different ways to launch an application from a user perspective. For example we can run a program from the [shell](https://en.wikipedia.org/wiki/Unix_shell) or double-click on the application icon. It does not matter. The Linux kernel handles application launch regardless how we do launch this application.
2020

2121
In this part we will consider the way when we just launch an application from the shell. As you know, the standard way to launch an application from shell is the following: We just launch a [terminal emulator](https://en.wikipedia.org/wiki/Terminal_emulator) application and just write the name of the program and pass or not arguments to our program, for example:
2222

@@ -68,12 +68,12 @@ $ strace uname
6868
execve("/bin/uname", ["uname"], [/* 62 vars */]) = 0
6969
```
7070
71-
So, an user application (`bash` in our case) calls the system call and as we already know the next step is Linux kernel.
71+
So, a user application (`bash` in our case) calls the system call and as we already know the next step is Linux kernel.
7272
7373
execve system call
7474
--------------------------------------------------------------------------------
7575
76-
We saw preparation before a system call called by an user application and after a system call handler finished its work in the second [part](http://0xax.gitbooks.io/linux-insides/content/SysCall/syscall-2.html) of this chapter. We stopped at the call of the `execve` system call in the previous paragraph. This system call defined in the [fs/exec.c](https://github.com/torvalds/linux/blob/master/fs/exec.c) source code file and as we already know it takes three arguments:
76+
We saw preparation before a system call called by a user application and after a system call handler finished its work in the second [part](http://0xax.gitbooks.io/linux-insides/content/SysCall/syscall-2.html) of this chapter. We stopped at the call of the `execve` system call in the previous paragraph. This system call defined in the [fs/exec.c](https://github.com/torvalds/linux/blob/master/fs/exec.c) source code file and as we already know it takes three arguments:
7777
7878
```
7979
SYSCALL_DEFINE3(execve,
@@ -161,7 +161,7 @@ The `sched_exec` function is used to determine the least loaded processor that c
161161

162162
After this we need to check [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) of the give executable binary. We try to check does the name of the our binary file starts from the `/` symbol or does the path of the given executable binary is interpreted relative to the current working directory of the calling process or in other words file descriptor is `AT_FDCWD` (read above about this).
163163

164-
If one of these checks is successfull we set the binary parameter filename:
164+
If one of these checks is successful we set the binary parameter filename:
165165

166166
```C
167167
bprm->file = file;
@@ -227,7 +227,7 @@ if (retval < 0)
227227
goto out;
228228
```
229229

230-
fills the `linux_binprm` structure with the `uid` from [inode](https://en.wikipedia.org/wiki/Inode) and read `128` bytes from the binary executable file. We read only first `128` from the executable file because we need to check a type of our executable. We will read the rest of the executable file in the later step. After the preparation of the `linux_bprm` structure we copy the filename of the executable binary file, command line arguments and enviroment variables to the `linux_bprm` with the call of the `copy_strings_kernel` function:
230+
fills the `linux_binprm` structure with the `uid` from [inode](https://en.wikipedia.org/wiki/Inode) and read `128` bytes from the binary executable file. We read only first `128` from the executable file because we need to check a type of our executable. We will read the rest of the executable file in the later step. After the preparation of the `linux_bprm` structure we copy the filename of the executable binary file, command line arguments and environment variables to the `linux_bprm` with the call of the `copy_strings_kernel` function:
231231

232232
```C
233233
retval = copy_strings_kernel(1, &bprm->filename, bprm);
@@ -249,7 +249,7 @@ And set the pointer to the top of new program's stack that we set in the `bprm_m
249249
bprm->exec = bprm->p;
250250
```
251251

252-
The top of the stack will contain the program filename and we store this fileneme tothe `exec` field of the `linux_bprm` structure.
252+
The top of the stack will contain the program filename and we store this filename to the `exec` field of the `linux_bprm` structure.
253253

254254
Now we have filled `linux_bprm` structure, we call the `exec_binprm` function:
255255

@@ -277,7 +277,7 @@ search_binary_handler(bprm);
277277
function. This function goes through the list of handlers that contains different binary formats. Currently the Linux kernel supports following binary formats:
278278
279279
* `binfmt_script` - support for interpreted scripts that are starts from the [#!](https://en.wikipedia.org/wiki/Shebang_%28Unix%29) line;
280-
* `binfmt_misc` - support differnt binary formats, according to runtime configuration of the Linux kernel;
280+
* `binfmt_misc` - support different binary formats, according to runtime configuration of the Linux kernel;
281281
* `binfmt_elf` - support [elf](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) format;
282282
* `binfmt_aout` - support [a.out](https://en.wikipedia.org/wiki/A.out) format;
283283
* `binfmt_flat` - support for [flat](https://en.wikipedia.org/wiki/Binary_file#Structure) format;
@@ -394,7 +394,7 @@ That's all. From this point our programm will be executed.
394394
Conclusion
395395
--------------------------------------------------------------------------------
396396
397-
This is the end of the fourth and last part of the about the system calls concept in the Linux kernel. We saw almost all related stuff to the `system call` concept in these four parts. We started from the understanding of the `system call` concept, we have learned what is it and why do users applications need in this concept. Next we saw how does the Linux handle a system call from an user application. We met two similar concepts to the `system call` concept, they are `vsyscall` and `vDSO` and finally we saw how does Linux kernel run an user program.
397+
This is the end of the fourth and last part of the about the system calls concept in the Linux kernel. We saw almost all related stuff to the `system call` concept in these four parts. We started from the understanding of the `system call` concept, we have learned what is it and why do users applications need in this concept. Next we saw how does the Linux handle a system call from a user application. We met two similar concepts to the `system call` concept, they are `vsyscall` and `vDSO` and finally we saw how does Linux kernel run a user program.
398398
399399
If you have questions or suggestions, feel free to ping me in twitter [0xAX](https://twitter.com/0xAX), drop me [email]([email protected]) or just create [issue](https://github.com/0xAX/linux-insides/issues/new).
400400

0 commit comments

Comments
 (0)