Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Kernel
Debunking Mac OS Myths
lucy
28 Dec 2007
Mach
UNIX
microkernel
Open Source
FreeBSD
64 bit
C++
Mach
UNIX
microkernel
Open Source
On the Mac, this kernel is called Mach
FreeBSD
64 bit
C++
microkernel
Open
with itsSource
stable open-source core based on FreeBSD 5.0
FreeBSD
64 bit
C++
http://developer.apple.com/internet/
Mac OS X for Mach
UNIX Users
UNIX The power of UNIX with the simplicity of Macintosh.
Features Mac OS X version 10.4 Tiger combines a robust and open UNIX-based foundation
microkernel
with the richness and usability of the Mac interface, bringing UNIX technology and
Open source, UNIX-based foundation
64-bit power to the mass market. Apple has made open source and standards a key
• SMP-optimized kernel based on FreeBSD 5
and Mach 3.0
part of its strategy to deliver an industrial-strength operating system that is both
• 64-bit virtual memory based on the LP64 innovative and easy to use.
model There are over 15 million Mac OS X users—scientists, animators, developers, system
• Standard libraries and utilities for easy porting administrators, and more—making Mac OS X the most widely used UNIX-based
Open Source
of Linux, UNIX, and POSIX source code
desktop operating system. In addition, Mac OS X is the only UNIX-based environment
UNIX-based foundation
• Hand-tuned, standards-compliant scalar and
that natively runs Microsoft Office, Adobe Photoshop, and thousands of other consumer
vector math libraries
• UNIX GUI support via native toolkits and
applications—all side by side with traditional command-line, X11, and Java applications.
included X11 server Mac OS X is also the foundation for Mac OS X Server, which makes open source software
• Open source code available via the Darwin easy to administer. Tight integration with Apple hardware, from the sleek PowerBook
project G4 to the award-winning Xserve G5, is making Mac OS X the platform of choice for an
emerging generation of UNIX users.
Standards-based networking
• Complete IP-based architecture supporting
IPv4, IPv6, and L2TP/IPSec VPN
FreeBSD
• Rich zero-configuration discovery and naming
via Bonjour and Dynamic DNS
• Interoperable file serving via NFS, AFP,
SMB/CIFS, and FTP
• Powerful Apache services (httpd, DAV, PHP)
• Open Directory services built on LDAP and
Kerberos for single sign-on
64 bit
Comprehensive UNIX user environment
• Standards-based graphics built on PDF
(Quartz), OpenGL, H.264, and MPEG-4
C++
(QuickTime)
• Xterm-compliant Terminal integrated with
Aqua user interface
• Choice of shells (bash, ksh, csh) and scripting
languages (Perl, Python, Tcl, Ruby)
• Enhanced with Spotlight searching, Xgrid
queuing, and Automator workflows
• Comprehensive UNIX/Linux utilities (emacs,
vim, gnutar, make)
• Xcode 2 developer tools with GCC 4.0 for
optimized code generation and ISO/IEC
14882:2003 C++ support
Technology Brief
Mac OS X for UNIX Users http://images.apple.com/macosx/pdf/MacOSX_UNIX_TB_v2.pdf
Mach
UNIX
microkernel
Open Source
FreeBSD
64 bit
C++
microkernel
Open Source
Obsolete Microkernel Dooms Mac OS X to Lag Linux in Performance
FreeBSD
64 bit
C++
128 KB
M68K
3.5”
single tasking
Macintosh
Macintosh System 7
128 KB
M68K
3.5” PowerPC
Copland ?
single tasking multitasking
Macintosh System 7
Apple Jobs
1985
NeXT Jobs
Be
Gassée ?
1985 1991 1996
+ ?
NeXT Jobs
+
http://www.hawkwings.net/wp-content/uploads/2006/07/stevesellsNeXT.jpg
http://www.photonhunter.co.uk/~art/computers/nextscreenshot.gif
NEXTSTEP
UNIX base
preemptive multitasking
memory protection
Display PostScript PowerPC
68K
i386 Rhapsody
NEXTSTEP 1.0 PA-RISC
Apple acquisition
SPARC i386
HW IPC MM sched
hardware
Microkernel
App App App
libc
API
VFS net
sec
user mode dev
kernel mode HW IPC MM sched
hardware
BSD Single Server
App App App
libc
BSD
API
VFS net
sec
user mode dev
kernel mode HW IPC MM sched
hardware
4
write() {
}
kernel
3
user
monolithic
write();
0
4
ipc() {
}
kernel
3
user
microkernel
ipc();
0
4
ipc() {
}
kernel
3
user
BSD
microkernel write() {
ipc();
0
4
ipc() {
}
kernel
3
user
microkernel
ipc();
0
BSD Single Server
App App App
libc
BSD
API
VFS net
sec
dev
user mode
kernel mode HW IPC MM sched
hardware
Co-location
App App App
kernel mode
BSD
API
VFS net
sec
dev
HW IPC MM sched
hardware
Mach
task task task
ROM 4 4 4 4
I/O
•
I/O
I/O
memory
3 3 3
VGA
management
• scheduling
• inter-process
RAM communication
0 0 0 0
Mach IPC
4 4
3 3
0 0
Mach Interface
Generator (MIG)
4 4
3 3
main() { func(a,b,c) {
func(1,2,3);
} }
func(a,b,c) {
MIG msg.a = a; receive(msg);
msg.b = b; a = msg.a;
generated msg.c = c; b = msg.b;
code send(msg); c = msg.c;
} func(a,b,c);
0 0
Mach + BSD int 0x80
%eax
>0 <0
user
kernel fork() open() ...
syscalls syscalls
POSIX BSD
BSD process signal VFS /dev
thread sockets
Mach mach
task thread exception message
#ifdef
#ifdef
#ifdef
#ifdef
#ifdef
I/O-Kit
generic.cc special.cc
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>msdosfs</string>
<key>CFBundleIdentifier</key>
<string>com.apple.filesystems.msdosfs</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>msdosfs</string>
<key>CFBundlePackageType</key>
<key>OSBundleLibraries</key>
<string>KEXT</string>
<dict>
<key>CFBundleShortVersionString</key>
<string>1.5</string>
<key>com.apple.kpi.bsd</key>
<key>CFBundleSignature</key>
<string>8.0.0</string>
<string>????</string>
<key>CFBundleVersion</key>
<key>com.apple.kpi.libkern</key>
<string>1.5</string>
<string>9.0.0d3</string>
<key>IOKitPersonalities</key>
<dict/>
<key>com.apple.kpi.mach</key>
<key>OSBundleLibraries</key>
<string>8.0.0</string>
<dict>
<key>com.apple.kpi.bsd</key>
<key>com.apple.kpi.unsupported</key>
<string>8.0.0</string>
<string>8.0.0</string>
<key>com.apple.kpi.libkern</key>
<string>9.0.0d3</string>
</dict>
<key>com.apple.kpi.mach</key>
<string>8.0.0</string>
<key>com.apple.kpi.unsupported</key>
<string>8.0.0</string>
</dict>
</dict>
</plist>
Info.plist
Booting
PC/BIOS 1 MB
BIOS
MBR
Video
?
640KB
RAM
0 MB
Booting
EFI 4 GB
EFI
GPT
HFS+
/System/Library
CoreServices/boot.efi
Caches/com.apple.kernelcaches/ Video
Extensions
mach_kernel
HFS+
2 GB
RAM
0 GB
http://clc.its.psu.edu/Labs/Mac/Resources/blastimageconfig/images/SigBuild/Intel-Sig-BootPicker.JPG
Mach-O
$ file libSystem.dylib
libSystem.dylib: Mach-O universal binary with 4 architectures
libSystem.dylib (for architecture ppc7400): Mach-O dynamically linked shared library ppc
libSystem.dylib (for architecture ppc64): Mach-O 64-bit dynamically linked shared library ppc64
libSystem.dylib (for architecture i386): Mach-O dynamically linked shared library i386
libSystem.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
/usr/lib C:\WINDOWS\SYSTEM
/usr/lib64 C:\WINDOWS\SYSTEM32
C:\WINDOWS\SYSTEM64
$ file /mach_kernel
/mach_kernel: Mach-O universal binary with 2 architectures
/mach_kernel (for architecture i386):
Mach-O executable i386
/mach_kernel (for architecture ppc):
Mach-O executable ppc
Rosetta
Rosetta
(dynarec)
Rosetta (byte swapping)
libA libB libC
libA libB libC
libSystem
libSystem Rosetta (byte swapping)
user
kernel
XNU XNU
hardware hardware
ppc
i386
Architectures
i386
PowerPC
PA-RISC
68K (i386) i386
SPARC
kernel
3 GB
user
0 GB
kernel
user
0 GB
Mac OS X Intel
4/4 Split
4 GB switcher
kernel
user
0 GB
Mac OS X Intel
x86_64
2^47 intr handler
4 GB
kernel
user
0
x86_64
2^47 intr handler
4 GB
kernel
user
0
x86_64
2^47 intr handler
user
4 GB
0
iPhone
• ARM
• Custom Bootloader
• No real KEXTs
• Kernel Cache
What Makes XNU Great
What Makes XNU Great
#8
dtrace
What Makes XNU Great
#7
kernel cache
What Makes XNU Great
#6
Separation between Mach, BSD, I/O-Kit
What Makes XNU Great
#5
POSIX Conformance
What Makes XNU Great
#4
Mach Message API
What Makes XNU Great
#3
I/O-Kit
What Makes XNU Great
#2
Stable KEXT ABI
What Makes XNU Great
#1
Universal Binaries
Buzzwords
again
Mach
lucy