Chapter 01
Chapter 01
• Assembling hardware
and programming
simple programs were
the norm (Assembly
Language)
• Large complex
programs are difficult
and time-consuming to
develop
• Users began to
demand more
functionality in
programs
MSDOS source code © Microsoft Corporation. Used under
Microsoft Research License Agreement
http://www.computerhistory.org/atchm/microsoft-research-license-agreement-msdos-v1-1-v2-0/
• Linux
supports dynamic
loadable modules
• Example: Windows NT
Architecture (Windows
2000, Windows XP, Vista,
Windows 7, Windows 8 )
• Example: BeOS
• Example: Minix
4 Virtual CPU
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
The Process Model (1)
CPU
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
The Process Model (3)
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Programs v. Processes
1. Process Initialized
5. Interrupted
6. Finished or aborted
7. Exits
Types of Processes
• User Processes - Applications executing on behalf or a user.
• Example: gcc
1. call-gate descriptor.
2. interrupt-gate descriptor.
3. trap-gate descriptor.
4. task-gate descriptor.
3. Save the program counter and reload it with the kernel entry
point.
sched.h 1182
1183
1184
unsigned int rt_priority;
const struct sched_class *sched_class;
struct sched_entity se;
1185 struct sched_rt_entity rt;
1186
1187 #ifdef CONFIG_PREEMPT_NOTIFIERS
1188 /* list of struct preempt_notifier: */
1189 struct hlist_head preempt_notifiers;
1190 #endif
1191
1192 /*
1193 * fpu_counter contains the number of consecutive context switches
1194 * that the FPU is used. If this is over a threshold, the lazy fpu
1195 * saving becomes unlazy to save the trap. This is an unsigned char
1196 * so that after 256 times the counter wraps and the behavior turns
1197 * lazy again; this to deal with bursty apps that only use FPU for
1198 * a short time
1199 */
1200 unsigned char fpu_counter;
1201 s8 oomkilladj; /* OOM kill score adjustment (bit shift). */
© 2017 Trevor Bakker and The University of Texas at Arlington
Linux Task_Struct
• Cons?
• Time
int main()
{
int x = 0xDEAD;
int y = 0xBEEF;
int z = x + y;
return z;
}
00000000004000b0 <main>:
4000b0: 55 push %rbp
4000b1: 48 89 e5 mov %rsp,%rbp
4000b4: c7 45 f4 ad de 00 00 movl $0xdead,0xfffffffffffffff4(%rbp)
4000bb: c7 45 f8 ef be 00 00 movl $0xbeef,0xfffffffffffffff8(%rbp)
4000c2: 8b 45 f8 mov 0xfffffffffffffff8(%rbp),%eax
4000c5: 03 45 f4 add 0xfffffffffffffff4(%rbp),%eax
4000c8: 89 45 fc mov %eax,0xfffffffffffffffc(%rbp)
4000cb: 8b 45 fc mov 0xfffffffffffffffc(%rbp),%eax
4000ce: c9 leaveq
4000cf: c3 retq
int main()
{
int x = 0xDEAD;
int y = 0xBEEF;
int z = 0;
z = add_numbers( x, y );
return z;
}
0000000000000000 <main>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 83 ec 10 sub $0x10,%rsp
8: c7 45 f4 ad de 00 00 movl $0xdead,0xfffffffffffffff4(%rbp)
f: c7 45 f8 ef be 00 00 movl $0xbeef,0xfffffffffffffff8(%rbp)
16: c7 45 fc 00 00 00 00 movl $0x0,0xfffffffffffffffc(%rbp)
1d: 8b 75 f8 mov 0xfffffffffffffff8(%rbp),%esi
20: 8b 7d f4 mov 0xfffffffffffffff4(%rbp),%edi
23: e8 00 00 00 00 call add_numbers
28: 89 45 fc mov %eax,0xfffffffffffffffc(%rbp)
2b: 8b 45 fc mov 0xfffffffffffffffc(%rbp),%eax
2e: c9 leaveq
2f: c3 retq
Let’s compile our example and tell the compiler we are going
to use a shared library
00000000004002e0 <add_numbers@plt-0x10>:
4002e0: ff 35 b2 01 20 00 pushq 2097586(%rip) # 600498 <_GLOBAL_OFFSET_TABLE_+0x8>
4002e6: ff 25 b4 01 20 00 jmpq *2097588(%rip) # 6004a0 <_GLOBAL_OFFSET_TABLE_+0x10>
4002ec: 0f 1f 40 00 nopl 0x0(%rax)
00000000004002f0 <add_numbers@plt>:
4002f0: ff 25 b2 01 20 00 jmpq *2097586(%rip) # 6004a8 <_GLOBAL_OFFSET_TABLE_+0x18>
4002f6: 68 00 00 00 00 pushq $0x0
4002fb: e9 e0 ff ff ff jmpq 4002e0 <add_numbers@plt-0x10>
Disassembly of section .text:
0000000000400300 <main>:
400300: 55 push %rbp
400301: 48 89 e5 mov %rsp,%rbp
400304: 48 83 ec 10 sub $0x10,%rsp
400308: c7 45 f4 ad de 00 00 movl $0xdead,0xfffffffffffffff4(%rbp)
40030f: c7 45 f8 ef be 00 00 movl $0xbeef,0xfffffffffffffff8(%rbp)
400316: c7 45 fc 00 00 00 00 movl $0x0,0xfffffffffffffffc(%rbp)
40031d: 8b 75 f8 mov 0xfffffffffffffff8(%rbp),%esi
400320: 8b 7d f4 mov 0xfffffffffffffff4(%rbp),%edi
400323: e8 c8 ff ff ff callq 4002f0 <add_numbers@plt>
400328: 89 45 fc mov %eax,0xfffffffffffffffc(%rbp)
40032b: 8b 45 fc mov 0xfffffffffffffffc(%rbp),%eax
40032e: c9 leaveq
40032f: c3 retq
• glibc library