• No results found

CS222: Systems Programming

N/A
N/A
Protected

Academic year: 2021

Share "CS222: Systems Programming"

Copied!
23
0
0

Loading.... (view fulltext now)

Full text

(1)

CS222:

Systems Programming

The Basics

January 24, 2008

(2)

 Operating System Essentials

 Windows API

 Hardware Abstraction Layer

 Windows Principles

 Win64

Agenda

(3)

Deep Thought for the Day

 There are only 10 types of people in this world – those who understand binary,

and those who don’t.

(4)

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.

(5)

Computer Architecture

System of Layers

(6)

Operating Systems

 What is an operating system?

 Where do we find operating systems?

(7)

Operating System Features

 Memory

 File systems

 Resource naming and location

 Multitasking

 Communication and synchronization

 Security and protection

(8)

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

(9)

The Kernel

(10)

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

(11)

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

(12)

Windows API

 Functional Categories

– Administration and Management – Diagnostics

– Graphics and Multimedia – Networking

– Security

– System Services

– Windows User Interface

(13)

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

(14)

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

(15)

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

(16)

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…

(17)

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

(18)

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)

(19)

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

(20)

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

(21)

Example

 Sequential File Copy

– Using C

– Using Windows

– Using convenience function

(22)

Review

 Operating System Essentials

 Windows API

 Hardware Abstraction Layer

 Windows Principles

 Win64

 Development Environment Setup and

Demo

(23)

For next class

 Monday, January 29

– Read Chapter 2 in “Windows System Programming”

 Assignment 1 will be delivered next

week

References

Related documents

Abstract The Global Trigger Tool (GTT) developed by the Institute for Healthcare Improvement is a method for retrospective patient record review based on the use of

Hydraulic System P1 P2 P3 Boom Bucket Travel Option Swing Arm Travel Swing motor Swivel joint Travel motor Gear pump Main pump Engine Travel motor... boom selector

We aspire to become the recognized center for such work and to have our research become widely cited and used to improve policy making and risk manage- ment for regulators and

To analyze the risk of power plant curtailment due to high effluent discharge temperatures, a multiple linear regression model for intake cooling water temperature in combination

Having reviewed its system fixed assets to identify assets that may be potentially uneconomic, Transpower is satisfied that an EV analysis of these assets would not result in an

Effect of Psychotropic Medication on Foster Care Experience and Outcomes: A Causal Analysis using Administrative Data..

National Conference on Student Recruitment, Marketing, and Retention July 2006 Prospect Inquiry Applicant Acceptance Confirmation Enroll Initiative 1 Determine what areas of your

Behavior algorithms for adaptive waypoints can be developed using the methods of GP and graduated embodiment by staged optimization, as highlighted in Figure 8-2. The advantage