Legacy Containers and OS Personalitiesos.inf.tu-dresden.de/Studium/KMB/WS2008/09-legacy... · 2008....
Transcript of Legacy Containers and OS Personalitiesos.inf.tu-dresden.de/Studium/KMB/WS2008/09-legacy... · 2008....
Faculty of Computer Science Institute for System Architecture, Operating Systems Group
Legacy Containers andOS Personalities
Dresden, 2008-12-16
Carsten Weinhold
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 2
So far...
So far:– Basics Concepts:
● Tasks, Threads, IPC● Memory, Synchronization, ...
– Device Drivers– Real-Time– Naming– Virtualization
Today:– Legacy Containers / OS Personalities
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 3
Motivation
What are legacy containers / OS personalities?● Emulation environment● Allow to run legacy applications
How is it different from virtualization?● Adaptation can be above hardware / OS layer● Often requires recompilation of the application
Why?● Reuse existing applications / APIs● Flexibility / Configurability● Lower resource consumption● Sometimes easier to achieve
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 4
Where to Cut?
Adaptation to underlying system can happen at various levels:
• Hardware level (virtualization):– Legacy OS and applications are moved to new
OS (full + para virtualization, e.g., L4Linux)
• OS level:– Legacy OS's interfaces are reimplemented on
top of new OS (e.g., Wine on Linux)
• Application level:
– Toolkits, frameworks, libraries (e.g., Qt)
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 5
Straightforward Way to OS Personality
Single-server approach:
– All (legacy) system services provided by a single server (e.g., L4Linux)
– No isolation among services
– Provides high level of compatibility, as original implementations are reused
– Ideally, applications do not need to be modified
Ext2 VFAT IP
Disk Driver NIC Driver
AppApp
Syscall Entry
SingleServer
Microkernel
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 6
Multiple Single Servers
• Multiple instances of single-server OSes
• Useful for isolation of applications
• Not necessarily identical OS personalities (e.g., have UNIX and Windows servers)
• “Virtual machines”
UNIX App
SingleServer
UNIX
Microkernel
UNIX App
SingleServer
UNIX
Windows App
SingleServer
Windows
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 7
Application Scenarios for Single Server
Hybrid applications (real time):
• “Enlightened” applications:
– Major parts of applications (e.g., GUIs) do not require real-time guarantees
– Small parts (e.g., device controller) may need real-time guarantees, can run next to legacy container
• Examples:– RT network, RT file system,
RT window system / widget
App
SingleServer
Microkernel
Real-TimeInfrastructure
Real-TimeServer
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 8
Application Scenarios for Single Server
Hybrid applications (security):
• “Enlightened” applications:
– Most parts are not security critical
– Small parts require strong isolation from potentially insecure legacy container
• Examples:– Cryptographic algorithms and
key handling
More in following lectures!
App
SingleServer
Microkernel
SecurityInfrastructure
SecurityServer
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 9
Single Server to Multi Server
Ext2 VFAT IP
Disk Driver NIC Driver
AppApp
Ext2 VFAT IP
Disk Driver NIC Driver
AppApp
Syscall Entry
Monolith
MicrokernelMicrokernel
Move from single server to multi server
Challenge: Application wants a consistent viewin a distributed system
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 10
Approach: Central Server
Ext2 VFAT IP
Disk Driver NIC Driver
Process / VFS / Net / ...
AppApp
• Central server provides consistent view for both:
– Applications• System resources (files, ...)
– Servers• Client state (file tables, ...)
• Problem:– Performance bottleneck– Scalability– Complexity
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 11
Approach: Emulation Library
Ext2 VFAT IP
Disk Driver NIC Driver
AppApp
• Emulation library
– Per application– Interacts with servers– Provides consistent view
• Each servers keeps its own client state
• In real world:
– Applications use C library, emulation library hidden below
– Emulation provides POSIX API
EmulationLibrary
EmulationLibrary
C Library C Library
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 12
Legacy Environment: POSIX
• POSIX “Portable Operating System Interface” is a family of standards (POSIX 1003.*)
• POSIX makes various UNIX-like systems compatible (even Windows NT and newer)
• Defines interfaces and properties:– I/O: files, sockets, terminal, ...– Threads / synchronization: PThread– System tools– ...
• POSIX API accessible via C library
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 13
C Library: API to POSIX
• Collection of various common functions• Abstraction layer above system calls
• Functions with different abstraction levels ...– low level: memcpy(), strlen()– medium: fopen(), fread()– high level: getpwent()
• ... and dependencies– none (freestanding): memcpy(), strlen()– small: malloc(): uses mmap() or sbrk()– strong: getpwent(): file access, “/etc/passwd”,
name service, ...
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 14
Multi-Server Aware C Library
• Observations:– C library depends on underlying OS– Specific implementation may differ
Application
libc + syscall bindings
Monolithic / Single-Server OS
System Call Interface
MemoryServer
Memory Interface
l4vfs_*(), rtc_*(),dm_phys_*(), ...
memcpy(), fopen(),getpwent()
TimeBE
FileBE
MemBE
...
libc
open(), read(),mmap()
FileSystem
File System Interface
Application
+ Backends
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 15
Example: uClibc on L4
• What is uClibc?– Reimplementation of C library– Designed for Embedded Linux– Compatible to GNU C library “glibc”
• Why uClibc?– Small and portable– Optional C++ support available (uClibc++)– Licensed under LGPL
• uClibc + backends provide applications with a consistent view of L4-based multi-server OS
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 16
C Library Backends in L4Env
• C library functions grouped in backends• Simple example 1: timeunsigned int offset;void l4libc_init_time(void){ int ret;
l4_calibrate_tsc(); ret = l4rtc_get_offset_to_realtime(&offset); if (ret != 0) { /* RTC server not found, /* assuming 1/1/1970, 0:00 */ offset = 0; }}
extern unsigned int offset;time_t time(time_t *t){ time_t t_temp; l4_uint32_t s, ns;
l4_tsc_to_s_and_ns(l4_rdtsc(), &s, &ns); /* get (cached) system time offset */ t_temp = s + offset; if (t) *t = t_temp; return t_temp;}
1. Initalization:Call time server
2. Usage:Calculate current time based on time stamp counter (nocall to time server necessary)
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 17
Flexibility of C Library Backends
Multiple implementations for some backends:
– Memory backends:• self_mem• sigma0_mem, sigma0_pool_mem• simple_mem• buddy_slab_mem,• TLSF (real-time memory allocator)
– I/O backends:• minimal_log_io, io
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 18
Example 2: Minimalist I/O Backend
• Minimalist I/O backend:– Simple backend for writing to STDOUT/STDERR– Uses L4/Fiasco kernel debugger
#include <unistd.h>#include <errno.h>
#include <l4/sys/kdebug.h>
int write(int fd, const void *buf, size_t count) __THROW{ /* just accept write to stdout and stderr */ if ((fd == STDOUT_FILENO) || (fd == STDERR_FILENO)) { l4kdb_outnstring((const char*)buf, count); return count; }
/* writes to other fds shall fail fast */ errno = EBADF; return -1;}
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 19
Example 3: Complex I/O Backend
• Complex I/O backend: L4VFS
• Example:1)App calls open(“/dev/tty0”)
2)Resolve name at name servera)Backend calls name serverb)Name server calls server con_term, gets back reference to tty0
3)Backend opens tty0, server con_term updates client state
4)Backend updates local file table5)Libc returns local file handle
Application (“test1”, 1c.2)
Libc
I/OBack-end
fd_table(12.2):230
12
con_term(12.2)
client_state’tty0’:1c.2:’r’:0
’tty2’:1e.4:’rw’:0
232425
name_server(11.0)
1 5
3
2a
2b
4(12.2):24
’tty0’:1c.2:’w’:0
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 20
Example 4: POSIX Signals on L4
• Signals used to deliver asynchronous event notifications– Exceptions (SIGFPE, SIGSEGV, SIGCHLD, ...)– Issued by applications (SIGUSR1, SIGUSR2,
SIGTERM, ...)
• Signals on Linux– built-in kernel mechanism– delivered upon return from kernel
• Signals on L4– implement in user space– map signals to L4 IPC?– Problem: IPC is synchronous!
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 21
POSIX Signals on L4
signal server
Application A Application B
libl4sig
Signal Thread(b.04)
register_handler()
register_handler()
setup signalhandlers
setup signalhandlerssetup signalhandlers
signal_threads
A a.03
B b.04
libl4sig
Signal Thread(a.03) signal(A,
SIGUSR1)notify(SIGUSR1)
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 22
POSIX Signals on L4: Mechanics
• How signals are dispatched:1) Signal thread choses arbitrary application
thread E (except for L4Env threads)2) Stores E's thread state (EIP, ESP)3) Forces E to run configured signal handler on
dedicated stack4) After E returns from handler: restore original
EIP and ESP• Specialties:
– SIGSTOP: set all threads to l4sleep()– SIGALRM: dedicated timer provided by the
signal server– SIGKILL: signal server kills application at task
server
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 23
Configurability of C Library Backends
Unnecessary backends can be omitted:– Applications rely on less components– Potentially better security properties– Smaller memory footprint
MemoryServer
Memory Interface
File SystemServer
File System Interface
TimeBE
FileBE
MemBE
...
libc + Backends
File-System Application
TimeBE
NetBE
MemBE
...
libc + Backends
Network Application
PF_INETServer
Network Interface
PF_LOCALServer
Network Interface
MemBE
libc + Backends
Simple Application
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 24
Summary: POSIX Emulation on L4Env
• L4Env offers significant part of POSIX APIs:– C library: all platform independent parts
• strcpy(), ...
– Dynamic memory allocation• Various backends
– I/O support (files, network, terminal, time):• L4VFS + L4VFS servers• RTC server
– Signal handling:• signal
– No PThread support (but is available in L4Re)
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 25
More Powerful Legacy Containers
• POSIX is limited to basic OS abstractions:
– No graphics / GUI support– No audio support
• Examples for more powerful APIs:
– SDL “Simple Direct Layer”(focuses on Multimedia)
– Qt toolkit(focuses on rich GUIs and complete OS abstraction)
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 26
Qt Toolkit on L4Env
• What is Qt?– Multi-platform toolkit library– Provides abstraction of underlying OS– Available for:
● UNIX/X11 (Linux, *BSD, ...)● Windows● Mac OS X● ... and L4Env (+Bastei port mostly done)
• Qt/L4 based on Qt3 for embedded Linux:– Has its own “Qt Windowing System” (QWS)– Relies on POSIX compliant OS
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 27
Qt Architecture
Qt API
File Access
Application
Operating System
NetworkThreads /
SynchGUI ...
POSIX / L4VFS POSIX / L4VFSL4Env / thread,
semaphore QWS
Platform Independent
Platform Specific
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 28
Graphical Console
libinput(Hardware Access)
Qt/L4: Qt Windowing System
• QWS is core part of Qt/L4:– Displays and manages windows from multiple
Qt applications– Operates on shared framebuffer– Events distributed via shared memory /
socketsQt App
(+ acts as QWS Server)
Qt library
FBDriver
Keyb.Driver
MouseDriver
Qt App
Qt library
FBDriver
Qt App
Qt library
FBDriver
QWSServerCode
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 29
Qt/L4: Features
• Complete support of GUI framework
• Threads, Synchronization supported
• Support for file access– Depends on available L4VFS file servers
• Support for network access– Basic functionality with L4VFS server “FLIPS”
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 30
Qt/L4: Easy Development
• Applications (or parts of them) can be developed and tested on Linux
• Rapid Application Development:– GUIs can be created with Qt Designer– Other tools (e.g, UI compiler) can also usable
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 31
DEMO
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 32
Coming soon...
• Later today:● Practical exercise in E042
• Next year: ● Big topic “security” starting on January 6● 5th exercise on January 13
TU Dresden, 2008-12-16 MOS - Legacy Containers Slide 33
References
• Carsten Weinhold: 'Portierung von Qt auf DROPS' Großer Beleg 2005http://os.inf.tu-dresden.de/paper_ps/weinhold-beleg.pdf
• Resources on POSIX standard: http://standards.ieee.org/regauth/posix/
• Previous slide sets for MOS lectures