Top Banner
Operating System Architecture CS3026 Operating Systems Lecture 03
42

CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

May 04, 2018

Download

Documents

doannguyet
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

OperatingSystemArchitecture

CS3026OperatingSystemsLecture03

Page 2: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

TheRoleofanOperatingSystem• Serviceprovider– Provideasetofservicestosystemusers

• Resourceallocator– Exploitthehardwareresourcesofoneormoreprocessorsandallocateittouserprograms

• Controlprogram– ControltheexecutionofprogramsandoperationsofI/Odevices• interruptthemtosend/receivedataviaI/Oortore-allocatehardwareresourcestootheruserprograms

• ProtectionandSecurity– Protectmultipleprogramsrunningfromeachother– Secureuseraccesstodataanddefineownershipoffilesandprocesses

Page 3: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

OperatingSystemFunctions

ExecutionExecutionofProgramInstructions

MemoryProgram-relatedData

PersistentStorageFiles

ProgramneedsmemorytoexecuteProgramstoresdata

Page 4: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

CoreConcepts

Virtualization“Unlimited”resourcesandprograms

ConcurrencyConcurrentExecutionofprograms

PersistenceStorageofData

VirtualizationofProcessor(processes,threads)

VirtualizationofMemory(virtualaddressspace)

Principle:ContextSwitch“AllotmentofTime”

Principle:PagingandSegmentation“AllotmentofSpace”

Page 5: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

OperatingSystemsExecution Memory Storage

Virtualization Process,threadContext switchProcessControlBlockSwapping

VirtualmemorymanagementSegmentationFreespacemanagementPagingPagetableTLB

StoragevolumesFile system

Concurrency MutualexclusionLockingConditionvariablesSemaphoresDeadlock

Sharedmemory Locking

Persistence FilesanddirectoriesI/ODevicesHarddisk

Page 6: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

OperatingSystemStructure

TheKernel

Page 7: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

ProtectingtheOperatingSystemModesofOperation

• UserMode– Userprogramsexecuteinusermode

– Certainareasareprotectedfromuseraccess

– Certaininstructionsmaynotbeexecuted

• KernelMode– Operatingsystemexecutesinkernelmode

– Privilegedinstructionsmaybeexecuted

– Protectedareasofmemorymaybeaccessed

Page 8: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

OperatingSystem

Kernel

Page 9: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

BasicComponentsofUnixKernel

ProcessManagement

MemoryManagement

I/OManagement

VirtualMemory FileSystems

DeviceDriver

Terminals

Network

Paging/SegmentationPagereplacement

ProcesscreationProcessInterruptionProcessterminationSchedulingInter-processCommunication

SystemCallInterface

InterruptsandTraps

Page 10: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

UtilisingHardwareResources

• Hardwaresupports– Basicinstructionexecution– Interrupthandling– Basicmemoryaddressingmechanisms– User/kernelmodeoperationforprotectingresources

• Operatingsystemmanagessoftwareconstructsbasedonthesehardwareservices– Processmanagement– Virtualmemorymanagement– Filestorageandcommunicationmanagement

Page 11: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

TraditionalUnixKernel

Page 12: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

SystemCalls

CallingOperatingSystemFunctions

Page 13: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

SystemCalls

• Systemcallsaretheonlyentrypointintothekernel

• Categories– Processmanagement–Memorymanagement– Filemanagement– Devicemanagement– Communication

• Systemcallsareexecutedinkernelmode

Page 14: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

SystemCalls• Interfacebetweena

programandtheoperatingsystemkernel– Provideaccesstooperating

systemservices• Isanexplicitrequestto

thekernelmadeviaasoftwareinterrupt

• Executedinkernelmode– Requiresamodeswitch

• Eachsystemcallisidentifiedbyasystemcallnumber SystemcallNo

ModeSwitch

Page 15: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

SoftwareInterruptforSystemCalls

• Softwareinterruptduetosystemcalls– Modeswitchofprocessorhardware:Systemcallsonlyallowedtoexecuteinkernelmode

– Modebitmanagedbetheprocessor• Providestheabilitytodistinguishbetweenuserandkernelmode• Privilegedinstructionsonlyinkernelmode

Page 16: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

InvokingaSystemCall• Typically,anumberisassociated

witheachsystemcall– Theprocessinvokingthesystemcall

mustpassthesystemcallnumber tothekerneltoidentifythecorrespondingsystemcallserviceroutine

• Operatingsystemmaintainsatableofpointerstosystemcallserviceroutines,systemcallnumberisindexforthistable

• Operatingsystemhandlestheinvocationoftheserviceroutineandanyreturnstatus/values

printf()SystemCallNoi

SystemCallDispatchTable

sys_write()iKernel

Page 17: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

SystemCallHandling

