systems programming - lecture 04
TRANSCRIPT
-
8/4/2019 Systems Programming - Lecture 04
1/21
Windows System Programing
Systems Programming
The Basics
October 10, 2009
Aamir Pare
-
8/4/2019 Systems Programming - Lecture 04
2/21
Windows System Programing
Agenda
Operating System Essentials
Windows API
Hardware Abstraction LayerWindows Principles
Win64
-
8/4/2019 Systems Programming - Lecture 04
3/21
Windows System Programing
Deep Thought for the Day
There are only 10 types of people in this
world those who understand binary, and
those who dont.
-
8/4/2019 Systems Programming - Lecture 04
4/21
Windows System Programing
Computer Architecture
Layered View of OS
-
8/4/2019 Systems Programming - Lecture 04
5/21
Windows System Programing
Operating Systems
What is an operating system?
Where do we find operating systems?
-
8/4/2019 Systems Programming - Lecture 04
6/21
Windows System Programing
Operating System Features
Memory
File systems
Resource naming and locationMultitasking
Communication and synchronization
Security and protection
-
8/4/2019 Systems Programming - Lecture 04
7/21
Windows System Programing
The Kernel
Central component of an OS
Manages resources
Interface between software andhardware
Provides lowest level abstraction layer
that applications must controlMemory, Processor, I/O
-
8/4/2019 Systems Programming - Lecture 04
8/21
Windows System Programing
The Kernel
Kernel and other OS Objects
-
8/4/2019 Systems Programming - Lecture 04
9/21
Windows System Programing
Hardware Abstraction Layer (HAL)
Enables porting to different processor architectures
Primary architecture: x86 (Intel), AMD
64-bit processors
Intel Itanium, AMD Athlon64 and Opteron64 (AMD64)
Intel 64-bit x86 extensions
Other architectures
Windows Mobile and Windows CE run on mobileplatforms
Windows NT was originally supported on DEC Alpha
-
8/4/2019 Systems Programming - Lecture 04
10/21
Windows System Programing
Windows API
Application Programming Interface (API)
Makes the OS components available
Has its own set of conventions andprogramming techniques
Scalable
EvolvingAlso known as Win32 API
-
8/4/2019 Systems Programming - Lecture 04
11/21
Windows System Programing
Windows API
Functional Categories
Administration and Management
Diagnostics
Graphics and Multimedia
Networking
Security
System Services
Windows User Interface
-
8/4/2019 Systems Programming - Lecture 04
12/21
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 servicesStandard threading library
Supported by NT Kernel
-
8/4/2019 Systems Programming - Lecture 04
13/21
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 kernelobjectidentified and referenced by a handle
Function calls will often have numerous parameters and
flags, many of which can normally be ignored
-
8/4/2019 Systems Programming - Lecture 04
14/21
Windows System Programing
Windows Principles
Windows offers numerous synchronization and
communication mechanisms tailored for
different requirements
The threadis the basic unit of execution. Aprocess can contain one or more threads.
Windows function names are long and
descriptiveWaitForSingleObject
WaitForSingleObjectEx
WaitForMultipleObjects
WaitNamedPipe
-
8/4/2019 Systems Programming - Lecture 04
15/21
Windows System Programing
Windows Principles
Conventions for type names
Predefined data types, required by the
API, are in uppercase and descriptive
BOOL
HANDLE
DWORDLPTSTR
LPSECURITY_ATTRIBUTES
Many others
-
8/4/2019 Systems Programming - Lecture 04
16/21
Windows System Programing
Naming Conventions (cont.)
Predefined types avoid the * operator and make distinctionssuch as differentiatingLPTSTR(defined as TCHAR *)
LPTCTSTR(defined as const TCHAR *)
Variable names in function prototypes also haveconventionslpszFileName
Long pointer to a zero-terminated stringdwAccess
A double word (32 bits) containing file access flags
dw denotes flags in a double word
-
8/4/2019 Systems Programming - Lecture 04
17/21
Windows System Programing
Naming Conventions (cont.)
The Windows API is backward compatible withthe Win16 API
The long pointer is simply a 32-bit or 64-bitpointer.
Win32 sometimes appears in macro names(WIN32_FIND_DATA) even though the macro isalso used with Win64
Numerous 16-bit functions are available, but
should not be usedOpenFile(16-bit)
CreateFile(32-bit)
-
8/4/2019 Systems Programming - Lecture 04
18/21
Windows System Programing
Win64 vs Win32
Main differences
Size of the pointer variables
Size of the virtual address space232= 4294967296
4 GB264= 18446744073709551616
18 exabytes (kilo, mega, giga, tera, peta, exa)
Be careful about assumptions concerning pointers and
integers being the same sizeDWORD32 and DWORD64 are defined
POINTER_32 and POINTER_64 control pointer size
-
8/4/2019 Systems Programming - Lecture 04
19/21
Windows System Programing
When to use C
Most file processing can be done using ANSI Standard Clibrary
Why use C, instead of Windows system calls?
Portability
Why use Windows system calls?
More powerful
Better performance
Additional capabilityFile locking
Memory mapping
Asynchronous I/O
Inter-process Communication
-
8/4/2019 Systems Programming - Lecture 04
20/21
Windows System Programing
Example
Sequential File Copy
Using C
Using WindowsUsing convenience function
-
8/4/2019 Systems Programming - Lecture 04
21/21
Windows System Programing
Review
Operating System Essentials
Windows API
Hardware Abstraction LayerWindows Principles
Win64
Development Environment Setup andDemo