Systems Programming - Lecture 04
Systems Programming - Lecture 04
Aamir Pare
Windows System Programing
Agenda
Operating System Essentials Windows API Hardware Abstraction Layer Windows Principles Win64
Computer Architecture
Layered View of OS
Operating Systems
What is an operating system? Where do we find operating systems?
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
Windows System Programing
The Kernel
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
Windows System Programing
Windows API
Functional Categories Administration and Management Diagnostics Graphics and Multimedia Networking Security System Services Windows User Interface
Windows System Programing
Other APIs
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
Windows System Programing
Windows Principles
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 Many system resources are represented as a kernel object identified and referenced by a handle Function calls will often have numerous parameters and flags, many of which can normally be ignored
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
Windows System Programing
Windows Principles
Conventions for type names Predefined data types, required by the API, are in uppercase and descriptive BOOL HANDLE DWORD LPTSTR LPSECURITY_ATTRIBUTES Windows Many othersSystem Programing
A double word (32 bits) containing file access flags dw denotes flags in a double word
Windows System Programing
Win64 vs Win32
Main differences Size of the pointer variables Size of the virtual address space
232= 4294967296
4 GB
264= 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
Windows System Programing
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
Windows System Programing
Example
Sequential File Copy Using C Using Windows Using convenience function
Review
Operating System Essentials Windows API Hardware Abstraction Layer Windows Principles Win64 Development Environment Setup and Demo
Windows System Programing