Win32 Programming Lesson 7: Kernel Objects. Abstract  Many of the concepts we’ll look at today won’t make complete sense until you use them  However,

Slides:



Advertisements
Similar presentations
Lesson 12: Kernel-mode Thread Sync (aka: Why I love Gentoo)
Advertisements

Win32 Programming Lesson 8: Processes. Where are we?  We’re starting to have some foundational understanding of Windows  But really, we don’t know how.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Win32 Programming Lesson 5: Error Codes. Before We Begin  Much of the time in this class we’ll be calling Win32 Functions  However, sometimes they’re.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
1 Processes and Pipes. 2 "He was below me. I saw his markings, manoeuvred myself behind him and shot him down. If I had known it was Saint-Exupery, I.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
ISP – 3 rd Recitation “The joy of Windows API” Processes Threads Handles Relevant functions A simple code example.
1 JMH Associates © 2004, All rights reserved Chapter 15 Windows System Security.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
CSE 451 Section 4 Project 2 Design Considerations.
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
Process Description and Control A process is sometimes called a task, it is a program in execution.
1 JMH Associates © 2004, All rights reserved Chapter 1 Getting Started with Win32/64.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
SimCorp Dimension 64-bit Migration Project Dyalog '11, Boston Stig Nielsen, SimCorp A/S.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
Win32 Programming Lesson 9: Jobs & Thread Basics.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 11 Case Study 2: Windows Vista Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Networked File System CS Introduction to Operating Systems.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Threads A thread (or lightweight process) is a basic unit of CPU.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Chapter 5 Being a Web App. Very few servlet or JSP stands alone Many times in our application, different servlets or JSPs need to share information 
Win32 Programming Lesson 16: Virtual Memory. Where are we?  We’ve covered the theory of Windows memory, and poked around some  Now let’s use how to.
MultiThreaded Applications. What is Multithreaded Programming? Having your software appear to perform multiple tasks in parallel –Individual paths of.
Win32 Programming Lesson 10: Thread Scheduling and Priorities.
Win32 Programming Lesson 20: Advanced DLL Techniques.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
1 Confidential Enterprise Solutions Group Process and Threads.
Win32 Programming Lesson 18: More Memory Mapped Files and the HEAP (Finally, cool stuff!)
Briefing for: Hacking Windows Internals Cesar Cerrudo Argeniss.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Win32 Programming Lesson 8a: Jobs. Where are we?  Grouping processes into logical groups: Jobs  However, processes don’t retain a parent- child relationship.
Homework Assignment #1 J. H. Wang Oct. 13, Homework #1 Chap.1: 1.24 Chap.2: 2.13 Chap.3: 3.5, 3.13* (or 3.14*) Chap.4: 4.6, 4.12* –(*: optional.
Win32 Programming Lesson 14: Introducing Windows Memory (C Rox…)
Homework Assignment #1 J. H. Wang Oct. 6, 2011.
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS2: Operating System Principles 2.4. The Windows.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Win32 Programming Lesson 17: Memory Mapped Files (Finally, cool stuff again, all this work is getting tedious!)
Processes and Virtual Memory
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Windows CE Portable Modular Real-time Small footprint Embedded market.
Win32 Synchronization CS Spring Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.
Memory Mapped I/O Gregory Mortensen CSIS 4330, Advanced Windows Programming – UVSC.
Chapter 3 The Programming Interface Chien-Chung Shen CIS/UD
Threads and Thread Synchronization. Introduction In windows the basic unit of execution is the thread. It is the smallest schedulable unit of execution.
Chapter 4 – Thread Concepts
Chapter 3: Windows7 Part 5.
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4 – Thread Concepts
Process Management Presented By Aditya Gupta Assistant Professor
OpenStorage API part II
INTER-PROCESS COMMUNICATION
System Structure and Process Model
System Structure and Process Model
System Structure B. Ramamurthy.
Windows APIs File Processing Copyright © 2016 Curt Hill.
System Structure and Process Model
Process Description and Control
Process Description and Control
Process Description and Control
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
The CreateFile Function
Presentation transcript:

Win32 Programming Lesson 7: Kernel Objects

