[APRESS] OS X and iOS Kernel Programming (Ole Henry Halvorsen) (2012).pdf
(
4926 KB
)
Pobierz
Master kernel programming for
efficiency and performance
OS X
and
iOS Kernel
Programming
Ole Henry Halvorsen
|
Douglas Clarke
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Contents at a Glance
About the Authors................................................................................................ xiv
About the Technical Reviewers ............................................................................ xv
Acknowledgments ............................................................................................... xvi
Introduction ........................................................................................................ xvii
Chapter 1: Operating System Fundamentals ..........................................................1
Chapter 2: Mac OS X and iOS ................................................................................15
Chapter 3: Xcode and the Kernel Development Environment ..............................39
Chapter 4: The I/O Kit Framework ........................................................................51
Chapter 5: Interacting with Drivers from Applications........................................69
Chapter 6: Memory Management .........................................................................99
Chapter 7: Synchronization and Threading ........................................................119
Chapter 8: Universal Serial Bus ..........................................................................141
Chapter 9: PCI Express and Thunderbolt ............................................................173
Chapter 10: Power Management ........................................................................205
Chapter 11: Serial Port Drivers...........................................................................223
Chapter 12: Audio Drivers...................................................................................249
Chapter 13: Networking......................................................................................275
Chapter 14: Storage Systems .............................................................................319
Chapter 15: User-Space USB Drivers ..................................................................357
Chapter 16: Debugging .......................................................................................381
Chapter 17: Advanced Kernel Programming ......................................................411
Chapter 18: Deployment .....................................................................................429
Index ...................................................................................................................443
iv
Introduction
Kernel development can be a daunting task and is very different from programming traditional user
applications. The kernel environment is more volatile and complex. Extraordinary care must be taken to
ensure that kernel code is free of bugs because any issue may have serious consequences to the stability,
security, and performance of the system. This book covers the fundamentals necessary to begin
programming in the kernel. We cover kernel development from a theoretical and practical point of view.
We cover concepts fundamental to kernel development such as virtual memory and synchronization, as
well as more practical knowledge. The book primarily focuses on Mac OS X, however the XNU kernel is
also used by iOS, and hence the theoretical material in this book will also apply to it. By far the most
common reason for doing development within the kernel’s execution environment is to implement a
device driver for controlling internal or external hardware devices. Because of this, much of the focus of
this book is centred on the development of device drivers. The primary framework for device driver
development in the XNU kernel is I/O Kit, which we cover extensively. As theory becomes boring quickly
we have provided working code samples which you can play with to learn more or use as a starting point
for your own drivers.
We hope you have as much fun reading this book as we have enjoyed writing it.
Who Is This Book For?
The book was written for anyone interested in Apple’s iOS and Mac OS X operating systems, with a focus
on practical kernel development, especially driver devel. Regardless of whether you are a hobbyist,
student, or professional engineer, we hope to provide you with material of interest. While the focus is on
kernel programming and development, we will cover many theoretical aspects of OS technology and
provide a detailed overview of the OS X and iOS kernel environments. The aim of the book is to provide
the knowledge necessary to start developing your own kernel extensions and drivers. We will focus in
particular on the I/O Kit framework for writing device drivers and extensions, but we will also cover
general knowledge that will give you a deeper understanding of how I/O Kit interacts with the OS. If you
are mainly interested in developing OS X or iOS user applications, this book may not be for you. We will
not cover Cocoa or any other framework used for developing end-user applications. This book covers
kernel-programming topics such as driver and kernel extension development on Apple’s OS X and iOS
platform.
Some knowledge of operating system internals will be useful in understanding the concepts
discussed in this book. Having completed an introductory computer science or engineering course will
be a helpful starting point. Additionally, knowledge of at least one programming language will be
required in order to understand examples throughout the book. Since we focus on I/O Kit, which is
written in a subset of C++ called Embedded C++, it would be highly beneficial to have some experience
with C++ (or at least C) to make the most of this book. The book does not cover general programming
topics or theory. We will briefly cover some fundamentals of OS theory to provide a context for further
discussions.
xvii
INTRODUCTION
Book Structure
The following is a brief description of each chapter in this book:
Chapter 1, Operating System Fundamentals.
Details the functionality of an operating system and
its role in managing the computer’s hardware resources. We describe the purpose of device drivers and
when they are needed, and introduce the differences between programming in the kernel environment
as compared to standard application development.
Chapter 2, Mac OS X and iOS.
Provides a brief overview of the technical structure of XNU, the kernel
used by Mac OS X and iOS.
Chapter 3, Xcode and the Kernel Development Environment.
Provides an overview of the
development tools provided by Apple for Mac OS X and iOS development. The chapter ends with a short
“Hello world” kernel extension.
Chapter 4, The I/O Kit Framework.
Introduces the I/O Kit framework that provides the driver model
for Mac OS X and its object-oriented architecture. We explain how the I/O Kit finds the appropriate
device driver to manage a hardware device. We demonstrate a generic device driver to illustrate the basic
structure of any I/O Kit driver.
Chapter 5, Interacting with Drivers from Applications.
Explains how application code can access a
kernel driver. We demonstrate how to search and match against a specific driver as well as how to install
a notification to wait for the arrival of a driver or a particular device. We will show how an application
can send commands to a driver and watch for events sent by the driver.
Chapter 6, Memory Management.
Provides an overview of kernel memory management and the
different types of memory that a driver needs to work with. We describe the differences between physical
and kernel virtual addresses and user-space memory. We also introduce the reader to the concepts such
as memory descriptors and memory mapping.
Chapter 7, Synchronization and Threading.
Describes the fundamentals of synchronization and
why it is a necessity for every kernel driver. We discuss the usage of kernel locking mechanisms such as
IOLock and IOCommandGate and their appropriate use. We explain how a typical driver requires
synchronization between its own threads, user-space threads, and hardware interrupts. We discuss the
kernel facilities for creating kernel threads and asynchronous timers.
Chapter 8, USB Drivers.
Introduces the reader to the architecture of USB and how a driver
interfaces with them. We provide an overview of the I/O Kit USB API and the classes it provides for
enumerating devices and transferring data to or from a USB device. We also discuss steps needed to
support device removal and provide an example to show how a driver can enumerate resources such as
pipes.
Chapter 9, PCI and Thunderbolt.
Provides an overview of the PCI architecture. We also describe the
concepts that are unique to PCI drivers, such as memory-mapped I/O, high-speed data transfer through
Direct Memory Access (DMA), and handling of device interrupts. We give an overview of the
IOPCIDevice
class that the I/O Kit provides for accessing and configuring PCI devices. We also discuss the related and
more recent Thunderbolt technology.
Chapter 10, Power Management.
Describes the methods that drivers need to implement in order to
allow the system to enter low power states such as machine sleep. We also describe advanced power
management that a driver can implement if it wishes to place its hardware into a low power state after a
period of inactivity.
Chapter 11, Serial Port Drivers.
Describes how to implement a serial port driver on Mac OS X. We
introduce relevant data structures such as circular queues and techniques for managing data flow
through blocking I/O and notification events. We show how a user application can enumerate and
access a serial port driver.
xviii
Plik z chomika:
Ryjufka
Inne pliki z tego folderu:
[SAMS] Cocoa Programming (Scott Anguish) (2002).pdf
(9155 KB)
Advanced Graphics Programming Using OpenGL (Tom McReynolds, David Blythe).pdf
(13052 KB)
Absolute FreeBSD (Michael W. Lucas).pdf
(7836 KB)
Beginning iOS Game Development (Patrick Alessi).pdf
(20539 KB)
Begining iPad Development for iPhone Developers (Jack Nutting).pdf
(6606 KB)
Inne foldery tego chomika:
[Eng] Android books
BPM Business Process Modeling
IT Ebooks Mega Pack
IT Ebooks Programming
IT epub
Zgłoś jeśli
naruszono regulamin