@@ -28,7 +28,7 @@ Linux system calls implementation
28
28
29
29
At a high level system calls are "services" offered by the kernel to
30
30
user applications and they resemble library APIs in that they are
31
- described as a function call with a name, parameters and return value.
31
+ described as a function call with a name, parameters, and return value.
32
32
33
33
.. slide :: System Calls as Kernel services
34
34
:inline-contents: True
@@ -90,8 +90,8 @@ actual system calls in order to make it easier for applications to use
90
90
them.
91
91
92
92
When a user to kernel mode transition occurs, the execution flow is
93
- interrupted and it is transfered to a kernel entry point. This is
94
- similar with how interrupts and exception are handled (in fact on some
93
+ interrupted and it is transferred to a kernel entry point. This is
94
+ similar to how interrupts and exceptions are handled (in fact on some
95
95
architectures this transition happens as a result of an exception).
96
96
97
97
The system call entry point will save registers (which contains values
@@ -100,7 +100,7 @@ parameters) on stack and then it will continue with executing the
100
100
system call dispatcher.
101
101
102
102
.. note :: During the user - kernel mode transition the stack is also
103
- switched from ther user stack to the kernel stack. This is
103
+ switched from the user stack to the kernel stack. This is
104
104
explained in more details in the interrupts lecture.
105
105
106
106
.. slide :: Example of Linux system call setup and handling
@@ -247,7 +247,7 @@ System call parameters handling
247
247
248
248
Handling system call parameters is tricky. Since these values are
249
249
setup by user space, the kernel can not assume correctness and must
250
- always verify them throughly .
250
+ always verify them thoroughly .
251
251
252
252
Pointers have a few important special cases that must be checked:
253
253
@@ -264,7 +264,7 @@ Since system calls are executed in kernel mode, they have access to
264
264
kernel space and if pointers are not properly checked user
265
265
applications might get read or write access to kernel space.
266
266
267
- For example, lets consider the case where such a check is not made for
267
+ For example, let's consider the case where such a check is not made for
268
268
the read or write system calls. If the user passes a kernel-space
269
269
pointer to a write system call then it can get access to kernel data
270
270
by later reading the file. If it passes a kernel-space pointer to a
@@ -281,7 +281,7 @@ read system call then it can corrupt kernel memory.
281
281
282
282
Likewise, if a pointer passed by the application is invalid
283
283
(e.g. unmapped, read-only for cases where it is used for writing), it
284
- could "crash" the kernel. There two approaches that could be used:
284
+ could "crash" the kernel. Two approaches could be used:
285
285
286
286
.. slide :: Invalid pointers handling approaches
287
287
:inline-contents: True
@@ -318,7 +318,7 @@ space to determine the cause:
318
318
But in the last two cases we don't have enough information to
319
319
determine the cause of the fault.
320
320
321
- In order to solve this issue Linux uses special APIs (e.g
321
+ In order to solve this issue, Linux uses special APIs (e.g
322
322
:c:func: `copy_to_user `) to accesses user space that are specially
323
323
crafted:
324
324
@@ -360,8 +360,8 @@ system call implementation, in a way that does not impact libc with
360
360
having to track the CPU capabilities in conjunction with the kernel
361
361
version.
362
362
363
- For example: x86 has two ways of issuing system calls: int 0x80 and
364
- sysenter. The later is significantly faster so it should be used when
363
+ For example, x86 has two ways of issuing system calls: int 0x80 and
364
+ sysenter. The latter is significantly faster so it should be used when
365
365
available. However, it is only available for processors newer than
366
366
Pentium II and only for kernel versions greater than 2.6.
367
367
@@ -392,7 +392,7 @@ With VDSO the system call interface is decided by the kernel:
392
392
393
393
394
394
395
- An interesting development of the VDSO are the virtual system calls
395
+ An interesting development of the VDSO is the virtual system calls
396
396
(vsyscalls) which run directly from user space. These vsyscalls are
397
397
also part of VDSO and they are accessing data from the VDSO page that
398
398
is either static or modified by the kernel in a separate read-write
@@ -417,9 +417,9 @@ Accessing user space from system calls
417
417
418
418
As we mentioned earlier, user space must be accessed with special APIs
419
419
(:c:func: `get_user `, :c:func: `put_user `, :c:func: `copy_from_user `,
420
- :c:func: `copy_to_user `) that check wether the pointer is in user space
420
+ :c:func: `copy_to_user `) that check whether the pointer is in user space
421
421
and also handle the fault if the pointer is invalid. In case of invalid
422
- pointers they return a non zero value.
422
+ pointers, they return a non- zero value.
423
423
424
424
.. slide :: Accessing user space from system calls
425
425
:inline-contents: True
@@ -458,8 +458,8 @@ Let's examine the simplest API, get_user, as implemented for x86:
458
458
})
459
459
460
460
461
- The implementation uses inline assembly, that allows inserting ASM
462
- sequences in C code and also handles access to / from variables in the
461
+ The implementation uses inline assembly, which allows inserting ASM
462
+ sequences in C code and also handles access to/ from variables in the
463
463
ASM code.
464
464
465
465
Based on the type size of the x variable, one of __get_user_1,
@@ -603,7 +603,7 @@ is accessed by the fault handler:
603
603
}
604
604
605
605
606
- All it does is to set the return address to the one in the to field of
606
+ All it does is to set the return address to the one in the field of
607
607
the exception table entry which, in case of the get_user exception
608
608
table entry, is bad_get_user which return -EFAULT to the caller.
609
609
0 commit comments