• Whenaprocessrunninginusermodeinvokesasystemcall,theCPUswitchestokernelmodeandstartstheexecutionofakernelfunction

Usermode

Kernelmode

printf()

UserProgram

SystemCallNri

KernelSystemCall

DispatchTable

sys_write()i

Standardlibc library,functionprototypeinstdio.h

Page 18: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

InvokingaSystemCallinLinux

• Linuximplementsasystemcallhandlertomanagetheinvocationofsystemcallserviceroutines

• SystemDispatchTableholdsalltheserviceroutineaddresses– SystemCallnumberisindexintothistable

int main(){

...xyz()...

}

int xyz(){

...“SYSCALL”...

}

ApplicationProgram

Wrapperroutineinlibc standardlibrary

...call sys_xyz()...“SYSEXIT”

int sys_xyz(){

...}

SystemCallHandler

SystemCallServiceRoutine

UserMode KernelMode

AssemblerinstructionswitchingCPUintoKernelModel

AssemblerinstructionswitchingCPUbackintoUserModel

SystemCallDispatchTable

Page 19: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

PassingParameters

• Threegeneralmethods:– PassviaCPUregisters– Useamemoryblock:

• Storeparametersinmemoryinatableormemoryblock• PassaddressofthismemoryblockviaCPUregistertoserviceroutine

• ThisapproachistakenbyLinuxandSolaris– Useastack

• Userprogrampushesparametersontostack• Systemserviceroutinepopsparametersfromstack

Page 20: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

API’sandSystemCalls• Operatingsystemsusuallycomewithalibrarythat

implementsanAPIoffunctionswrappingthesesystemcalls:– Typicallywritteninahigh-levellanguage(CorC++)

• StandardCLibrary• Unix/Linux:libc orglibc

– Usually,eachsystemcallhasacorrespondingwrapperroutine,whichanapplicationprogrammercanuseintheirprograms• E.g.:printf()

• POSIXisastandardAPIimplementedbymanykernelarchitectures:– ManyUnixkernels,Linux,MacOSX,WindowsNT

• Win32isanotherimportantAPI

Page 21: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.
Page 22: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

KernelArchitectures

Page 23: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

UnixKernel

Page 24: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

KernelArchitectures

• Kernelthecoreelementofoperatingsystem• Variousdesignandimplementationapproaches–Monolithickernels– Layeredapproach–Microkernel– Kernelmodules

Page 25: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

MonolithicKernel• Mostoperatingsystems,untilrecently,featuredalargemonolithic

kernel(mostUnixsystems,Linux)• Provide

– Scheduling– Filesystemmanagement– Networking– Devicedrivers– Memorymanagement– Etc.

• Implementedasasingleprocess– Allfunctionalcomponentssharesameaddressspace

• Benefit– Performance

• Problem– Vulnerabilitytofailureincomponents

Page 26: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

SimpleMonolithicStructure• Earlyoperatingsystems

weremonolithic• Nowelldefinedstructure• Nolayering,notdividedinto

modules• Startedassmallandsimple

systems• Example:MS-DOS

– Developedtoprovidemostfunctionalityintheleastspace

– Levelsnotwellseparated,programscandirectlyaccessI/Odevices

Page 27: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

IntroducingLayers• Simpleun-organisedstructuresbecameinfeasible• Introductionofalayeredapproach• Operatingsystemisdividedintoanumberoflayers(levels),eachbuiltontopoflowerlayers– Thebottomlayer(layer0)isthehardware– Thehighestlayer(layerN)istheuserinterface

• Eachlayerusesonlyfunctionsandservicesprovidedbyalowerlayer

• Allormostofthelayersoperateinkernelmode• Examples– MULTICS,VAX/VMS

Page 28: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

LayeredApproach• ApproachusedbyoriginalUnixkernel– Minimallayering,thickmonolithiclayers,noclearseparation– circulardependencies,difficulttodebugandextend

• Betterapproach- strictlayering• Difficulty– Howtodefinelayersappropriately?– Layeringisonlypossibleifthereisastrictcallinghierarchyamongsystemcallsandnocirculardependencies

• Example– TheTCP/IPnetworkingstackisastrictlylayeredarchitecture

Page 29: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

LayeredApproach- Problems

• Circulardependencies– Examplediskdevicedriver

• DevicedrivermayhavetowaitforI/Ocompletion,invokestheCPUschedulinglayer

• CPUmayneedtocallthedevicedrivertoswapprocessesinandouttoharddisk

• Themorelayersthemoreindirectionsfromfunctiontofunctionandthebiggertheoverheadinfunctioncalls

• Backlashagainststrictlayering:returntofewerlayerswithmorefunctionality

Page 30: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

Microkernel• Amicrokernelisareducedoperatingsystemcorethat