Abstract  Many of the concepts we’ll look at today won’t make complete sense until you use them  However, it’s impossible to talk about Windows without understanding how the API’s interact with Kernel Objects

What is a Kernel Object?  Any time you write Windows code you’re probably manipulating Kernel objects and you just don’t know it  Examples: Access token objects Event objects File objects File-mapping objects The list goes on and on

Manipulation of Kernel Objects  Cannot be carried out directly from an application Portability Security Consistency  Only manipulated via specific APIs Via a HANDLE object

HANDLES  Each HANDLE is process relative Huh? If this is the case, how can we share objects across processes? We’ll look at 3 mechanisms today

Usage Tracking  Kernel objects are owned by the Kernel not the process Not necessarily destroyed on process exit Kernel tracks usage of the object when assigning handles to processes

Security  Protected with a security descriptor Who created the object Who can access the object Usually used for server applications, not client

Example  HANDLE CreateFileMapping ( HANDLE hFile, PSECURITY_ATTRIBUTES psa, DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow, PCTSTR pszName );

Security Attributes  typedef struct _SECURITY_ATTRIBUTES { DWORD nLength; LPVOID lpSecurityDescriptor; BOOL bInheritHandle; } SECURITY_ATTRIBUTES;

Security Attributes (cntd)  SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); // Used for versioning sa.lpSecurityDescriptor = pSD; // Address of an initialized SD sa.bInheritHandle = FALSE; // Discussed later HANDLE hFileMapping = CreateFileMapping( INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, 1024, "MyFileMapping“ );

Existing Objects  When you open an existing object, you must specify what access you want HANDLE hFileMapping = OpenFileMapping(FI LE_MAP_READ, FALSE, "MyFileMapping") ;  FILE_MAP_READ allows the correct security check to be performed  If it fails, we can call…? ERROR_ACCESS_DENIED

Kernel Object Handle Table  Created when a process is created  Details are undocumented, but it gives you a feel for how it works IndexPointer to Kernel Memory Block Access Mask (DWORD) Flags 10x???????? 2 …………

Failure!  Unfortunately, Windows isn’t 100% consistent  Failure usually returns: 0 (NULL) -1 (INVALID_HANDLE_VALUE) You must check the actual API in question (sorry)

CloseHandle  Of course, we have to close the handles we open BOOL CloseHandle (HANDLE hObj)  Sets GetLastError on failure  What happens if we don’t do this?

Sharing Process Objects  Object Handle Inheritance  Named Objects  Duplicating Objects

Inheritance  Used when we have a parent-child relationship between processes  Gives the Children controlled access to the parent’s handles Create an Inheritable Handle Spawn a new Process Pass the inherited handle (often by command-line option) The details are in the book – read them!

Named Objects  Many Kernel Objects can be named  We can then use the name to access the object from another thread  See, for example, CreateMutex, CreateEvent etc.  All have the same parameter: pszName

Example: CreateMutexCreateMutex  Process A: HANDLE hMutexProcessA = CreateMutex(NULL, FALSE, “Panther”);  Process B: HANDLE hMutexProcessB = CreateMutex(NULL, FALSE, “Panther”); Now, checks for a Mutex with name Panther If found, checks access rights; if allowed, creates entry in the Process’ Handle table

Alernative Approach: Open  Use OpenMutex instead of CreateMutex  Main difference: Open can only open an existing Mutex – it can never Create one  Often used to prevent multiple instances of the same application from running  See example: OneOnly

Duplicate Object Handles  Final option is to create a duplicate copy of a handle, and use a regular IPC to pass the new handle through  The call is DuplicateHandle Makes an entry in the handle table of another process

Example: Limiting Access  Suppose we have a FileMapping object in our system.  We wish to pass READ ONLY access to this object to one of our functions  Would be nice if we could pass a read only handle… and we can, by using DuplicateHandle

Example  HANDLE hFileMapRW = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 10240, NULL); HANDLE hFileMapRO; DuplicateHandle( GetCurrentProcess(), hFileMapRW, GetCurrentProcess(), &hFileMapRO, FILE_MAP_READ, FALSE, 0); // Pass the RO handle… MyROFunction(hFileMapRO); CloseHandle(hFileMapRO); CloseHandle(hFileMapRW);