0% found this document useful (0 votes)
97 views

Systems Programming - Lecture 04

This document covers the basics of systems programming on Windows. It discusses the Windows API, hardware abstraction layer, operating system essentials like memory management and multitasking, and key Windows principles. The document also touches on differences between Win32 and Win64 environments and when to use C versus Windows system calls for programming tasks. It concludes with an example comparing sequential file copying using each approach.

Uploaded by

Nabeel Jarral
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Systems Programming - Lecture 04

This document covers the basics of systems programming on Windows. It discusses the Windows API, hardware abstraction layer, operating system essentials like memory management and multitasking, and key Windows principles. The document also touches on differences between Win32 and Win64 environments and when to use C versus Windows system calls for programming tasks. It concludes with an example comparing sequential file copying using each approach.

Uploaded by

Nabeel Jarral
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Systems Programming The Basics October 10, 2009

Aamir Pare
Windows System Programing

Agenda
Operating System Essentials Windows API Hardware Abstraction Layer Windows Principles Win64

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.

Windows System Programing

Computer Architecture
Layered View of OS

Windows System Programing

Operating Systems
What is an operating system? Where do we find operating systems?

Windows System Programing

Operating System Features


Memory File systems Resource naming and location Multitasking Communication and synchronization Security and protection

Windows System Programing

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

Kernel and other OS Objects


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 mobile platforms Windows NT was originally supported on DEC Alpha

Windows System Programing

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 System Programing

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

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
Windows System Programing

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)
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

Windows System Programing

Review
Operating System Essentials Windows API Hardware Abstraction Layer Windows Principles Win64 Development Environment Setup and Demo
Windows System Programing

You might also like