CS222: Systems Programming The Basics January 24, 2008 A Designated Center of Academic Excellence in Information Assurance Education by the National Security Agency
Agenda Operating System Essentials Windows API Hardware Abstraction Layer Windows Principles Win64 2 1/25/2008
Deep Thought for the Day There are only 10 types of people in this world those who understand binary, and those who don t. 3 1/25/2008
Class Email List I will use the email address listed on BanWeb for the class email list If you prefer I use another address, email it to me. 4 1/25/2008
Computer Architecture System of Layers 5 1/25/2008
Operating Systems What is an operating system? Where do we find operating systems? 6 1/25/2008
Operating System Features Memory File systems Resource naming and location Multitasking Communication and synchronization Security and protection 7 1/25/2008
The Kernel Central component of an OS Manages resources Interface between software and hardware Provides lowest level abstraction layer that applications must control Memory, Processor, I/O 8 1/25/2008
The Kernel 9 1/25/2008
Hardware Abstraction Layer (HAL) Enables porting to different processor architectures Primary architecture: x86 (Intel), AMD 64-bit processors Intel Itanium, AMD Athlon 64 and Opteron 64 (AMD64) Intel 64-bit x86 extensions Other architectures Windows Mobile and Windows CE run on mobile platforms Windows NT was originally supported on DEC Alpha 10 1/25/2008
Windows API Application Programming Interface (API) Makes the OS components available Has its own set of conventions and programming techniques Scalable Evolving Also known as Win32 API 11 1/25/2008
Windows API Functional Categories Administration and Management Diagnostics Graphics and Multimedia Networking Security System Services Windows User Interface 12 1/25/2008
Other API s POSIX Portable Operating System Interface for unix Formally designated IEEE 1003 Specifies user and software interface to the OS Standard command line and scripting interface User-level programs, services, and utilities Program-level services Standard threading library Supported by NT Kernel 13 1/25/2008
Windows Principles Many system resources are represented as a kernel object identified and referenced by a handle Kernel objects must be manipulated by Windows APIs Objects include files, processes, threads, pipes, memory mapping, events, etc. Objects have security attributes Many functions perform the same or similar operations Function calls will often have numerous parameters and flags, many of which can normally be ignored 14 1/25/2008
Windows Principles Windows offers numerous synchronization and communication mechanisms tailored for different requirements The thread is the basic unit of execution. A process can contain one or more threads. Windows function names are long and descriptive WaitForSingleObject WaitForSingleObjectEx WaitForMultipleObjects WaitNamedPipe 15 1/25/2008
Windows Principles Conventions for type names Predefined data types, required by the API, are in uppercase and descriptive BOOL HANDLE DWORD LPTSTR LPSECURITY_ATTRIBUTES Many others 16 1/25/2008
Naming Conventions (cont.) Predefined types avoid the * operator and make distinctions such as differentiating LPTSTR (defined as TCHAR *) LPTCTSTR (defined as const TCHAR *) Variable names in function prototypes also have conventions lpszfilename Long pointer to a zero-terminated string dwaccess A double word (32 bits) containing file access flags dw denotes flags in a double word 17 1/25/2008
Naming Conventions (cont.) The Windows API is backward compatible with the Win16 API The long pointer is simply a 32-bit or 64-bit pointer. Win32 sometimes appears in macro names (WIN32_FIND_DATA) even though the macro is also used with Win64 Numerous 16-bit functions are available, but should not be used OpenFile (16-bit) CreateFile (32-bit) 18 1/25/2008
Win64 vs Win32 Main differences Size of the pointer variables Size of the virtual address space 2 32 = 4294967296 4 GB 2 64 = 18446744073709551616 18 exabytes (kilo, mega, giga, tera, peta, exa) Be careful about assumptions concerning pointers and integers being the same size DWORD32 and DWORD64 are defined POINTER_32 and POINTER_64 control pointer size 19 1/25/2008
When to use C Most file processing can be done using ANSI Standard C library Why use C, instead of Windows system calls? Portability Why use Windows system calls? More powerful Better performance Additional capability File locking Memory mapping Asynchronous I/O Inter-process Communication 20 1/25/2008
Example Sequential File Copy Using C Using Windows Using convenience function 21 1/25/2008
Review Operating System Essentials Windows API Hardware Abstraction Layer Windows Principles Win64 Development Environment Setup and Demo 22 1/25/2008
For next class Monday, January 29 Read Chapter 2 in Windows System Programming Assignment 1 will be delivered next week 23 1/25/2008