containsonlyessentialOSfunctions• Idea:minimisekernelbyexecutingasmuchfunctionalityas

possibleinusermode– Runthemasconventionaluserprocesses– Processesinteractonlyviamessagepassing(IPC)

• Manyservicesarenowexternalprocesses– Devicedrivers– Filesystems– Virtualmemorymanager– Windowingsystems– Securityservicesetc.

• Example:Machoperatingsystem

Page 31: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

MachKernel

• DevelopedatCarnegieMellonUniversity1985• Researchkernel• Variousversionsofitweredevelopedfurther–Microkernelaswellasnon-microkernelversions

• Notably– NeXTSTEP /MacOSX,FreeBSD(notamicrokernel,butprovidesmicrokernelIPCtoapplications)

• ProblemofMachkernel:IPC(Inter-ProcessCommunication)overhead

Page 32: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

MicrokernelSystemStructure• Operatingsystemcomponentsexternaltothemicrokernelareimplementedasserverprocesses– Theseprocessesinteractviamessagepassing(IPC)

• Microkernelfacilitatesthemessageexchange– Validatesmessages– Passesmessagesbetweencomponents– Checkswhethermessagepassingispermitted

• Grantsaccesstohardware• Microkerneleffectivelyimplementsaclient-serverinfrastructureonasinglecomputer

Page 33: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

Microkernel• Benefits– Uniforminterfaces

• Processespassmessages,nodistinctionbetweenuser-modeandkernel-modeservices,allservicesareprovidedviamessagepassingasinaclient-serverinfrastructure

– Extendibility• Easiertoextend,newservicesintroducedasnewapplications

– Portability• Onlythemicrokernelhastobeadaptedtoanewhardware

– Reliabilityandsecurity• muchlesscoderunsinkernelmode,programfailuresoccurringinusermodeexecutiondoesnotaffecttherestofthesystem

Page 34: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

MicrokernelDesign

• Minimalfunctionalitythathastobeincludedintoamicrokernel– Low-levelmemorymanagement

• Mappingofmemorypagestophysicalmemorylocations• Allothermechanismsofmemorymanagementareprovidedbyservicesrunninginusermode– Addressspaceprotection– Pagereplacementalgorithms– Virtualmemorymanagement

– Interprocess communication(IPC)– I/Oandinterruptmanagement

Page 35: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

SystemCallMonolithicvs MicroKernel

Page 36: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

Microkernel• Problems– Performanceoverheadofcommunicationbetweensystemservices• Eachinteractioninvolvesthekernelandausermode/kernelmodeswitch

• Systemservicesrunninginusermodeareprocesses,operatingsystemhastoswitchbetweenthem

– Solution:reintegrationofservicesrunninginusermodebackintothekernel• Improvesperformance:lessmodeswitches,servicesintegratedinkernelshareoneaddressspace(oneprocess)

• ThiswasdonewiththeMachkernel– Solution:makekernelevensmaller– experimentalkernelarchitectures(Nano kernels,pico kernels)

Page 37: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

ModularKernelDesign• Manyoperatingsystemsimplementkernelmodules– E.g.:Linux

• Eachcorecomponentisseparate• Communicationviadefinedinterfaces• Loadableondemand

• Modulesaresomehowahybridbetweenthelayeredandmicrokernelapproach– Cleansoftwareengineeringapproach– But:modulesareinsidethekernelspace,theydon’trequiretheoverheadofmessagepassing

– Compromisewithperformancebenefits

Page 38: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

ModernUnixKernel

• ModernUnixkernelshaveamodulararchitecture

• Commonfacilitiesastheinnercoreofthekernel

• Restofsystemservicesaddedasmodules

• SeeLinux

Page 39: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

ModularApproach

• MacOSX– takesahybridapproach,hasaMachkernel(microkernel)combined

withaBSDinterface– BSD(BerkeleySoftwareDistribution,sometimescalledBerkeley

Unix):providessupportforcommandlineinterface,networking,filesystem,filesystem,POSIXAPIandthreads

– Mach:memorymanagement,RemoteprocedureCall(RPC),Interprocess communication(IPC),messagepassing

BSD

Mach

ApplicationEnvironmentCommunicationServices

Kernel

Page 40: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

OSFunctionality

• LinuxKernelMap– http://www.makelinux.net/kernel_map/

• Alsoavailableat:– http://upload.wikimedia.org/wikipedia/commons/5/5b/Linux_kernel_map.png

– http://i.imgur.com/4sftcoo.jpg

Page 41: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.
Page 42: CS3026 Operating Systems Lecture 03 - Homepageshomepages.abdn.ac.uk/m.j.kollingbaum/pages/teaching... · – Secure user access to data and define ownership of files and processes.

http://en.wikipedia.org/wiki/File:Unix_history-simple.svg