OS Structure
OS Structure
Structure
OS Services
An operating system provides an environment for the execution of
programs by providing services to users and programs.
UI
• The three primary approaches for interacting with an operating
system are
(1) command interpreters
(2) graphical user interfaces
(3) touchscreen interfaces
System Call Example
cp in.txt out.txt (when file names read from user)
System Calls
System calls can be divided into six major categories: (1) process
control (2) file management (3) device management (4) information
maintenance (5) communications and (6) protection.
1- Process control
◦ create process terminate process
◦ load execute
◦ get process attributes set process attributes
◦ wait event signal event
◦ allocate and free memory
System Calls cont…
2- File management 3- Device management
◦ create file delete file ◦ request device release device
◦ open close ◦ read write reposition
◦ read write reposition ◦ get device attributes set
◦ get file attributes set file device attributes
attributes ◦ logically attach or detach
devices
System Calls cont…
4- Information maintenance 5- Communications
◦ get time or date set time or date ◦ create delete communication
◦ get system data set system data connection
◦ get process file or device attributes ◦ send receive messages
◦ set process file or device attributes ◦ transfer status information
◦ attach or detach remote devices
6- Protection
◦ get file permissions
◦ set file permissions
Linker &
Loader
• A linker combines several
relocatable object modules
into a single binary
executable file.
• A loader loads the
executable file into memory
making it eligible to run on
an available CPU.
Relocating Symbols and Resolving
External• Symbols
References
are lexical entities that name functions and variables.
• Each symbol has a value (typically a memory address).
• Code consists of symbol definitions and references.
• References can be either local or external.
m.c a.c
int e=7; extern int e;
Def of local
symbol e int main() { int *ep=&e; Ref to
int r = a(); int x=15; external
exit(0); int y; symbol e
} Def of
local int a() { Defs of
Ref to external symbol return *ep+x+y; local
} symbols
symbol exit Ref to external ep
(defined in x and y
symbol a Def of
libc.so) Refs of local
local
symbols epxy
symbol a
m.o Relocation Info
m.c
int e=7; Disassembly of section .text:
00000000 <e>:
0: 07 00 00 00
source: objdump
a.o Relocation Info (.text)
a.c
extern int e; Disassembly of section .text:
00000000 <a>:
int *ep=&e;
0: 55 pushl %ebp
int x=15; 1: 8b 15 00 00 00 movl 0x0%edx
int y; 6: 00
3: R_386_32 ep
int a() { 7: a1 00 00 00 00 movl 0x0%eax
return *ep+x+y; 8: R_386_32 x
} c: 89 e5 movl %esp%ebp
e: 03 02 addl (%edx)%eax
10: 89 ec movl %ebp%esp
12: 03 05 00 00 00 addl 0x0%eax
17: 00
14: R_386_32 y
18: 5d popl %ebp
19: c3 ret
a.o Relocation Info (.data)
a.c
extern int e; Disassembly of section .data:
00000000 <ep>:
int *ep=&e;
0: 00 00 00 00
int x=15; 0: R_386_32 e
int y; 00000004 <x>:
4: 0f 00 00 00
int a() {
return *ep+x+y;
}
Executable After Relocation and
External Reference Resolution (.text)
08048530 <main>:
8048530: 55 pushl %ebp
8048531: 89 e5 movl %esp%ebp
8048533: e8 08 00 00 00 call 8048540 <a>
8048538: 6a 00 pushl $0x0
804853a: e8 35 ff ff ff call 8048474 <_init+0x94>
804853f: 90 nop
08048540 <a>:
8048540: 55 pushl %ebp
8048541: 8b 15 1c a0 04 movl 0x804a01c%edx
8048546: 08
8048547: a1 20 a0 04 08 movl 0x804a020%eax
804854c: 89 e5 movl %esp%ebp
804854e: 03 02 addl (%edx)%eax
8048550: 89 ec movl %ebp%esp
8048552: 03 05 d0 a3 04 addl 0x804a3d0%eax
8048557: 08
8048558: 5d popl %ebp
8048559: c3 ret
Executable After Relocation and
External Reference Resolution(.data)
m.c
int e=7;
Disassembly of section .data:
int *ep=&e;
int x=15; 0804a020 <x>:
int y; 804a020: 0f 00 00 00
int a() {
return *ep+x+y;
}
Merging Re-locatable Object Files
into an Executable Object File
Re-locatable Object Files Executable Object File