Professional Documents
Culture Documents
AOS-Unit1-Notes
AOS-Unit1-Notes
AOS-Unit1-Notes
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
SYLLABUS
UNIT I: Overview of UNIX system calls. The anatomy of a system call and x86
mechanisms for system call implementation. How the MMU/memory translation,
segmentation, and hardware traps interact to create kernel–user context separation.
What makes virtualization work? The kernel execution and programming context.
Live debugging and tracing. Hardware and software support for debugging.
1
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Lecture- 1
UNIT I
UNIX system calls are used to manage the file system, control processes,and to provide
interprocess communication. The UNIX system interface consists of about 80 system
calls (as UNIX evolves this number will increase). The following table lists about 40 of
the more important system call:
close()
Input/Output read()
write()
Files unlink()
fstat()
chmod()
chown()
umask()
2
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
exit()
getuid()
getgid()
getegid()
getppid()
kill()
alarm()
msgsnd()
msgrcv()
msgctl()
Semaphores semget()
semop()
shmat()
shmdt()
3
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
[NOTE: The system call interface is that aspect of UNIX that has changed the most
since the inception of the UNIX system. Therefore, at the time of writing a software
tool, one should protect that tool by putting system calls in other subroutines within
the program and then calling only those subroutines. Should the next version of the
UNIX system change the syntax and semantics of the system calls now used, needs
only to change the interface routines.]
4
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Lecture- 2
The anatomy of a System call and x86 mechanisms for system call
implementation.
NaCl syscalls are the interface between untrusted code and the trusted codebase.
They are the means by which a NaCl process can execute code outside the inner
sandbox. This is kind of a big deal, because the entire point of NaCl is to prevent
untrusted code from getting out of the inner sandbox. Accordingly, the design and
implementation of the syscall interface is a crucial part of the NaCl system.
This figure shows the flow of control:
5
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
1. Exits the hardware sandbox (on non-SFI implementations) by restoring the original
system value of
%ds.
2. Calls the untrusted-to-trusted context switch function (NaCl Syscall Seg)
The many ways of implementing user-to-kernel transitions on x86, i.e. system calls.
Let’s first quickly
review what system calls actually need to accomplish.
Secure in this context means that the application cannot just jump to arbitrary kernel
code, because that would effectively allow the application to do what it wants on the
system. The kernel must be able to configure defined entry points and the system call
mechanism of the processor must enforce these.
After the system call is handled, the operating system also needs to know where to
return to in the application, so the system call mechanism also has to provide this
information.
Now, let us with four mechanisms that match this description that work for 64-bit
environments.
save the weirder ones that only work on 32-bit for another post. So we have:
6
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Because interrupt vector 0x80 can still be used to invoke system calls2 on 64-bit Linux,
we are going to stick with this example:
The processor finds the kernel entry address by taking the interrupt vector number from
the int instruction and looking up the corresponding descriptor in the Interrupt
Descriptor Table (IDT). This descriptor will be an Interrupt or Trap Gate3 to kernel
mode and it contains the pointer to the handling function in the kernel.
7
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Lecture- 3
A virtual address must be translated to a physical address before a memory access can
take place (because we must know which physical memory location we are accessing).
This need for translation also applies to cached data, because on Armv6 and later
processors, the data caches store data using the physical address (addresses that are
physically tagged). Therefore, the address must be translated before a cache lookup can
complete.
Note: Architecture is a behavioural specification. The caches must behave as if they are
physically tagged. An implementation might do something different, as long as this is
not software-visible.
Table entry
8
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
The translation tables work by dividing the virtual address space into equal-sized
blocks and by providing one entry in the table per block.
Entry 0 in the table provides the mapping for block 0, entry 1 provides the mapping
for block 1, and so on. Each entry contains the address of a corresponding block of
physical memory and the attributes to use when accessing the physical address.
Table lookup
A table lookup occurs when a translation takes place. When a translation happens,
the virtual address that is issued by the software is split in two, as shown in this
diagram:
9
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
The upper-order bits, which are labelled 'Which entry' in the diagram, tell you which
block entry to look in and they are used as an index into the table. This entry block
contains the physical address for the virtual address.
The lower-order bits, which are labelled 'Offset in block' in the diagram, are an offset
within that block and are not changed by the translation.
Multilevel translation
In a single-level lookup, the virtual address space is split into equal-sized blocks. In
practice, a hierarchy of tables is used.
The first table (Level 1 table) divides the virtual address space into large blocks. Each
entry in this table can point to an equal-sized block of physical memory or it can point
to another table which subdivides the block into smaller blocks. We call this type of
table a 'multilevel table'.
Here we can see an example of a multilevel table that has three levels:
10
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
In Armv8-A, the maximum number of levels is four, and the levels are numbered 0 to
3. This multilevel approach allows both larger blocks and smaller blocks to be
described. The characteristics of large and small blocks are as follows:
Large blocks require fewer levels of reads to translate than small blocks. Plus, large
blocks are more efficient to cache in the TLBs.
Small blocks give software fine-grain control over memory allocation. However, small
blocks are less efficient to cache in the TLBs. Caching is less efficient because small
blocks require multiple reads through the levels to translate.
To manage this trade-off, an OS must balance the efficiency of using large mappings
against the flexibility of using smaller mappings for optimum performance.
Note: The processor does not know the size of the translation when it starts the table
lookup. The processor works out the size of the block that is being translated by
performing the table walk.
Lecture- 4
Segmentation
11
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
The details about each segment are stored in a table called a segment table. Segment
table is stored in one (or many) of the segments.
Till now, we were using Paging as our main memory management technique. Paging is
closer to the Operating system rather than the User. It divides all the processes into the
form of pages regardless of the fact that a process can have some relative parts of
functions which need to be loaded in the same page.
The operating system doesn't care about the User's view of the process. It may divide
the same function into different pages and those pages may or may not be loaded at the
same time into the memory. It decreases the efficiency of the system.
It is better to have segmentation which divides the process into segments. Each segment
contains the same type of functions such as the main function can be included in one
segment and the library functions can be included in the other segment.
12
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
1. Segment Number
2. Offset
For Example:
Suppose a 16 bit address is used with 4 bits for the segment number and 12 bits for the
segment offset so the maximum segment size is 4096 and the maximum number of
segments that can be refereed is 16.
When a program is loaded into memory, the segmentation system tries to locate space
that is large enough to hold the first segment of the process, space information is
obtained from the free list maintained by memory manager. Then it tries to locate space
for other segments. Once adequate space is located for all the segments, it loads them
into their respective areas.
The operating system also generates a segment map table for each program.
13
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
With the help of segment map tables and hardware assistance, the operating system can
easily translate a logical address into physical address on execution of a program.
The Segment number is mapped to the segment table. The limit of the respective segment
is compared with the offset. If the offset is less than the limit then the address is valid
otherwise it throws an error as the address is invalid.
In the case of valid addresses, the base address of the segment is added to the offset to get
the physical address of the actual word in the main memory.
The above figure shows how address translation is done in case of segmentation.
Advantages of Segmentation
1. No internal fragmentation
14
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
3. Less overhead
5. The segment table is of lesser size as compared to the page table in paging.
Disadvantages
Lecture- 5
15
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
is −
16
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
In the above image, the user process executes in the user mode until it gets a system
call. Then a system trap is generated, and the mode bit is set to zero. The system call
gets executed in kernel mode.
After the execution is completed, again a system trap is generated and the mode bit is
set to 1. The system control returns to kernel mode and the process execution
continues.
Necessity of Dual Mode (User Mode and Kernel Mode) in Operating System
The lack of a dual mode i.e user mode and kernel mode in an operating system can
cause serious
problems. Some of these are −
A running user program can accidentaly wipe out the operating system by overwriting
it withuser data.
Multiple processes can write in the same system at the same time, with disastrous
results.
Lecture- 6
17
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
18
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
The Operating system may have the capability to allow or deny access to such
resources based on which the program requests them and the user account in the
context of which it runs. OS may also hide these resources, which leads that when a
computer program computes them, they do not appear in the enumeration results.
Nevertheless, from a programming perspective, the computer program has interacted
with those resources and the operating system has managed an act of interaction.
With operating-system-virtualization or containerization, it is probable to run
programs within containers, to which only parts of these resources are allocated. A
program that is expected to perceive the whole computer, once run inside a container,
can only see the allocated resources and believes them to be all that is available.
Several containers can be formed on each operating system, to each of which a subset
of the computer’s resources is allocated. Each container may include many computer
programs. These programs may run parallel or distinctly, even interrelate with each
other.
Operating system-based virtualization can raise demands and problems related to
performance overhead, such as:
1. The host operating system employs CPU, memory, and other hardware IT resources.
2. Hardware-related calls from guest operating systems need to navigate numerous layers
to and from the hardware, which shrinkage overall performance.
3. Licenses are frequently essential for host operating systems, in addition to individual
licenses for each of their guest operating systems.
19
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
In the dictionary a kernel is a softer, usually edible part of a nut, seed, or fruit stone
contained within its shell such as “the kernel of a walnut”. It can also be the central or
most important part of something “this is the kernel of the argument”.
In computing the kernel is a computer program that is the core of a computer’s
operating system,
with complete control over everything in the system.
The kernel is often one of the first programs loaded up on start-up before the boot
loader.
“A boot loader is a type of program that loads and starts the boot time tasks and
processes of an operating system or the computer system. It enables loading the
operating system within the computer memory when a computer is started or booted up.
A boot loader is also known as a boot manager or bootstrap loader.”
You have probably heard the expression of ‘booting up’ a system. The bootloader
translates the data- processing instructions for the central processing unit. The
bootloader handles memory and peripherals like keyboards, monitors and speakers.
The boot system for all standard computers and operating systems
An inkling that the kernel was important as part of the computer system operation,
however it is unsure of how it operates. As such, found more information about the
Linux Kernel in particular.
20
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Lecture- 7
21
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
The Linux kernel is a free and open-source, monolithic, Unix-like operating system
kernel. This can berepresented as such.
A system call is a way for programs to interact with the operating system. A computer
program makes a system call when it makes a request to the operating system’s kernel.
System call provides the services of the operating system to the user programs via
Application Program Interface(API).
In an article on the geek stuff the interaction between the computer hardware, OS
Kernel, System Functions, Application Code and Library Functions:
22
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Application code used in one environment and can be changed to alter the behaviour.
As an example of the difference, I’ll implement a sample logging mechanism. One
written as application code and one written as library code.
As such the difference between a microkernel and a monolithic kernel lies within the
system calls as well as the ‘kernel space’.
23
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
24
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Debug and trace enables you to monitor the application for errors and exception with
out VS.NET IDE. In Debug mode compiler inserts some debugging code inside the
executable. As the debugging code is the part of the executable they run on the same
thread where the code runs and they do not given you the exact efficiency of the code (
as they run on the same thread). So, for every full executable DLL you will see a debug
file also as shown in figure ‘Debug Mode'. Trace works in both debug as well as release
mode. The main advantage of using trace over debug is to do performance analysis
which can not be done by debug. Trace runs on a different thread thus it does not
impact the main code thread. There is also a fundamental difference in thinking when
we want to use trace and when want to debug. Tracing is a process about getting
information regarding program's execution. On the other hand, debugging is about
finding errors in the code.
25
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Lecture-8
26
l
O
M
o
A
R
c
P
S
D
|
3
6
8
2
2
8
3
6
Description: To debug a program, user has to start with a problem, isolate the source
code of the problem, and then fix it. A user of a program must know how to fix the
problem as knowledge about problem analysis is expected. When the bug is fixed, then
the software is ready to use. Debugging tools (called debuggers) are used to identify
coding errors at various development stages. They are used to reproduce the conditions
in which error has occurred, then examine the program state at that time and locate the
cause. Programmers can trace the program execution step-by-step by evaluating the
value of variables and stop the execution wherever required to get the value of variables
or reset the program variables. Some programming language packages provide a
debugger for checking the code for errors while it is being written at run time.
Lecture- 9
DOUBT SESSION,
Assignment – 1
27